Lazypipe allows you to create an immutable, lazily-initialized pipeline. It's designed to be used in an environment where you want to reuse partial pipelines, such as with gulp.
This module returns a function that can be used to start building a lazypipe. Individual steps are added via the
.pipe() method. At any point, a new lazypipe can be built by adding to an existing one, without affecting the previous lazypipe. Lazypipes can even be used as steps within another lazypipe.
Once the partial pipeline is ready to use, call the last result from
.pipe() directly as a function (e.g.:
npm i --save-dev lazypipe
Then create lazypipes like so:
// Example usage within a gulpfilevar lazypipe = ;...// initialize a lazypipevar jsHintTasks =// adding a pipeline step, notice the stream function has not been called!// adding a step with an argument;// this is OK, because lazypipes are immutable// jsHintTasks will _not_ be affected by the addition.var jsTasks = jsHintTasks;// Create another pipevar cssTasks =;// now using the lazypipesgulp;gulp;gulp;
You can combine lazypipes in various ways:
// streamA -> streamBvar foo = ;// streamA -> streamB -> streamCvar bar = foo;// streamD -> streamA -> streamB -> streamEvar baz = ;
Lazypipe assumes that all function parameters are static, gulp-if arguments need to be instantiated inside each lazypipe. This difference can be easily solved by passing a function on the lazypipe step
var gulpif = ;var jshint = ;var uglify = ;var concat = ;var compressing = false;var jsChannel =// adding a pipeline step// notice the stream function has not been called!// adding a step with an argument// adding a step with multiple arguments// you can't say: .pipe(gulpif, compressing, uglify)// because uglify needs to be instantiated separately in each lazypipe instance// you can say this instead:;// why does this work? lazypipe calls the function, passing in the no arguments to it,// it instantiates a new gulp-if pipe and returns it to lazypipe.gulp;
Initializes a lazypipe. Returns a function that can be used to create the pipeline. The returned function has a function (
pipe) which can be used to create new lazypipes with an additional step.
Creates a new lazy pipeline with all the previous steps, and the new step added to the end. Returns the new lazypipe.
fn- a stream creation function to call when the pipeline is created later. You can either provide existing functions (such as gulp plugins), or provide your own custom functions if you want to manipulate the stream before creation.
arg1, arg2, ...- Any remaining arguments are saved and passed into
fnwhen the pipeline is created.
The arguments allows you to pass in configuration arguments when the pipeline is created, like this:
var pipeline = ;// now, when gulp.src().pipe(pipeline()) is called later, it's as if you did:gulp;
Calling the result of
pipe() as a function builds the pipeline at that time. This can be used multiple times, and can even be called if the lazypipe was used to create different pipelines.
It returns a stream created using
stream-combiner, where all the internal steps are processed sequentially, and the final result is passed on.
If you'd like to support this and other OverZealous Creations (Phil DeJarnett) projects, donate via Gratipay!