简体   繁体   中英

Run Grunt tasks in Node

I'd like to know how is possible to run in a node.js file a task for grunt.

I defined a task that works like that:

grunt backup --option1=sourceFolder --option2=destFolder

If I run it on CMD, all works fine.

But in the moment I try to run it in a node.js file, where there is an instruction like

var sourceFolder = __dirname + "\\" + process.argv[2];
var destFolder = __dirname + "\\"+ process.argv[3]; 

...other things...

exec("grunt backup --option1=" + sourceFolder + " --option2=" + destFolder);

happens this:

Running "copy:backup:grunt.option("option1"):grunt.option("option2")" (copy) task...

Why this happens? And there is a smater way in nodeJS instead of this ugly exec?

Thanks in advance!

You should be using a GruntFile with your defined tasks. Then you simply run grunt task-name from the command line instead of running this within a separate node script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM