Skip to content

Commit b796164

Browse files
Wes24Wes24
authored andcommitted
Adding a callback function as a config option to the bundle complete event
1 parent 56f9bab commit b796164

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

lib/stream-bundles-watch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function _bundle(config, env) {
7373
.pipe(gif(resultOpts, results(resultOpts)))
7474
.pipe(gulp.dest(config.options.dest))
7575
.pipe(through.obj(function (file, enc, cb) {
76-
bundleDone(prettyScriptsBundleName, start);
76+
bundleDone(prettyScriptsBundleName, start, config.options.callback, file);
7777
}));
7878

7979
});
@@ -109,7 +109,7 @@ function _bundle(config, env) {
109109
.pipe(gif(resultOpts, results(resultOpts)))
110110
.pipe(gulp.dest(config.options.dest))
111111
.pipe(through.obj(function (file, enc, cb) {
112-
bundleDone(prettyStylesBundleName, start);
112+
bundleDone(prettyStylesBundleName, start, config.options.callback, file);
113113
}));
114114

115115
});

lib/watch/bundle-done.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ var gulp = require('gulp'),
44
prettyTime = require('pretty-hrtime'),
55
using = require('./../using');
66

7-
module.exports = function (name, start) {
7+
module.exports = function (name, start, callback, file) {
88
var hrDuration = process.hrtime(start); // [seconds,nanoseconds]
99
var time = prettyTime(hrDuration);
1010
logger.log('Finished bundling', '\'' + gutil.colors.green(name) + '\'',
1111
'after', gutil.colors.magenta(time)
1212
);
13-
};
13+
if (callback && typeof(callback) === 'function') {
14+
callback(file);
15+
}
16+
};

test/unit/watch/bundle-done-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ describe('bundle-done', function () {
99

1010
var prettyTimeStub = sinon.stub().returns('');
1111

12+
var callback = sinon.spy();
13+
var mockFile = {};
1214
var loggerStub = sinon.stub();
1315
loggerStub.log = sinon.spy();
1416

1517
var bundleDone = proxyquire(libPath + '/watch/bundle-done', { 'pretty-hrtime': prettyTimeStub, '../service/logger': loggerStub });
1618

17-
bundleDone('main.scripts', [ 1800216, 25 ]);
19+
bundleDone('main.scripts', [ 1800216, 25 ], callback, mockFile);
1820

1921
prettyTimeStub.calledOnce.should.be.ok;
2022
loggerStub.log.calledOnce.should.be.ok;
2123
loggerStub.log.calledWith('Finished bundling').should.be.ok;
22-
24+
25+
callback.calledOnce.should.be.ok;
26+
callback.calledWith(mockFile).should.be.ok;
2327
});
2428

2529
});

0 commit comments

Comments
 (0)