Running Grunt Tasks in Node

I would like to know how a task for grunt can be run in the node.js file.

I have defined a task that works like this:

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

      

If I run it on CMD everything works fine.

But 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);

      

the following happens:

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

Why is this happening? And in the JS node is there a smater way instead of that ugly exec?

Thanks in advance!

+3


source to share


1 answer


You have to use GruntFile with specific tasks. Then you just run grunt task-name

from the command line rather than running it in a separate node script.



0


source







All Articles