UNPKG

1.62 kBJavaScriptView Raw
1var clean = require("../graph/clean");
2var makeConfiguration = require("../configuration/make");
3var pluck = require("../graph/pluck");
4var through = require("through2");
5var transpile = require("../graph/transpile");
6var winston = require("winston");
7
8module.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
19function transpileGraph(data, transpileOptions) {
20 var dependencyGraph = data.graph,
21 options = data.options,
22 configuration = makeConfiguration(data.loader, data.buildLoader, options);
23
24 // Remove @config so it is not transpiled. It is a global,
25 // but we will want it to run ASAP.
26 var configGraph = pluck(
27 dependencyGraph,
28 data.loader.configMain || "@config",
29 transpileOptions.keepInGraph || []
30 );
31
32 // Remove steal dev from production builds.
33 pluck(dependencyGraph, "@dev", transpileOptions.keepInGraph || []);
34
35 // Clean development code if the option was passed
36 if(options.removeDevelopmentCode) {
37 clean(configGraph, options);
38 clean(dependencyGraph, options);
39 }
40
41 // Transpile each module to amd. Eventually, production builds
42 // should be able to work without steal.js.
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}