如何将一个npm脚本转换成一个咕task任务? [英] How to transform a npm script to a grunt task?
本文介绍了如何将一个npm脚本转换成一个咕task任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
scripts:{
start: grunt,
test:node --debug --harmony node_modules / grunt-cli / bin / grunt test
}
我正在运行节点v0.11.13,因此我需要设置--harmony标志。在grunt上测试配置正确,如果我用npm测试启动它们,但我宁愿将它全部放在grunt文件中。有没有办法配置grunt来启动服务器并运行测试?
grunt与这些节点标志,像这样: grunt.registerTask('debug',function(){
var done = this.async();
//指定要生成的任务
var tasks = Array.prototype.slice.call(arguments,0);
grunt.util.spawn({
//使用现有节点路径
cmd:process.execPath,
//添加标志并使用process.argv [1]获取grunt bin的路径
args: ['--debug','--harmony',process.argv [1]]。concat(任务),
//打印此进程正在对父级stdio执行的所有操作
opts:{stdio :'inherit'}
},done);
});
然后你可以启动服务器并运行测试: grunt default debug:测试
或者真的有任何组合:
-
grunt server test
(同时运行时不使用节点标志)
grunt debug:server:test
(同时使用节点标志运行)。
I have the following script with my nodeJS.
"scripts": {
"start": "grunt",
"test": "node --debug --harmony node_modules/grunt-cli/bin/grunt test"
}
I am running node v0.11.13 so I need to set --harmony flag. On grunt the tests are configured right if I start them with npm test, but I would prefer to have it all in a gruntfile. Is there a way to configure grunt to start the server and also run the test ?
解决方案
You can create an alias task that spawns grunt with those node flags, like such:
grunt.registerTask('debug', function() {
var done = this.async();
// Specify tasks to run spawned
var tasks = Array.prototype.slice.call(arguments, 0);
grunt.util.spawn({
// Use the existing node path
cmd: process.execPath,
// Add the flags and use process.argv[1] to get path to grunt bin
args: ['--debug', '--harmony', process.argv[1]].concat(tasks),
// Print everything this process is doing to the parent stdio
opts: { stdio: 'inherit' }
}, done);
});
Then you can start the server and run tests with: grunt default debug:test
Or really any combination:
grunt server test
(runs both without node flags)grunt debug:server:test
(runs both with node flags).
这篇关于如何将一个npm脚本转换成一个咕task任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文