-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENHANCEMENT] Gulp-If should support lazy evaluation #75
Comments
I like this idea, but so far we've been unable to find a syntax that
doesn't look conveluted. Lazypipe's syntax is just weird. Do you have a
proposal for how this should look?
|
I wasn't sure how to make the arguments lazily evaluated without resorting to using the same syntax as lazy pipe. This is the syntax I settled on. There are two: gulp.task('default', () => {
return gulpIf(true)
.then(gulp.src, ['**/*.ts'])
.otherwise(gulp.src, ['**/*.js'])
.pipe(concat('files.txt'))
.pipe(gulp.dest('dist'));
}); This first one uses the builder pattern to build the full stream gulp.task('test1', () => {
return gulp.src(['**/*', '!dist/**/*', '!dist/']).pipe(
gulpIf({
condition: (vf: Vinyl) => vf.path.endsWith('.js'),
thenStream: concat('all.js')
}).otherwise(concat, 'rest.txt'))
.pipe(gulp.dest('dist'));
}); This one uses an options parameter to specify the condition, and branches. You can also specify the Here is an example that brings them all together including showing how to include minimatch options: gulp.task('test3', () => {
return gulp.src(['**/*', '!dist/**/*', '!dist/']).pipe(
gulpIf({
condition: (vf: Vinyl) => vf.path.endsWith('.js'),
thenStream: gulpIf('INDEX.JS', {nocase: true}).then(concat, 'found.index.js')
}).otherwise(concat, 'rest.txt'))
.pipe(gulpIf('*.+(index.js|txt)').then(concat('index-and-nonjs.txt'))
.otherwise(concat, 'something.txt'))
.pipe(gulp.dest('dist'));
}); You can find the complete project at https://github.com/smac89/gulp-if. It is in typescript mind you. After doing |
At the moment, it requires one to pass in an already existing stream as parameter. It would be nice if instead, one can pass in a function which returns a stream.
The benefit of this is that the conditions are evaluated lazily rather than eagerly, thus making it possible for to pass in streams with side-effects, but only the side-effects of the chosen stream will occur and not the other.
I'm sure there are other benefits to having lazily evaluated operands, but that's all I can think of atm, because it relates to my use-case.
If this is something you would like, I would be glad to create a pull request once it's ready.
The text was updated successfully, but these errors were encountered: