core
core

Reputation: 33079

Fail subsequent gulp tasks if first task fails

I have my default task in my gulpfile.js that looks something like this:

gulp.task('default', [
    'jshint',
    ...
]);

What I'd like to do is have the rest of the tasks not execute if task jshint returns warnings. In other words, "fail fast."

Is this possible? It appears to me that the tasks under default are run async, out of order—not serial.

Upvotes: 2

Views: 654

Answers (1)

Ben
Ben

Reputation: 10104

You need to do two things:

  • Use the fail reporter with jshint to make it throw errors instead of warnings.
  • Make your other tasks depend on the jshint task so that jshint always runs first.
gulp.task('default', ['js']);

gulp.task('jshint', function() {
  return gulp.src('*.js')
    .pipe(jshint(opts))
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'));
});

gulp.task('js', ['jshint'], function() {
  //somethin
});

Upvotes: 2

Related Questions