Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get gulp to error on missing file?

I've got gulpfile.js set up like this:

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,
        }))
        ...

i.e., all my script files are exact matches. No globbing.

Every now and then I mess up a file path or the author changes the directory structure. I want to be notified when this happens instead of the script silently being excluded and causing run-time errors.

Is there some way for me to make gulp.src report these kinds of errors?

like image 297
mpen Avatar asked May 15 '15 17:05

mpen


1 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)

like image 159
mpen Avatar answered Nov 10 '22 18:11

mpen