npkgz/gulp-prettyerror

Does not show the error in the first task in a loop

Closed this issue · 2 comments

haqqi commented

Hi, i have created a gulpfile.js looks like below:

// require all the libraries
const gulp          = require('gulp'),
      babel         = require('gulp-babel')
      changed       = require('gulp-changed'),
      prettyError   = require('gulp-prettyerror');

// react source map
const moduleSources = {
  squarebook: {
    src   : './common/modules/squarebook/web/jsx/*.{js,jsx}',
    dest   : './common/modules/squarebook/web/js'
  },
  frontend: {
    src   : './frontend/web/jsx/*.{js,jsx}',
    dest  : './frontend/web/js'
  }
}

gulp.task('babel', function () {
  for(var moduleName in moduleSources) {
    var sourceMap = moduleSources[moduleName];
    var taskName = 'babel:' + moduleName;

    // create the task
    gulp.task(taskName, function () {
      return gulp.src(sourceMap.src)
        .pipe(changed(sourceMap.dest)) // make sure only changed source
        .pipe(prettyError())
        .pipe(babel()) // do the babel
        .pipe(gulp.dest(sourceMap.dest));
    });
    // do the watcher
    gulp.watch(sourceMap.src, [taskName]);
  }
});

gulp.task('default', [
  'babel'
]);

Now that i have tried to create an error on the './common/modules/squarebook/web/jsx/*.{js,jsx}', the error is not displayed. It seems that prettyError only shows the error in the last loop. The watcher is not breaking, but the error is not displayed. Any idea why this is happening?

haqqi commented

Sorry, seems like my for loop is the cause of the problem. But still, i do now know why.