Last active
April 10, 2019 20:59
-
-
Save just-boris/89ee7c1829e87e2db04c to your computer and use it in GitHub Desktop.
Gulp wrap pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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
Let's assume I have few consecutive actions in one task. I have to catch errors for each of them?
Somehow like this way?