CLOVIS
08/18/2021, 9:36 AMdevNpm
dependency that has a JS script I'd like to run during development.
So far I've done it by using my locally installed /usr/bin/node, but that's not portable (especially for CI); I'd like to take advantage of Kotlin's Node installation.CLOVIS
08/18/2021, 9:57 AM~/.gradle/nodejs/node-<version>/bin/node
Is it possible to know the node version used by Gradle, to statically know what the file will be?ephemient
08/18/2021, 10:29 AMNodeJsRootPlugin.apply(rootProject)
val kotlinNodeJs = the<NodeJsRootExtension>().nodeVersion
something like that might work, but how node is set up is pretty configurable and varies by platform too. might have an easier time telling Kotlin to use your existing node installCLOVIS
08/18/2021, 10:30 AMCLOVIS
08/18/2021, 10:32 AMtasks.create<Exec>("yourTask") {
dependsOn(":kotlinNodeJsSetup")
val kotlinNodeJsSetup = rootProject.tasks["kotlinNodeJsSetup"] as org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsSetupTask
workingDir = File(kotlinNodeJsSetup.destination, "bin")
commandLine(
"node",
// whatever
)
}
ephemient
08/18/2021, 10:33 AMCLOVIS
08/18/2021, 10:57 AMJoffrey
08/18/2021, 12:08 PMbin
subfolder there, directly node.exe:Joffrey
08/18/2021, 12:09 PMFile(kotlinNodeJsSetup.destination, "bin")
might not be universalCLOVIS
08/18/2021, 12:09 PMJoffrey
08/18/2021, 12:18 PMworkDir = if (windows) destination else File(...)
would do the trickephemient
08/19/2021, 5:29 AMval kotlinNodeJs = rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>()
val nodeJsEnv = kotlinNodeJs.requireConfigured()
nodeJsEnv.nodeExecutable // full path to node binary, including ".exe" on Windows, "/bin/" on UNIX