1 | var util = require("util");
|
2 | var defaults = require("lodash/defaults");
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | module.exports = function(bundles, configuration, targetBundle, options) {
|
11 | var paths = getBundlesPaths(configuration);
|
12 |
|
13 | if (!options) options = {};
|
14 | defaults(options, {
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | getBundleName(bundle) {
|
21 | return bundle.name;
|
22 | }
|
23 | });
|
24 |
|
25 | var excludedBundles = options.excludedBundles || {};
|
26 | var bundledBundles = bundles.slice(0);
|
27 |
|
28 |
|
29 | function isTargetBundle(bundle) {
|
30 | return bundle.name === targetBundle.name;
|
31 | }
|
32 |
|
33 | var bundlesConfig = {};
|
34 | bundledBundles.forEach(function(bundle) {
|
35 |
|
36 |
|
37 | if(!isTargetBundle(bundle) && !excludedBundles[bundle.name]) {
|
38 | var name = options.getBundleName(bundle);
|
39 | bundlesConfig[name] = bundle.nodes.map(function(node){
|
40 | return node.load.name;
|
41 | });
|
42 | }
|
43 | });
|
44 |
|
45 | return {
|
46 | load: {
|
47 | name: "[system-bundles-config]",
|
48 | metadata: {
|
49 | bundlesConfig: bundlesConfig
|
50 | }
|
51 | },
|
52 | minifiedSource: paths + "System.bundles = "+JSON.stringify(bundlesConfig)+";"
|
53 | };
|
54 | };
|
55 |
|
56 |
|
57 | function getBundlesPaths(configuration){
|
58 |
|
59 |
|
60 | if(!configuration.loader.bundlesPath) {
|
61 | return "";
|
62 | }
|
63 | var bundlesPath = configuration.bundlesPathURL;
|
64 |
|
65 |
|
66 | var paths = util.format('\tSystem.paths["bundles/*.css"] ="%s/*css";\n' +
|
67 | '\tSystem.paths["bundles/*"] = "%s/*.js";\n',
|
68 | bundlesPath, bundlesPath);
|
69 | return "if(!System.bundlesPath) {\n" + paths + "}\n";
|
70 | }
|