-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (27 loc) · 914 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var through = require('through');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var path = require('path');
var bempack = require('bem-pack');
module.exports = function (fileName, options) {
var firstFile = null;
var pack = bempack(options);
function apply(obj) {
if (!firstFile) { firstFile = obj; }
pack.add(obj.path);
}
function compile() {
pack.bundle(function (err, buf) {
if (err) { return this.emit('error', new PluginError('gulp-bem-pack', err)); }
if (firstFile) {
var joinedFile = firstFile.clone();
joinedFile.path = path.join(firstFile.base, fileName);
joinedFile.contents = buf;
this.emit('data', joinedFile);
}
this.emit('end');
}.bind(this));
}
var rs = through(apply, compile);
return rs;
};