문제 설명
프로그램에서 연속적으로 오류 코드를 받는 Gruntfile (Gruntfile getting error codes from programs serially)
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
참조 솔루션
방법 1:
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();
});
});
(by GTDev、Kyle Robinson Young)