How to get gulp error message in file missing?

I have gulpfile.js configured as follows:

var scripts = [ 'bower_components/timezone-js/src/date.js', 'bower_components/jquery/jquery.min.js', 'bower_components/jquery-migrate/jquery-migrate.js', 'bower_components/jquery-ui/ui/minified/jquery-ui.min.js', 'bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.min.js', ... ]; gulp.task('scripts', function () { return gulp.src(scripts, {base: '.'}) .pipe(plumber(plumberOptions)) .pipe(sourcemaps.init({ loadMaps: false, debug: debug, })) ... 

ie, all my script files are exact matches. No swallowing.

From time to time I messed up the file path or the author changes the directory structure. I want to be notified when this happens instead of a script that will be disabled and will cause errors at runtime.

Can I make gulp.src report these errors?

+5
source share
2 answers

Use gulp-expect-file as per this answer .

 var coffee = require('gulp-coffee'); var expect = require('gulp-expect-file'); gulp.task('mytask', function() { var files = ['idontexist.html']; return gulp.src(files) .pipe(expect(files)) .pipe(coffee()); }); 

(Thanks rve )

+5
source

gulp.src is actually just an alias for vinyl-fs.src , which looks like this:

 function src(glob, opt) { opt = opt || {}; var pass = through.obj(); if (!isValidGlob(glob)) { throw new Error('Invalid glob argument: ' + glob); } // return dead stream if empty array if (Array.isArray(glob) && glob.length === 0) { process.nextTick(pass.end.bind(pass)); return pass; } var options = defaults(opt, { read: true, buffer: true }); var globStream = gs.create(glob, options); // when people write to use just pass it through var outputStream = globStream .pipe(through.obj(createFile)) .pipe(getStats(options)); if (options.read !== false) { outputStream = outputStream .pipe(getContents(options)); } return outputStream.pipe(pass); } 

In turn, it uses glob-stream , which uses glob . You can possibly get around most of this and use through2 directly to create a channel from the array files. I have not figured out how to do this yet.

0
source

All Articles