Grunt task that can be run without arguments

I am trying to write a grunt task with api identical to the unix mv command.

I would like to call him using grunt mv path/to/old/file path/to/new/file.

I was hoping that I could do this by contacting node process.argv, however, when I call a task using this API, grunt tries to treat it path/to/old/fileas another task that I am trying to run, it throws an error, which Warning: Task "path/to/old/file" not found. Use --force to continue.quits.

Is there a way to do what I'm trying to do?

+4
source share
3 answers

I think you are looking for the parameter --options http://gruntjs.com/frequently-asked-questions#options .

, grunt mv --from=path/to/old/file --to=path/to/new/file.

+1

, ":",

grunt mv:path/to/old/file:path/to/new/file

. this.args. . https://github.com/Grunt-generate/grunt-generate/blob/master/tasks/generate.js . API doc: http://gruntjs.com/api/inside-tasks

+1

process.argv :

, . be 'node', JavaScript. .

:

: mv.js

console.log(process.argv[2]);
console.log(process.argv[3]);

, : node mv.js /// ///

:

path/to/old/file
path/to/new/file
0

Source: https://habr.com/ru/post/1538903/


All Articles