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

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

Open IvanPizhenko opened this issue 2 years ago • 1 comments

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?

IvanPizhenko avatar Feb 21 '23 12:02 IvanPizhenko

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 🤔

deepy avatar Feb 22 '23 08:02 deepy