From 47be667590ce547f6acc21780d2d309b50109cb2 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Wed, 24 Apr 2019 13:27:26 +0100 Subject: [PATCH] Make watch task work with new Gulp API Gulp changed its API in version 4.0. The watch task was not updated to the new format when we moved to this version. This moves the watch task to the new format. --- gulpfile.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 15df27cb6..648bf86eb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,7 @@ // 1. LIBRARIES // - - - - - - - - - - - - - - - -const { src, pipe, dest, series, parallel } = require('gulp'); +const { src, pipe, dest, series, parallel, watch } = require('gulp'); const stylish = require('jshint-stylish'); const plugins = {}; @@ -142,14 +142,26 @@ const images = () => { }; -// Watch for changes and re-run tasks -const watchForChanges = () => { - return watch(paths.src + 'javascripts/**/*', ['javascripts']) - .watch(paths.src + 'stylesheets/**/*', ['sass']) - .watch(paths.src + 'images/**/*', ['images']) - .watch('gulpfile.js', ['default']); +const watchFiles = { + javascripts: (cb) => { + watch([paths.src + 'javascripts/**/*'], javascripts); + cb(); + }, + sass: (cb) => { + watch([paths.src + 'stylesheets/**/*'], sass); + cb(); + }, + images: (cb) => { + watch([paths.src + 'images/**/*'], images); + cb(); + }, + self: (cb) => { + watch(['gulpfile.js'], defaultTask); + cb(); + } }; + const lint = { 'sass': () => { return src([ @@ -171,6 +183,7 @@ const lint = { } }; + // Default: compile everything const defaultTask = parallel( series( @@ -188,6 +201,16 @@ const defaultTask = parallel( ) ); + +// Watch for changes and re-run tasks +const watchForChanges = parallel( + watchFiles.javascripts, + watchFiles.sass, + watchFiles.images, + watchFiles.self +); + + exports.default = defaultTask; exports.lint = series(lint.sass, lint.js);