diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c80e7f3ca..9e9b10486 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: diff --git a/build.gradle b/build.gradle index e6187f63a..0b121e646 100644 --- a/build.gradle +++ b/build.gradle @@ -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' }