我想创建一个连续运行 3 个 grunt 任务的 grunt 文件,无论它们是失败还是通过。如果其中一个 grunts 任务失败,我想返回最后一个错误代码。
我试过:
grunt.task.run('task1', 'task2', 'task3');
运行时使用--force
选项。
问题在于,当指定 --force
时,无论出现什么错误,它都会返回错误代码 0。
谢谢
最佳答案
使用 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();
});
});
关于javascript - Gruntfile 从程序中串行获取错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16487681/