0

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);
        });
    });
})();
Marcio Cruz
  • 2,012
  • 1
  • 23
  • 30
  • Did you try to catch the 'error' event in order to be sure that no error occurred while running your pipeline? https://nodejs.org/api/stream.html#stream_event_error – Reuven Chacha Oct 03 '16 at 15:06
  • Are you sure that this pattern `'src/**/*.js'` does not pick a huge number of files? Try to run it and open a task manager (top in case of linux) and check if gulp is present there. If you are able to see it in the task manager and it is working really hard, then it is quite possible that this pattern is wrong. – Stavros Zavrakas Oct 03 '16 at 15:11
  • Thanks for the tip, Reuven. I just tried and the error callback is not called. – Marcio Cruz Oct 03 '16 at 15:11
  • Svabael, I used gulp-debug to see the files, it's a small project and it brings only 22 files. – Marcio Cruz Oct 03 '16 at 15:12

1 Answers1

2

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);
    });
});
Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70
  • That worked, thanks! Now I have to figure out why I'm still getting `unexpected token import` despite calling babel before. But thats unrelated to the question. – Marcio Cruz Oct 03 '16 at 16:14