-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (42 loc) · 1.15 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* gulp.js plugin for ngBoba
*/
var through2 = require('through2');
var path = require('path');
var addBoba = require('ng-boba');
module.exports = function (output, options) {
'use strict';
var firstFile, sourcePaths = [];
function collectFile(file, enc, cb) {
/*
* Process each file in the stream.
*/
if (file.isNull()) {
return cb();
}
if (!firstFile) {
firstFile = file;
}
sourcePaths.push(path.relative(process.cwd(), file.path));
return cb();
}
function pourBoba(cb) {
/*
* Run the files through ngBoba, throw the result into the stream
*/
var outputFile;
if (!firstFile) { // empty configuration would be better
return cb();
}
options.files = sourcePaths;
outputFile = firstFile.clone({contents: false});
outputFile.path = path.join(firstFile.base, output);
return addBoba(options).then((function (fileStream) {
return function (bobaData) {
outputFile.contents = new Buffer(JSON.stringify(bobaData, null, '\t'));
fileStream.push(outputFile);
};
}(this))).then(cb);
}
return through2.obj(collectFile, pourBoba);
};