Update Node.js to v20.19.0 and npm to v10.2.3; refactor npmBuild task to use plugin-provided npmCommand and add nodeVersionCheck task for environment validation.
This commit is contained in:
parent
291c9df5c6
commit
871615702b
|
|
@ -8,8 +8,9 @@ plugins {
|
||||||
|
|
||||||
node {
|
node {
|
||||||
download.set(true)
|
download.set(true)
|
||||||
version.set("22.14.0")
|
// Update to the version that's compatible with your environment requirements
|
||||||
npmVersion.set("10.9.2")
|
version.set("20.19.0")
|
||||||
|
npmVersion.set("10.2.3") // A compatible npm version for Node.js 20.19.0
|
||||||
workDir.set(file("${project.projectDir}/node"))
|
workDir.set(file("${project.projectDir}/node"))
|
||||||
npmWorkDir.set(file("${project.projectDir}/node"))
|
npmWorkDir.set(file("${project.projectDir}/node"))
|
||||||
}
|
}
|
||||||
|
|
@ -21,38 +22,37 @@ tasks.register<Delete>("cleanDist") {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a task that will run npm build
|
// Create a task that will run npm build
|
||||||
tasks.register("npmBuild") {
|
tasks.register<com.github.gradle.node.npm.task.NpmTask>("npmBuild") {
|
||||||
description = "Run 'npm run build'"
|
description = "Run 'npm run build'"
|
||||||
group = "build"
|
group = "build"
|
||||||
|
|
||||||
doLast {
|
// Determine which build script to run based on the OS
|
||||||
// Use nodeCommand directly from the plugin
|
val isWindows = System.getProperty("os.name").lowercase().contains("windows")
|
||||||
project.exec {
|
npmCommand.set(listOf("run", if (isWindows) "build:dev" else "build:beta"))
|
||||||
workingDir(project.projectDir)
|
|
||||||
|
|
||||||
// Use node's npm to ensure it works on all environments
|
|
||||||
val nodeDir = "${project.projectDir}/node"
|
|
||||||
val isWindows = System.getProperty("os.name").lowercase().contains("windows")
|
|
||||||
|
|
||||||
if (isWindows) {
|
|
||||||
val npmCmd = file(nodeDir).listFiles()?.find { it.name.startsWith("npm") && it.isDirectory }?.let {
|
|
||||||
"${it.absolutePath}/npm.cmd"
|
|
||||||
} ?: "$nodeDir/node_modules/npm/bin/npm.cmd"
|
|
||||||
|
|
||||||
commandLine(npmCmd, "run", "build:dev")
|
|
||||||
} else {
|
|
||||||
val npmExecutable = file(nodeDir).listFiles()?.find { it.name.startsWith("npm") && it.isDirectory }?.let {
|
|
||||||
"${it.absolutePath}/bin/npm"
|
|
||||||
} ?: "$nodeDir/node_modules/npm/bin/npm"
|
|
||||||
|
|
||||||
commandLine(npmExecutable, "run", "build:beta")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependsOn("npmInstall")
|
dependsOn("npmInstall")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a new task to check Node.js and npm versions
|
||||||
|
tasks.register<com.github.gradle.node.task.NodeTask>("nodeVersionCheck") {
|
||||||
|
description = "Check Node.js and npm versions"
|
||||||
|
script.set(file("${projectDir}/node-version-check.js"))
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
// Create a temporary script to check versions
|
||||||
|
file("${projectDir}/node-version-check.js").writeText("""
|
||||||
|
console.log('Node.js version:', process.version);
|
||||||
|
console.log('npm version:', require('npm/package.json').version);
|
||||||
|
console.log('Build command that would be used:', process.platform === 'win32' ? 'build:dev' : 'build:beta');
|
||||||
|
""".trimIndent())
|
||||||
|
}
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
// Clean up the temporary script
|
||||||
|
delete("${projectDir}/node-version-check.js")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tasks.named("assemble") {
|
tasks.named("assemble") {
|
||||||
dependsOn("npmBuild")
|
dependsOn("npmBuild")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user