node-gradle / gradle-node-plugin

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

Passing arguments to gruntfile #215

Closed StephenChamberlain closed 2 years ago

StephenChamberlain commented 2 years ago

Hi!

I am trying to use grunt with the plugin as specified in https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/faq.md.

I would like to pass the project version from my gradle file to the gruntfile (using the grunt option mechanism https://gruntjs.com/api/grunt.option).

I can't get this to work; I have tried:

task ngBuildRpm(type: NpxTask) {
   ....
    command = "grunt --version=bla"
    args = ["--verbose", "mytask"]

but this results in:

Error: Invalid tag name "grunt --version=bla": Tags may not have any characters that encodeURIComponent encodes.
    at invalidTagName (C:\<my project path>\build\nodejs\node-v14.17.6-win-x64\node_modules\npm\node_modules\npm-package-arg\npa.js:91:15)
    at fromRegistry (C:\<my project path>\build\nodejs\node-v14.17.6-win-x64\node_modules\npm\node_modules\npm-package-arg\npa.js:296:13)
    at resolve (C:\<my project path>\build\nodejs\node-v14.17.6-win-x64\node_modules\npm\node_modules\npm-package-arg\npa.js:81:12)
    at npa (C:\<my project path>\build\nodejs\node-v14.17.6-win-x64\node_modules\npm\node_modules\npm-package-arg\npa.js:52:10)
    at fastPathArgs (C:\<my project path>\build\nodejs\node-v14.17.6-win-x64\node_modules\npm\node_modules\libnpx\parse-args.js:105:17)
    at Function.parseArgs (C:\<my project path>\build\nodejs\node-v14.17.6-win-x64\node_modules\npm\node_modules\libnpx\parse-args.js:11:12)
    at Object.<anonymous> (C:\<my project path>\build\nodejs\node-v14.17.6-win-x64\node_modules\npm\bin\npx-cli.js:8:9)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32) {
  code: 'EINVALIDTAGNAME'
}

if I try:

task ngBuildRpm(type: NpxTask) {
   ....
    command = "grunt"
    args = ["--verbose", "--version=bla",  "mytask"]

The build doesn't fail, but grunt also does not execute correctly:

grunt-cli v1.4.3
grunt v1.4.1
Install path: C:\<my project path>\node_modules\grunt
Available tasks: mytask
Available options: --help -h --base -b --no-color --gruntfile --debug -d --stack --force -f --tasks --npm --no-write --verbose -v --version -V --completion --preload -p

I'm sure it's something simple, but would love some pointers!

deepy commented 2 years ago

I'm not familiar with grunt, but having skimmed the page maybe the args is supposed to be ["--verbose", "mytask", "--version=bla"]?

I guess the question is, do you want to pass the arg to grunt or do your grunt task? If it's the former then the arg should appear before your task, if it's the latter it should appear after, probably.

StephenChamberlain commented 2 years ago

Thanks for the reply; I've tried both variants, but these both lead to the same error:

grunt-cli v1.4.3
grunt v1.4.1
Install path: C:\<my project path>\node_modules\grunt
Available tasks: mytask
Available options: --help -h --base -b --no-color --gruntfile --debug -d --stack --force -f --tasks --npm --no-write --verbose -v --version -V --completion --preload -p
deepy commented 2 years ago

I did a quick test and turns out you can stick your parameters anywhere in arguments, before or after your task.

But version is reserved for grunt and if added will produce the output you're seeing, so rename it to something that's not in grunt --help and it should work 👍

StephenChamberlain commented 2 years ago

Ah, of course; thanks! I eventually went a different route, but I will bear this in mind going forward!