-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrecipe.js
56 lines (54 loc) · 2.17 KB
/
recipe.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
47
48
49
50
51
52
53
54
55
56
'use strict';
var path = require('path');
/**
* Recipe for distribution files reving
*
* @config rev.replaceInExtensions
*/
module.exports = function ($, config) {
/* Used hooks
*************/
var filesort = $.lazypipe()
.pipe(function () {
// Files may be presorted already. To keep null files in order of arrival, use promise and chain done events.
var orderPromise = Promise.resolve();
return $.if(config.angular.modulesFilter,
$.lazypipe()
// read null files
.pipe($.through2.obj, function (file, enc, done) {
// read null file
if(file.isNull()) {
// Require only when really needed.
// Require calls are memoized anyway.
var fs = require('graceful-fs');
var stripBom = require('strip-bom');
orderPromise.then(function () {
return new Promise(function(resolve, reject) {
fs.readFile(file.path, function (err, data) {
if(err) {
reject(err);
}
file.contents = stripBom(data);
done(null, file);
resolve();
});
});
})
}
else {
orderPromise.then(function () {
done(null, file);
});
}
})
.pipe($.angularFilesort)()
)
});
return {
pipes: {
processJsAngular: [config.order.angularAnnotate, $.ngAnnotate],
postDevAssetAngular: [config.order.angularSort, filesort],
postAssetAngular: [config.order.angularSort, filesort]
}
};
};