npkgz / gulp-prettyerror

:hash: Display Errors in a pretty way, without breaking watch tasks
https://www.npmjs.com/package/gulp-prettyerror
MIT License
14 stars 1 forks source link

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

Closed haqqi closed 8 years ago

haqqi commented 8 years ago

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 8 years ago

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

AndiDittrich commented 8 years ago

2