From 79212325a27cf478e6e219905c989450847632bb Mon Sep 17 00:00:00 2001 From: Wes24 Date: Fri, 12 Jan 2018 16:46:01 -0500 Subject: [PATCH] Adding a callback function as a config option to the bundle complete event --- lib/stream-bundles-watch.js | 4 ++-- lib/watch/bundle-done.js | 7 +++++-- test/unit/watch/bundle-done-test.js | 8 ++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/stream-bundles-watch.js b/lib/stream-bundles-watch.js index 2f51cfde..86e7a7d5 100644 --- a/lib/stream-bundles-watch.js +++ b/lib/stream-bundles-watch.js @@ -73,7 +73,7 @@ function _bundle(config, env) { .pipe(gif(resultOpts, results(resultOpts))) .pipe(gulp.dest(config.options.dest)) .pipe(through.obj(function (file, enc, cb) { - bundleDone(prettyScriptsBundleName, start); + bundleDone(prettyScriptsBundleName, start, config.options.callback, file); })); }); @@ -109,7 +109,7 @@ function _bundle(config, env) { .pipe(gif(resultOpts, results(resultOpts))) .pipe(gulp.dest(config.options.dest)) .pipe(through.obj(function (file, enc, cb) { - bundleDone(prettyStylesBundleName, start); + bundleDone(prettyStylesBundleName, start, config.options.callback, file); })); }); diff --git a/lib/watch/bundle-done.js b/lib/watch/bundle-done.js index 5360f8e5..9178ffa3 100644 --- a/lib/watch/bundle-done.js +++ b/lib/watch/bundle-done.js @@ -4,10 +4,13 @@ var gulp = require('gulp'), prettyTime = require('pretty-hrtime'), using = require('./../using'); -module.exports = function (name, start) { +module.exports = function (name, start, callback, file) { var hrDuration = process.hrtime(start); // [seconds,nanoseconds] var time = prettyTime(hrDuration); logger.log('Finished bundling', '\'' + gutil.colors.green(name) + '\'', 'after', gutil.colors.magenta(time) ); -}; \ No newline at end of file + if (callback && typeof(callback) === 'function') { + callback(file); + } +}; diff --git a/test/unit/watch/bundle-done-test.js b/test/unit/watch/bundle-done-test.js index 2e630dd3..a8b1e76a 100644 --- a/test/unit/watch/bundle-done-test.js +++ b/test/unit/watch/bundle-done-test.js @@ -9,17 +9,21 @@ describe('bundle-done', function () { var prettyTimeStub = sinon.stub().returns(''); + var callback = sinon.spy(); + var mockFile = {}; var loggerStub = sinon.stub(); loggerStub.log = sinon.spy(); var bundleDone = proxyquire(libPath + '/watch/bundle-done', { 'pretty-hrtime': prettyTimeStub, '../service/logger': loggerStub }); - bundleDone('main.scripts', [ 1800216, 25 ]); + bundleDone('main.scripts', [ 1800216, 25 ], callback, mockFile); prettyTimeStub.calledOnce.should.be.ok; loggerStub.log.calledOnce.should.be.ok; loggerStub.log.calledWith('Finished bundling').should.be.ok; - + + callback.calledOnce.should.be.ok; + callback.calledWith(mockFile).should.be.ok; }); });