Skip to content

Commit

Permalink
Adding a callback function as a config option to the bundle complete …
Browse files Browse the repository at this point in the history
…event
  • Loading branch information
Wes24 authored and Wes24 committed Jan 12, 2018
1 parent 56f9bab commit b796164
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/stream-bundles-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));

});
Expand Down Expand Up @@ -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);
}));

});
Expand Down
7 changes: 5 additions & 2 deletions lib/watch/bundle-done.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
};
if (callback && typeof(callback) === 'function') {
callback(file);
}
};
8 changes: 6 additions & 2 deletions test/unit/watch/bundle-done-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

});

0 comments on commit b796164

Please sign in to comment.