Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemon restart run gulp tasks

I have the following code in my gulpfile

gulp.task('scripts', function () {
    gulp.src(paths.browserify)
        .pipe(browserify())
        .pipe(gulp.dest('./build/js'))
        .pipe(refresh(server));
});

gulp.task('lint', function () {
    gulp.src(paths.js)
        .pipe(jshint())
        .pipe(jshint.reporter(stylish));
});

gulp.task('nodemon', function () {
    nodemon({
        script: 'app.js'
    });
});

I need to run the scripts and lint tasks when Nodemon restarts.I have the following

gulp.task('nodemon', function () {
    nodemon({
        script: 'app.js'
    }).on('restart', function () {
        gulp.run(['scripts', 'lint']);
    });
});

Gulp.run() is now deprecated, so how would I achieve the above using gulp and best practices?

like image 681
TYRONEMICHAEL Avatar asked Feb 06 '14 09:02

TYRONEMICHAEL


2 Answers

gulp-nodemon documentation states that you can do it directly, passing an array of tasks to execute:

nodemon({script: 'app.js'}).on('restart', ['scripts', 'lint']);

See doc here

UPDATE, as the author of gulp-nodemon uses run as well:

Idea #1, use functions:

var browserifier = function () {
  gulp.src(paths.browserify)
    .pipe(browserify())
    .pipe(gulp.dest('./build/js'))
    .pipe(refresh(server));
});

gulp.task('scripts', browserifier);

var linter = function () {
  gulp.src(paths.js)
    .pipe(jshint())
    .pipe(jshint.reporter(stylish));
});

gulp.task('lint', linter);

nodemon({script: 'app.js'}).on('restart', function(){
  linter();
  browserifier();
});
like image 69
Mangled Deutz Avatar answered Oct 19 '22 14:10

Mangled Deutz


If you can, use Mangled Deutz's suggestion about using functions. That's the best, most guaranteed way to make sure this works now and going forward.

However, functions won't help if you need to run dependent tasks or a series of tasks. I wrote run-sequence to fix this. It doesn't rely on gulp.run, and it's able to run a bunch of tasks in order.

like image 33
OverZealous Avatar answered Oct 19 '22 14:10

OverZealous