1 | var _ = require("lodash");
|
2 | var through = require("through2");
|
3 | var bundleFilename = require("./filename");
|
4 | var concatSource = require("../bundle/concat_source");
|
5 | var normalizeSource = require("./normalize_source");
|
6 |
|
7 | module.exports = function(){
|
8 | return through.obj(function(data, enc, next) {
|
9 | try {
|
10 | var p = concat(data);
|
11 | p.then(function(result){
|
12 | next(null, result);
|
13 | });
|
14 | } catch(err) {
|
15 | next(err);
|
16 | }
|
17 | });
|
18 | };
|
19 |
|
20 | function concat(data) {
|
21 | var bundles = data.bundles;
|
22 | var configuration = data.configuration;
|
23 | var bundlesPath = configuration.bundlesPath;
|
24 |
|
25 | var bundlesDir = _.endsWith(bundlesPath, "/") ?
|
26 | bundlesPath : bundlesPath + "/";
|
27 |
|
28 | var promises = [];
|
29 |
|
30 | bundles.forEach(function(bundle){
|
31 | var bundlePath = bundle.bundlePath =
|
32 | bundlesDir + "" + bundleFilename(bundle);
|
33 |
|
34 |
|
35 | if(bundle.isDirty === false) {
|
36 | return;
|
37 | }
|
38 |
|
39 |
|
40 | normalizeSource(bundle, bundlePath);
|
41 |
|
42 |
|
43 | promises.push(concatSource(bundle, { format: "amd" }));
|
44 | });
|
45 |
|
46 | return Promise.all(promises).then(() => data);
|
47 | }
|