From 265453ff0994656b6aa593372260a08cf81b7da8 Mon Sep 17 00:00:00 2001 From: Pascal Andy Date: Tue, 12 Feb 2019 14:06:20 -0500 Subject: [PATCH] (2.9.2) Updated gulp to handle errors for every stream Signed-off-by: Pascal Andy --- gulpfile.js | 74 +++++++++++++++++++++++++++++----------------------- package.json | 31 +++++++++++----------- 2 files changed, 57 insertions(+), 48 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 831e70f..779a588 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,13 +1,14 @@ var gulp = require('gulp'); +var pump = require('pump'); // gulp plugins and utils -var gutil = require('gulp-util'); var livereload = require('gulp-livereload'); var postcss = require('gulp-postcss'); var sourcemaps = require('gulp-sourcemaps'); var zip = require('gulp-zip'); var uglify = require('gulp-uglify'); var filter = require('gulp-filter'); +var beeper = require('beeper'); // postcss plugins var autoprefixer = require('autoprefixer'); @@ -16,23 +17,26 @@ var cssnano = require('cssnano'); var customProperties = require('postcss-custom-properties'); var easyimport = require('postcss-easy-import'); -var swallowError = function swallowError(error) { - gutil.log(error.toString()); - gutil.beep(); - this.emit('end'); -}; - var nodemonServerInit = function () { livereload.listen(1234); }; +function handleError(done) { + return function (err) { + if (err) { + beeper(); + } + return done(err); + }; +} + gulp.task('build', ['css', 'js'], function (/* cb */) { return nodemonServerInit(); }); gulp.task('generate', ['css', 'js']); -gulp.task('css', function () { +gulp.task('css', function (done) { var processors = [ easyimport, customProperties, @@ -41,45 +45,49 @@ gulp.task('css', function () { cssnano() ]; - return gulp.src('assets/css/*.css') - .on('error', swallowError) - .pipe(sourcemaps.init()) - .pipe(postcss(processors)) - .pipe(sourcemaps.write('.')) - .pipe(gulp.dest('assets/built/')) - .pipe(livereload()); + pump([ + gulp.src('assets/css/*.css'), + sourcemaps.init(), + postcss(processors), + sourcemaps.write('.'), + gulp.dest('assets/built/'), + livereload() + ], handleError(done)); }); -gulp.task('js', function () { +gulp.task('js', function (done) { var jsFilter = filter(['**/*.js'], {restore: true}); - return gulp.src('assets/js/*.js') - .on('error', swallowError) - .pipe(sourcemaps.init()) - .pipe(jsFilter) - .pipe(uglify()) - .pipe(jsFilter.restore) - .pipe(sourcemaps.write('.')) - .pipe(gulp.dest('assets/built/')) - .pipe(livereload()); + pump([ + gulp.src('assets/js/*.js'), + sourcemaps.init(), + jsFilter, + uglify(), + jsFilter.restore, + sourcemaps.write('.'), + gulp.dest('assets/built/'), + livereload() + ], handleError(done)); }); gulp.task('watch', function () { gulp.watch('assets/css/**', ['css']); }); -gulp.task('zip', ['css', 'js'], function () { +gulp.task('zip', ['css', 'js'], function (done) { var targetDir = 'dist/'; var themeName = require('./package.json').name; var filename = themeName + '.zip'; - return gulp.src([ - '**', - '!node_modules', '!node_modules/**', - '!dist', '!dist/**' - ]) - .pipe(zip(filename)) - .pipe(gulp.dest(targetDir)); + pump([ + gulp.src([ + '**', + '!node_modules', '!node_modules/**', + '!dist', '!dist/**' + ]), + zip(filename), + gulp.dest(targetDir) + ], handleError(done)); }); gulp.task('default', ['build'], function () { diff --git a/package.json b/package.json index cb3dfdb..caa5271 100644 --- a/package.json +++ b/package.json @@ -46,21 +46,22 @@ "bugs": "https://github.com/firepress-org/FirePress_Klimax2/issues", "contributors": "https://github.com/TryGhost/Casper/graphs/contributors", "devDependencies": { - "autoprefixer": "6.3.6", - "cssnano": "3.7.1", - "gscan": "^2.0.0", - "gulp": "3.9.1", - "gulp-livereload": "3.8.1", - "gulp-postcss": "6.1.1", - "gulp-sourcemaps": "1.6.0", - "gulp-util": "3.0.7", - "gulp-watch": "4.3.8", - "gulp-zip": "4.0.0", - "postcss-color-function": "2.0.1", - "postcss-custom-properties": "5.0.1", - "postcss-easy-import": "1.0.1", - "gulp-filter": "5.1.0", - "gulp-uglify": "3.0.1" + "autoprefixer": "6.3.6", + "beeper": "^1.1.1", + "cssnano": "3.7.1", + "gscan": "^2.0.0", + "gulp": "3.9.1", + "gulp-filter": "5.1.0", + "gulp-livereload": "3.8.1", + "gulp-postcss": "6.1.1", + "gulp-sourcemaps": "1.6.0", + "gulp-uglify": "3.0.1", + "gulp-watch": "4.3.8", + "gulp-zip": "4.0.0", + "postcss-color-function": "2.0.1", + "postcss-custom-properties": "5.0.1", + "postcss-easy-import": "1.0.1", + "pump": "3.0.0" }, "config": { "posts_per_page": 25,