Gruntfile从程序串行获取错误代码 [英] Gruntfile getting error codes from programs serially
本文介绍了Gruntfile从程序串行获取错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个连续运行3个grunt任务的grunt文件,不管它们是失败还是通过。如果其中一个咕噜声任务失败,我想返回上一个错误代码。
我试过了:
grunt.task.run('task1','task2','task3');
在运行时使用 - force
选项。
这个问题是,当指定 --force
时,无论错误如何,它都会返回错误码0。 / p>
感谢
解决方案使用
grunt.util .spawn
: http://gruntjs.com/api/grunt.util# grunt.util.spawn grunt.registerTask('serial',function(){
var做= this.async();
变种任务= { '任务1':0,1 'TASK2':0, 'TASK3':0};
grunt.util.async.forEachSeries(Object.keys (任务),函数(task,next){
grunt.util.spawn({
grunt:true,//使用grunt来产生
args:[task],//产生这个任务
opts:{stdio:'inherit'},//打印到相同的标准输出
},函数(err,result,code){
tasks [task] = code;
next();
});
},function(){
//现在执行一些任务,每个
//包含它们各自的错误代码
done();
});
});
I want to create a grunt file that runs 3 grunt tasks serially one after another regardless of whether they fail or pass. If one of the grunts task fails, I want to return the last error code.
I tried:
grunt.task.run('task1', 'task2', 'task3');
with the --force
option when running.
The problem with this is that when --force
is specified it returns errorcode 0 regardless of errors.
Thanks
解决方案
Use grunt.util.spawn
: http://gruntjs.com/api/grunt.util#grunt.util.spawn
grunt.registerTask('serial', function() {
var done = this.async();
var tasks = {'task1': 0, 'task2': 0, 'task3': 0};
grunt.util.async.forEachSeries(Object.keys(tasks), function(task, next) {
grunt.util.spawn({
grunt: true, // use grunt to spawn
args: [task], // spawn this task
opts: { stdio: 'inherit' }, // print to the same stdout
}, function(err, result, code) {
tasks[task] = code;
next();
});
}, function() {
// Do something with tasks now that each
// contains their respective error code
done();
});
});
这篇关于Gruntfile从程序串行获取错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文