Skip to content

Instantly share code, notes, and snippets.

@a1ip
Forked from just-boris/index.js
Last active August 29, 2015 14:25
Show Gist options
  • Save a1ip/d6f25c31dacb3b96c8cc to your computer and use it in GitHub Desktop.
Save a1ip/d6f25c31dacb3b96c8cc to your computer and use it in GitHub Desktop.
Gulp wrap pipe
/**
* Wrap gulp streams into fail-safe function for better error reporting
* Usage:
* gulp.task('less', wrapPipe(function(success, error) {
* return gulp.src('less/*.less')
* .pipe(less().on('error', error))
* .pipe(gulp.dest('app/css'));
* }));
*/
function wrapPipe(taskFn) {
return function(done) {
var onSuccess = function() {
done();
};
var onError = function(err) {
done(err);
}
var outStream = taskFn(onSuccess, onError);
if(outStream && typeof outStream.on === 'function') {
outStream.on('end', onSuccess);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment