node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
601 stars 117 forks source link

Question: How to pass additional arguments to npm task via Gradle command line? #262

Open IvanPizhenko opened 1 year ago

IvanPizhenko commented 1 year ago

Assume in my package.json I have a task named "xxx". Using npm itself, I can run it as follows: npm run xxx. I also can run it with additional arguments in the following way: npm run xxx -- more arguments for xxx. When I run this task using node plugin for Gradle, I can run it using ./gradlew npm_run_xxx. But is there a way to pass those additional arguments to the npm task, like I've done above with npm right on the Gradle command line?

deepy commented 1 year ago

Do you need these to be generic or is there a different set of them? If you've got a set of them you can do something like the following for each:

tasks.register('myNpmTask', NpmTask) {
  args = ['run', 'task', 'args']
  inputs.dir('src') // Remember to declare inputs and outputs
  outputs.dir('dist')
}

Otherwise if you need it to be dynamic you can either subclass NpmTask and add a command-line argument or make use of project properties in the args

But this project supplying a generalized NpmRunTask might make sense here 🤔