import com.github.gradle.node.NodeExtension import com.github.gradle.node.npm.task.NpmTask plugins { id("com.github.node-gradle.node") version "7.1.0" id("base") // This adds the standard Gradle lifecycle tasks like "build" } node { download.set(true) version.set("22.14.0") npmVersion.set("10.9.2") workDir.set(file("${project.projectDir}/node")) npmWorkDir.set(file("${project.projectDir}/node")) } // Clean the distribution directory tasks.register("cleanDist") { description = "Clean the distribution directory" delete("dist") } // Create a task that will run npm build tasks.register("npmBuild") { description = "Run 'npm run build'" group = "build" doLast { // Use nodeCommand directly from the plugin project.exec { 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") } 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") } } } dependsOn("npmInstall") } tasks.named("assemble") { dependsOn("npmBuild") }