gradle-node-plugin icon indicating copy to clipboard operation
gradle-node-plugin copied to clipboard

NPX?

Open Exerosis opened this issue 7 years ago • 3 comments

I might be missing something obvious, but how I can create a gradle task that runs npx it gets mad about the missing script property if I just omit that, but IDK what I would put there if I just wanted to execute npx.

Exerosis avatar Oct 12 '18 23:10 Exerosis

Hi there!

It does not seem like this project is still active at the moment.

For a workaround you might use something like this:

task npxWorkaround(type: Exec) {
  dependsOn "npmInstall"

  if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) {
    commandLine "${dirWhereIInstalledNodeModules}/node_modules/.bin/my_module_executable.cmd"
  } else {
    commandLine "${dirWhereIInstalledNodeModules}/node_modules/.bin/my_module_executable"
  }
}

If you do not have node installed locally and install it via the plugin you might need to actually call it directly via a NodeTask.

task doSth(type: NodeTask) {
  dependsOn "npmInstall"
  
  script = file("${dirWhereIInstalledNodeModules}/node_modules/my_module/bin/my_module_executable")
}

bennyboer avatar Oct 29 '18 06:10 bennyboer

Ah, this seems like a good solution! Let me give this a go, thank you so much for taking the time to give me a hand here.

Exerosis avatar Oct 31 '18 07:10 Exerosis

There's support for NpxTask in the fork thanks to this PR https://github.com/node-gradle/gradle-node-plugin/pull/32

deepy avatar Sep 19 '19 06:09 deepy