Gruntfile getting error codes from programs serially

可紊 提交于 2019-12-22 07:04:10

问题


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();
  });
});


来源:https://stackoverflow.com/questions/16487681/gruntfile-getting-error-codes-from-programs-serially

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!