Snippet:
gulp.task('foo', [], function() {
var barFiles = getBarFiles();
var bazFiles = getBazFiles();
var barStream, bazStream;
if (barFiles && barFiles.length > 0) {
barStream = gulp.src(barFiles);
}
if (bazStream && bazStream.length > 0) {
bazStream = gulp.src(bazStream);
}
return eventStream
.merge(barStream, bazStream)
.pipe(g.concat('bar-and-baz'))
.pipe(gulp.dest('./foo-output/'));
});
getBarFiles()
or getBazFiles()
may potentially return an empty array,
which won't work with gulp.src()
: resulting in Error: Invalid glob argument
,
hence the need to create a stream only when files are present.
The main query is, how can an empty stream be constructed, to be combined with another empty or non-empty stream?