简体   繁体   English

在Node中运行Grunt任务

[英]Run Grunt tasks in Node

I'd like to know how is possible to run in a node.js file a task for grunt. 我想知道如何在node.js文件中运行grunt的任务。

I defined a task that works like that: 我定义了一个像这样工作的任务:

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

If I run it on CMD, all works fine. 如果我在CMD上运行它,一切正常。

But in the moment I try to run it in a node.js file, where there is an instruction like 但是此刻我尝试在node.js文件中运行它,其中有一个类似的指令

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... 运行“copy:backup:grunt.option(”option1“):grunt.option(”option2“)”(复制)任务...

Why this happens? 为什么会这样? And there is a smater way in nodeJS instead of this ugly exec? 在nodeJS中有一种更为强硬的方式而不是这个丑陋的exec?

Thanks in advance! 提前致谢!

You should be using a GruntFile with your defined tasks. 您应该将GruntFile与您定义的任务一起使用。 Then you simply run grunt task-name from the command line instead of running this within a separate node script. 然后,您只需从命令行运行grunt task-name ,而不是在单独的节点脚本中运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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