Marcio Cruz Marcio Cruz - 2 months ago 6
Node.js Question

gulp end callback not called

I'm having trouble setting up a simple task on gulp. I want to pass the files through

gulp-babel
to run a script, but the
end
callback is never called.

I also tried
finish
. The only callback called is
data
, but it doesn't work for me because I need to run it after all the files ran through babel.

gulp-debug
shows the files have been correctly found.

Any toughts?

(function () {
'use strict';

var gulp = require('gulp'),
babel = require('gulp-babel'),
debug = require('gulp-debug');


gulp.task('parseReviews', function () {
gulp.src(['scripts/parseReviews.js', 'src/**/*.js'])
.pipe(debug())
.pipe(babel())
.on('end', function () {
const foo = require('../../scripts/parseReviews');
console.log(foo);
});
});
})();

Answer

You need to return your stream from your task:

gulp.task('parseReviews', function () {
  return gulp.src(['scripts/parseReviews.js', 'src/**/*.js'])
    .pipe(debug())
    .pipe(babel())
    .on('end', function () {
        const foo = require('../../scripts/parseReviews');
        console.log(foo);
    });
});