1.0.1 • Published 7 years ago

gulp-stream-to-promise2 v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

gulp-stream-to-promise2

Returns a promise from a Gulp stream, plus (optionally) catches pipeline-breaking errors for Gulp v3.

Installation

npm install --save gulp-stream-to-promise2

Usage

Passing a stream

If passed a Gulp stream, gulpStreamToPromise will then return a Promise;

/* ... */
var gulpStreamToPromise = require('gulp-stream-to-promise2');

gulp.task('default', function(){
    var stream = gulp.src( /* ... */ )
        .pipe(examplePlugin())
        .pipe(anotherExamplePlugin());

    return gulpStreamToPromise(stream)
        .then(function(){ /* success */ })
        .catch(function(err){ /* error */ });
});

Passing a callback function

If you choose to pass a callback, it must return a gulp stream. Your callback will get called with two arguments;

  • plumbErrors: (Function) if used in your pipeline, any errors in following pipes won't kill your pipeline / file-watching. Uses gulp-plumber under the hood.
  • stopPlumbingErrors: (Function) if you've used plumbErrors, you can use this function to resume default behaves for any following pipes.

Note: you don't need to call these plumbing functions if you're using Gulp v4+.

gulpStreamToPromise will then return a Promise;

/* ... */
var gulpStreamToPromise = require('gulp-stream-to-promise2');

gulp.task('default', function(){
    return gulpStreamToPromise(function(plumbErrors, stopPlumbingErrors){
        return gulp.src( /* ... */ )
            .pipe(plumbErrors())
            .pipe(examplePlugin()) // errors from this plugin won't kill your build
            .pipe(stopPlumbingErrors())
            .pipe(anotherExamplePlugin()); // errors from this plugin will kill your build
    })
    .then(function(){ /* success */ })
    .catch(function(err){ /* error */ });
});