1 | var clean = require("../graph/clean");
|
2 | var makeConfiguration = require("../configuration/make");
|
3 | var pluck = require("../graph/pluck");
|
4 | var through = require("through2");
|
5 | var transpile = require("../graph/transpile");
|
6 | var winston = require("winston");
|
7 |
|
8 | module.exports = function(options) {
|
9 | return through.obj(function(data, enc, done){
|
10 | try {
|
11 | var buildResult = transpileGraph(data, options || {});
|
12 | done(null, buildResult);
|
13 | } catch(err){
|
14 | done(err);
|
15 | }
|
16 | });
|
17 | };
|
18 |
|
19 | function transpileGraph(data, transpileOptions) {
|
20 | var dependencyGraph = data.graph,
|
21 | options = data.options,
|
22 | configuration = makeConfiguration(data.loader, data.buildLoader, options);
|
23 |
|
24 |
|
25 |
|
26 | var configGraph = pluck(
|
27 | dependencyGraph,
|
28 | data.loader.configMain || "@config",
|
29 | transpileOptions.keepInGraph || []
|
30 | );
|
31 |
|
32 |
|
33 | pluck(dependencyGraph, "@dev", transpileOptions.keepInGraph || []);
|
34 |
|
35 |
|
36 | if(options.removeDevelopmentCode) {
|
37 | clean(configGraph, options);
|
38 | clean(dependencyGraph, options);
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 | options.sourceMapPath = configuration.bundlesPath;
|
44 |
|
45 | winston.info("Transpiling...");
|
46 | var outputFormat = transpileOptions.outputFormat || "amd";
|
47 | transpile(dependencyGraph, outputFormat, options, data);
|
48 | transpile(configGraph, outputFormat, options, data);
|
49 |
|
50 | data.configGraph = configGraph;
|
51 | data.configuration = configuration;
|
52 |
|
53 | return data;
|
54 | }
|