Build the handbook with Gradle

This commit is contained in:
KingRainbow44 2023-05-26 13:48:52 -04:00
parent 2107866787
commit 77796aa8b6
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 41 additions and 3 deletions

View File

@ -43,7 +43,7 @@ jobs:
url: https://api.grasscutter.io/static/handbook.html
target: src/main/resources/html/
- name: Run Gradle
run: ./gradlew && ./gradlew jar
run: ./gradlew && ./gradlew jar -PskipHandbook=1
- name: Upload build
uses: actions/upload-artifact@v3
with:

View File

@ -1,3 +1,4 @@
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.plugins.ide.eclipse.model.SourceFolder
/*
@ -220,7 +221,7 @@ publishing {
maven {
if (version.endsWith('-dev')) {
// Check if the action being ran is 'publish'.
if (project.hasProperty('publish')) {
if (publish.state.executing) {
println('Publishing to Ben4J-Maven')
}
@ -232,7 +233,7 @@ publishing {
}
} else {
// Check if the action being ran is 'publish'.
if (project.hasProperty('publish')) {
if (publish.state.executing) {
println('Publishing to Sonatype')
}
@ -323,6 +324,43 @@ public final class BuildConfig {
}"""
}
tasks.register('generateHandbook') {
if (project.hasProperty('skipHandbook')) {
println('Skipping handbook generation.')
return
}
def nodeVersion = {
try {
return 'node --version'.execute().text.trim()
} catch (ignored) {
return 'NODE_NOT_FOUND'
}
}
// Check if Node is installed.
if (nodeVersion() == 'NODE_NOT_FOUND') {
println('Node is not installed. Skipping handbook generation.')
} else {
// Build the handbook.
var npm = 'npm'
if (Os.isFamily(Os.FAMILY_WINDOWS))
npm = 'npm.cmd'
exec {
workingDir 'src/handbook'
commandLine npm, 'run', 'build'
}
// Copy the handbook from /dist to /src/main/resources.
copy {
from 'src/handbook/dist/index.html'
into 'src/main/resources'
rename 'index.html', 'handbook.html'
}
}
}
processResources {
dependsOn 'generateProto'
}