UNPKG

1.1 kBJavaScriptView Raw
1var _ = require("lodash");
2var through = require("through2");
3var bundleFilename = require("./filename");
4var concatSource = require("../bundle/concat_source");
5var normalizeSource = require("./normalize_source");
6
7module.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
20function 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 // If the bundle is explicity marked as clean, just resolve.
35 if(bundle.isDirty === false) {
36 return;
37 }
38
39 // Adjusts URLs
40 normalizeSource(bundle, bundlePath);
41
42 // Combines the source
43 promises.push(concatSource(bundle, { format: "amd" }));
44 });
45
46 return Promise.all(promises).then(() => data);
47}