From feba17e4e55a2e40a16768ddd7484b5e2c91ec72 Mon Sep 17 00:00:00 2001 From: Modestas Vainius Date: Tue, 9 Jun 2015 08:52:35 +0300 Subject: [PATCH] Expose original 'done' callback to the custom callback. This can be done via this.webpackDone in the custom callback. --- index.js | 56 +++++++++++++++++++++++++++++-------------------------- readme.md | 7 ++++++- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index 928e11f..17dd259 100644 --- a/index.js +++ b/index.js @@ -25,34 +25,38 @@ var defaultStatsOptions = { module.exports = function(options, wp, done) { options = options || {}; - if (typeof done !== 'function') { - var callingDone = false; - done = function(err, stats) { - stats = stats || {}; - if (options.quiet || callingDone) { - return; - } - // Debounce output a little for when in watch mode - if (options.watch) { - callingDone = true; - setTimeout(function() { callingDone = false; }, 500); - } - if (options.verbose) { - gutil.log(stats.toString({ - colors: gutil.colors.supportsColor, - })); - } else { - var statsOptions = options && options.stats || {}; - - Object.keys(defaultStatsOptions).forEach(function(key) { - if (typeof statsOptions[key] === 'undefined') { - statsOptions[key] = defaultStatsOptions[key]; - } - }); - gutil.log(stats.toString(statsOptions)); - } + var callingDone = false; + var webpackDone = function(err, stats) { + stats = stats || {}; + if (options.quiet || callingDone) { + return; + } + // Debounce output a little for when in watch mode + if (options.watch) { + callingDone = true; + setTimeout(function() { callingDone = false; }, 500); + } + if (options.verbose) { + gutil.log(stats.toString({ + colors: gutil.colors.supportsColor, + })); + } else { + var statsOptions = options && options.stats || {}; + + Object.keys(defaultStatsOptions).forEach(function(key) { + if (typeof statsOptions[key] === 'undefined') { + statsOptions[key] = defaultStatsOptions[key]; + } + }); + + gutil.log(stats.toString(statsOptions)); } + }; + if (typeof done === 'function') { + done = done.bind({ 'webpackDone': webpackDone }); + } else { + done = webpackDone; } var webpack = wp || require('webpack'); diff --git a/readme.md b/readme.md index 0ecd314..4805829 100644 --- a/readme.md +++ b/readme.md @@ -54,7 +54,9 @@ gulp.task('default', function() { }); ``` -Pass in 3rd argument if you want to access the stats outputted from webpack when the compilation is done: +Pass in 3rd argument if you want to access the stats outputted from webpack when the compilation is done. +In addition, if you wish to delegate to the original done callback, you may do it via call to +`this.webpackDone`: ```js @@ -66,6 +68,9 @@ gulp.task('default', function() { /* config */ }, null, function(err, stats) { /* Use stats to do more things if needed */ + + /* Call original callback if needed */ + this.webpackDone(err, stats); })) .pipe(gulp.dest('dist/')); });