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 26, 2018
1 parent 56f9bab commit 2ede231
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 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
8 changes: 6 additions & 2 deletions lib/watch/bundle-done.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ 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);
}
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@
"gulp-jshint": "1.11.0",
"gulp-mocha": "2.1.1",
"gulp-nice-package": "1.0.0",
"gulp-sass": "2.0.4",
"gulp-sass": "2.0.2",
"gulp-shrinkwrap": "2.0.1",
"jshint-stylish": "2.0.0",
"mocha-lcov-reporter": "0.0.2",
"multiline": "1.0.2",
"node-sass": "^4.7.2",
"proxyquire": "1.5.0",
"request": "^2.81.0",
"rimraf": "^2.5.2",
"should": "6.0.3",
"sinon": "1.15.3",
Expand Down
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 2ede231

Please sign in to comment.