Refactor build scripts and workflows (#52)

* Refactor build scripts and workflows

* Add a unit test sample

* chore: bump @halo-dev/ui-plugin-bundler-kit version

Signed-off-by: Ryan Wang <i@ryanc.cc>

---------

Signed-off-by: Ryan Wang <i@ryanc.cc>
Co-authored-by: Ryan Wang <i@ryanc.cc>
This commit is contained in:
John Niang
2025-06-19 16:50:31 +08:00
committed by GitHub
parent d7629caa1f
commit e31b994a7f
12 changed files with 1114 additions and 95 deletions

17
.github/workflows/cd.yaml vendored Normal file
View File

@@ -0,0 +1,17 @@
name: CD
on:
release:
types:
- published
jobs:
cd:
uses: halo-sigs/reusable-workflows/.github/workflows/plugin-cd.yaml@v3
permissions:
contents: write
with:
pnpm-version: 9
node-version: 22
java-version: 21
skip-appstore-release: true

View File

@@ -10,6 +10,9 @@ on:
jobs:
ci:
uses: halo-sigs/reusable-workflows/.github/workflows/plugin-ci.yaml@v1
uses: halo-sigs/reusable-workflows/.github/workflows/plugin-ci.yaml@v3
with:
ui-path: "ui"
pnpm-version: 9
node-version: 22
java-version: 21

View File

@@ -1,6 +1,6 @@
# plugin-starter
Halo 2.0 插件开发快速开始模板。
Halo 2.x 插件开发快速开始模板。
## 开发环境
@@ -8,7 +8,7 @@ Halo 2.0 插件开发快速开始模板。
所需环境:
1. Java 17
1. JDK 21
2. Node 20
3. pnpm 9
4. Docker (可选)

View File

@@ -1,56 +1,48 @@
plugins {
id 'java'
id "com.github.node-gradle.node" version "7.0.2"
id "io.freefair.lombok" version "8.0.1"
id "run.halo.plugin.devtools" version "0.2.0"
id "io.freefair.lombok" version "8.13"
id "run.halo.plugin.devtools" version "0.6.0"
}
group 'run.halo.starter'
sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
maven { url 'https://s01.oss.sonatype.org/content/repositories/releases' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
implementation platform('run.halo.tools.platform:plugin:2.20.0-SNAPSHOT')
implementation platform('run.halo.tools.platform:plugin:2.21.0')
compileOnly 'run.halo.app:api'
testImplementation 'run.halo.app:api'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
test {
useJUnitPlatform()
}
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
}
node {
nodeProjectDir = file("${project.projectDir}/ui")
}
tasks.register('buildFrontend', PnpmTask) {
args = ['build']
dependsOn('installDepsForUI')
}
tasks.register('installDepsForUI', PnpmTask) {
args = ['install']
}
build {
// build frontend before build
tasks.named('compileJava').configure {
dependsOn('buildFrontend')
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
halo {
version = '2.20'
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.release = 21
}
tasks.register('processUiResources', Copy) {
from project(':ui').tasks.named('buildFrontend')
into layout.buildDirectory.dir('resources/main/console')
}
tasks.named('processResources', ProcessResources) {
dependsOn tasks.named('processUiResources')
}
halo {
version = '2.21'
}

View File

@@ -4,4 +4,4 @@ pluginManagement {
}
}
rootProject.name = 'plugin-starter'
include 'ui'

View File

@@ -7,7 +7,7 @@ metadata:
name: starter
spec:
enabled: true
requires: ">=2.20.0"
requires: ">=2.21.0"
author:
name: Halo
website: https://github.com/halo-dev

View File

@@ -0,0 +1,24 @@
package run.halo.starter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import run.halo.app.plugin.PluginContext;
@ExtendWith(MockitoExtension.class)
class StarterPluginTest {
@Mock
PluginContext context;
@InjectMocks
StarterPlugin plugin;
@Test
void contextLoads() {
plugin.start();
plugin.stop();
}
}

6
ui/.prettierrc.json Normal file
View File

@@ -0,0 +1,6 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"singleQuote": true,
"printWidth": 100
}

30
ui/build.gradle Normal file
View File

@@ -0,0 +1,30 @@
plugins {
id 'base'
id "com.github.node-gradle.node" version "7.1.0"
}
group 'run.halo.starter.ui'
tasks.register('buildFrontend', PnpmTask) {
args = ['build']
dependsOn tasks.named('pnpmInstall')
inputs.dir(layout.projectDirectory.dir('src'))
inputs.files(fileTree(
dir: layout.projectDirectory,
includes: ['*.cjs', '*.ts', '*.js', '*.json', '*.yaml']))
outputs.dir(layout.buildDirectory.dir('dist'))
shouldRunAfter(tasks.named('check'))
}
tasks.register('checkFrontend', PnpmTask) {
args = ['test:unit']
dependsOn tasks.named('pnpmInstall')
}
tasks.named('check') {
dependsOn tasks.named('checkFrontend')
}
tasks.named('build') {
dependsOn tasks.named('buildFrontend')
}

View File

@@ -1,23 +1,24 @@
{
"type": "module",
"scripts": {
"dev": "vite build --watch --mode=development",
"build": "run-p type-check \"build-only {@}\" --",
"build-only": "vite build",
"test:unit": "vitest",
"type-check": "vue-tsc --build --force",
"dev": "vite build --watch --mode=development",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"prettier": "prettier --write src/"
"prettier": "prettier --write src/",
"test:unit": "vitest --passWithNoTests",
"type-check": "vue-tsc --build --force"
},
"dependencies": {
"@halo-dev/api-client": "^2.17.0",
"@halo-dev/components": "^2.17.0",
"@halo-dev/console-shared": "^2.17.0",
"@halo-dev/api-client": "^2.21.0",
"@halo-dev/components": "^2.21.0",
"@halo-dev/console-shared": "^2.21.0",
"axios": "^1.7.2",
"canvas-confetti": "^1.9.3",
"vue": "^3.4.31"
},
"devDependencies": {
"@halo-dev/ui-plugin-bundler-kit": "^2.17.0",
"@halo-dev/ui-plugin-bundler-kit": "^2.21.1",
"@iconify/json": "^2.2.224",
"@rushstack/eslint-patch": "^1.10.3",
"@tsconfig/node20": "^20.1.4",
@@ -40,5 +41,6 @@
"vite": "^5.3.2",
"vitest": "^1.6.0",
"vue-tsc": "^2.0.24"
}
},
"packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
}

1027
ui/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,17 @@
import { fileURLToPath, URL } from "url";
import { HaloUIPluginBundlerKit } from "@halo-dev/ui-plugin-bundler-kit";
import Vue from "@vitejs/plugin-vue";
import { viteConfig } from "@halo-dev/ui-plugin-bundler-kit";
import Icons from "unplugin-icons/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [Vue(), Icons({ compiler: "vue3" }), HaloUIPluginBundlerKit()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
// For more info,
// please see https://github.com/halo-dev/halo/tree/main/ui/packages/ui-plugin-bundler-kit
export default viteConfig({
vite: {
plugins: [Icons({ compiler: "vue3" })],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
},
});