Skip to content

Commit e31b994

Browse files
JohnNiangruibaby
andauthored
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 <[email protected]> --------- Signed-off-by: Ryan Wang <[email protected]> Co-authored-by: Ryan Wang <[email protected]>
1 parent d7629ca commit e31b994

File tree

12 files changed

+1108
-89
lines changed

12 files changed

+1108
-89
lines changed

.github/workflows/cd.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: CD
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
cd:
10+
uses: halo-sigs/reusable-workflows/.github/workflows/plugin-cd.yaml@v3
11+
permissions:
12+
contents: write
13+
with:
14+
pnpm-version: 9
15+
node-version: 22
16+
java-version: 21
17+
skip-appstore-release: true

.github/workflows/ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010

1111
jobs:
1212
ci:
13-
uses: halo-sigs/reusable-workflows/.github/workflows/plugin-ci.yaml@v1
13+
uses: halo-sigs/reusable-workflows/.github/workflows/plugin-ci.yaml@v3
1414
with:
1515
ui-path: "ui"
16+
pnpm-version: 9
17+
node-version: 22
18+
java-version: 21

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# plugin-starter
22

3-
Halo 2.0 插件开发快速开始模板。
3+
Halo 2.x 插件开发快速开始模板。
44

55
## 开发环境
66

77
插件开发的详细文档请查阅:<https://docs.halo.run/developer-guide/plugin/introduction>
88

99
所需环境:
1010

11-
1. Java 17
11+
1. JDK 21
1212
2. Node 20
1313
3. pnpm 9
1414
4. Docker (可选)

build.gradle

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,48 @@
11
plugins {
22
id 'java'
3-
id "com.github.node-gradle.node" version "7.0.2"
4-
id "io.freefair.lombok" version "8.0.1"
5-
id "run.halo.plugin.devtools" version "0.2.0"
3+
id "io.freefair.lombok" version "8.13"
4+
id "run.halo.plugin.devtools" version "0.6.0"
65
}
76

87
group 'run.halo.starter'
9-
sourceCompatibility = JavaVersion.VERSION_17
108

119
repositories {
1210
mavenCentral()
13-
maven { url 'https://s01.oss.sonatype.org/content/repositories/releases' }
14-
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
15-
maven { url 'https://repo.spring.io/milestone' }
1611
}
1712

1813
dependencies {
19-
implementation platform('run.halo.tools.platform:plugin:2.20.0-SNAPSHOT')
14+
implementation platform('run.halo.tools.platform:plugin:2.21.0')
2015
compileOnly 'run.halo.app:api'
2116

2217
testImplementation 'run.halo.app:api'
2318
testImplementation 'org.springframework.boot:spring-boot-starter-test'
19+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
2420
}
2521

2622
test {
2723
useJUnitPlatform()
2824
}
2925

