From 8a30c31243a2a43cace5d69fba5af0f346c628ea Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sun, 23 Nov 2014 17:50:30 -0500 Subject: [PATCH] Adding error notification to gulp tasks --- config.json | 1 - gulpfile.js | 31 +++++++++++++++++++++++-------- package.json | 6 ++++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/config.json b/config.json index 6a385b5..a6cd00c 100644 --- a/config.json +++ b/config.json @@ -14,7 +14,6 @@ "sourcemap": true }, "browserify": { - "entries": ["./main.js"], "basedir": "./src/js", "debug": true } diff --git a/gulpfile.js b/gulpfile.js index 70e04b8..f049821 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,14 @@ var gulp = require('gulp'), + notify = require('gulp-notify'), + plumber = require('gulp-plumber'), config = require('./config'); +function errorHandler() { + return plumber({ + errorHandler: notify.onError('Error: <%= error.message %>') + }); +} + gulp.task('default', ['server'], function() { gulp.watch(config.globs.other, ['static']); gulp.watch([config.globs.html, config.templateFile], ['markup']); @@ -14,6 +22,7 @@ gulp.task('server', ['build'], function() { watch('./build/**/*', { name: 'Server' }) .pipe(connect.reload()); + return connect.server({ root: './build', livereload: true @@ -24,6 +33,7 @@ gulp.task('build', ['static', 'markup', 'compass', 'browserify']); gulp.task('static', function() { return gulp.src(config.globs.other) + .pipe(errorHandler()) .pipe(gulp.dest('./build')); }); @@ -31,6 +41,7 @@ gulp.task('markup', function() { var wrap = require('gulp-wrap'); return gulp.src(config.globs.html) + .pipe(errorHandler()) .pipe(wrap({ src: config.templateFile })) .pipe(gulp.dest('./build')); }); @@ -39,20 +50,24 @@ gulp.task('compass', function() { var compass = require('gulp-compass'); return gulp.src(config.globs.sass) + .pipe(errorHandler()) .pipe(compass(config.compass)); }); gulp.task('browserify', function() { var browserify = require('browserify'), es6ify = require('es6ify'), - source = require('vinyl-source-stream'); - bundler = browserify(config.browserify); + tap = require('gulp-tap'); - bundler.add(es6ify.runtime); - bundler.transform(es6ify); + return gulp.src('./src/js/main.js', { read: false }) + .pipe(errorHandler()) + .pipe(tap(function(file) { + var bundler = browserify(config.browserify); - return bundler - .bundle() - .pipe(source('js/main.js')) - .pipe(gulp.dest('./build')); + bundler.add([file.path, es6ify.runtime]); + bundler.transform(es6ify); + + file.contents = bundler.bundle(); + })) + .pipe(gulp.dest('./build/js')); }); diff --git a/package.json b/package.json index 1552b23..0d3b9b3 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,10 @@ "gulp": "^3.8.10", "gulp-compass": "^2.0.3", "gulp-connect": "^2.2.0", + "gulp-notify": "^2.0.1", + "gulp-plumber": "^0.6.6", + "gulp-tap": "^0.1.3", "gulp-watch": "^2.0.0", - "gulp-wrap": "^0.5.0", - "vinyl-source-stream": "^1.0.0" + "gulp-wrap": "^0.5.0" } }