Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 839
GTDev Avatar asked May 10 '13 17:05

GTDev


1 Answers

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();
  });
});
like image 153
Kyle Robinson Young Avatar answered Nov 17 '22 09:11

Kyle Robinson Young