30-
tasks.withType(JavaCompile).configureEach {
31-
options.encoding = "UTF-8"
32-
}
33-
34-
node {
35-
nodeProjectDir = file("${project.projectDir}/ui")
26+
java {
27+
toolchain {
28+
languageVersion = JavaLanguageVersion.of(21)
29+
}
3630
}
3731

38-
tasks.register('buildFrontend', PnpmTask) {
39-
args = ['build']
40-
dependsOn('installDepsForUI')
32+
tasks.withType(JavaCompile).configureEach {
33+
options.encoding = "UTF-8"
34+
options.release = 21
4135
}
4236

43-
tasks.register('installDepsForUI', PnpmTask) {
44-
args = ['install']
37+
tasks.register('processUiResources', Copy) {
38+
from project(':ui').tasks.named('buildFrontend')
39+
into layout.buildDirectory.dir('resources/main/console')
4540
}
4641

47-
build {
48-
// build frontend before build
49-
tasks.named('compileJava').configure {
50-
dependsOn('buildFrontend')
51-
}
42+
tasks.named('processResources', ProcessResources) {
43+
dependsOn tasks.named('processUiResources')
5244
}
5345

5446
halo {
55-
version = '2.20'
47+
version = '2.21'
5648
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ pluginManagement {
44
}
55
}
66
rootProject.name = 'plugin-starter'
7-
7+
include 'ui'

src/main/resources/plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
name: starter
88
spec:
99
enabled: true
10-
requires: ">=2.20.0"
10+
requires: ">=2.21.0"
1111
author:
1212
name: Halo
1313
website: https://github.com/halo-dev
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package run.halo.starter;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.extension.ExtendWith;
5+
import org.mockito.InjectMocks;
6+
import org.mockito.Mock;
7+
import org.mockito.junit.jupiter.MockitoExtension;
8+
import run.halo.app.plugin.PluginContext;
9+
10+
@ExtendWith(MockitoExtension.class)
11+
class StarterPluginTest {
12+
13+
@Mock
14+
PluginContext context;
15+
16+
@InjectMocks
17+
StarterPlugin plugin;
18+
19+
@Test
20+
void contextLoads() {
21+
plugin.start();
22+
plugin.stop();
23+
}
24+
}

ui/.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"semi": false,
4+
"singleQuote": true,
5+
"printWidth": 100
6+
}

ui/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
plugins {
2+
id 'base'
3+
id "com.github.node-gradle.node" version "7.1.0"
4+
}
5+
6+
group 'run.halo.starter.ui'
7+
8+
tasks.register('buildFrontend', PnpmTask) {
9+
args = ['build']
10+
dependsOn tasks.named('pnpmInstall')
11+
inputs.dir(layout.projectDirectory.dir('src'))
12+
inputs.files(fileTree(
13+
dir: layout.projectDirectory,
14+
includes: ['*.cjs', '*.ts', '*.js', '*.json', '*.yaml']))
15+
outputs.dir(layout.buildDirectory.dir('dist'))
16+
shouldRunAfter(tasks.named('check'))
17+
}
18+
19+
tasks.register('checkFrontend', PnpmTask) {
20+
args = ['test:unit']
21+
dependsOn tasks.named('pnpmInstall')
22+
}
23+
24+
tasks.named('check') {
25+
dependsOn tasks.named('checkFrontend')
26+
}
27+
28+
tasks.named('build') {
29+
dependsOn tasks.named('buildFrontend')
30+
}

ui/package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
{
2+
"type": "module",
23
"scripts": {
3-
"dev": "vite build --watch --mode=development",
44
"build": "run-p type-check \"build-only {@}\" --",
55
"build-only": "vite build",
6-
"test:unit": "vitest",
7-
"type-check": "vue-tsc --build --force",
6+
"dev": "vite build --watch --mode=development",
87
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
9-
"prettier": "prettier --write src/"
8+
"prettier": "prettier --write src/",
9+
"test:unit": "vitest --passWithNoTests",
10+
"type-check": "vue-tsc --build --force"
1011
},
1112
"dependencies": {
12-
"@halo-dev/api-client": "^2.17.0",
13-
"@halo-dev/components": "^2.17.0",
14-
"@halo-dev/console-shared": "^2.17.0",
13+
"@halo-dev/api-client": "^2.21.0",
14+
"@halo-dev/components": "^2.21.0",
15+
"@halo-dev/console-shared": "^2.21.0",
1516
"axios": "^1.7.2",
1617
"canvas-confetti": "^1.9.3",
1718
"vue": "^3.4.31"
1819
},
1920
"devDependencies": {
20-
"@halo-dev/ui-plugin-bundler-kit": "^2.17.0",
21+
"@halo-dev/ui-plugin-bundler-kit": "^2.21.1",
2122
"@iconify/json": "^2.2.224",
2223
"@rushstack/eslint-patch": "^1.10.3",
2324
"@tsconfig/node20": "^20.1.4",
@@ -40,5 +41,6 @@
4041
"vite": "^5.3.2",
4142
"vitest": "^1.6.0",
4243
"vue-tsc": "^2.0.24"
43-
}
44+
},
45+
"packageManager": "[email protected]+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
4446
}

0 commit comments

Comments
 (0)