Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lazy Pipe for Gulp
var combine = require('stream-combiner');
function lazypipe() {
var createPipeline = function(tasks) {
var build = function() {
return combine.apply(null, tasks.map(function(t) {
return t.task.apply(null, t.args);
}));
};
build.pipe = function(task) {
if(!task) {
throw "Invalid call to lazypipe().pipe(): no task specified";
} else if(typeof task !== 'function') {
throw "Invalid call to lazypipe().pipe(): task is not a function";
}
return createPipeline(tasks.concat({
task: task,
args: Array.prototype.slice.call(arguments, 1)
}));
}
return build;
};
return createPipeline([]);
}
module.exports = lazypipe;
var jsHintTasks = lazypipe()
.pipe(jshint)
.pipe(jshint.reporter, 'jshint-stylish');
// this is OK, because lazypipes are immutable now
var jsTasks = jsHintTasks
.pipe(gulp.dest, 'build/js');
var cssTasks = lazypipe()
.pipe(recess, recessConfig)
.pipe(less)
.pipe(autoprefixer);
@OverZealous

This comment has been minimized.

Copy link
Owner Author

@OverZealous OverZealous commented Jan 19, 2014

Also, you can use a raw function if you need, like this:

var foo = lazypipe().pipe(function() {
        return jshint({globals: { angular: true }});
    })
    .pipe(jshint.reporter, 'jshint-stylish');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.