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();
  });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top