1 | var _ = require("lodash");
|
2 | var winston = require("winston");
|
3 | var stealTools = require("../../index");
|
4 | var clone = require("lodash/cloneDeep");
|
5 | var options = clone(require("./options"));
|
6 | var makeStealConfig = require("./make_steal_config");
|
7 |
|
8 | var pathsToOmit = [
|
9 | "bundles-path",
|
10 | "bundle-steal",
|
11 | "watch",
|
12 | "tree-shaking",
|
13 | "no-tree-shaking"
|
14 | ];
|
15 |
|
16 | var bundleOptions = _.assign(
|
17 | {},
|
18 | _.omit(options, pathsToOmit),
|
19 | {
|
20 | dest: {
|
21 | alias: "d",
|
22 | type: "string",
|
23 | default: "",
|
24 | describe: "Defaults to root folder, a directory to save the bundles"
|
25 | },
|
26 | filter: {
|
27 | alias: "f",
|
28 | default: "**",
|
29 | type: "string",
|
30 | describe: "Glob pattern to match modules to be included in the bundle"
|
31 | },
|
32 | deps: {
|
33 | type: "boolean",
|
34 | default: false,
|
35 | describe: "Generates a development bundle of the dependencies in the node_modules folder"
|
36 | },
|
37 | dev: {
|
38 | type: "boolean",
|
39 | default: false,
|
40 | describe: "Generates a development bundle like --deps but includes StealJS @config modules"
|
41 | }
|
42 | }
|
43 | );
|
44 |
|
45 | module.exports = {
|
46 | command: "bundle",
|
47 |
|
48 | describe: "Creates a custom bundle",
|
49 |
|
50 | builder: bundleOptions,
|
51 |
|
52 | handler: function (argv) {
|
53 | var options = argv;
|
54 | var config = makeStealConfig(argv);
|
55 | var filter = getFilterPattern(options);
|
56 |
|
57 | options.filter = filter ? filter : options.filter;
|
58 |
|
59 | return stealTools.bundle(config, options)
|
60 | .then(function() {
|
61 | winston.info("\nBundle created successfully".green);
|
62 | })
|
63 | .catch(function(e) {
|
64 | e = typeof e === "string" ? new Error(e) : e;
|
65 |
|
66 | winston.error(e.message.red);
|
67 | winston.error("\nBuild failed".red);
|
68 |
|
69 | process.exit(1);
|
70 | });
|
71 | }
|
72 | };
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | function getFilterPattern(options) {
|
80 | var pattern;
|
81 |
|
82 |
|
83 |
|
84 | if (options.dev) {
|
85 | pattern = ["node_modules/**/*", "package.json"];
|
86 | }
|
87 |
|
88 |
|
89 | else if (options.deps) {
|
90 | pattern = "node_modules/**/*";
|
91 | }
|
92 |
|
93 | return pattern;
|
94 | }
|