1 | var winston = require("winston");
|
2 | var omit = require("lodash/omit");
|
3 | var assign = require("lodash/assign");
|
4 | var clone = require("lodash/cloneDeep");
|
5 | var stealTools = require("../../index");
|
6 | var isString = require("lodash/isString");
|
7 | var makeStealConfig = require("./make_steal_config");
|
8 | var makeBuildOptions = require("./make_build_options");
|
9 |
|
10 | var options = assign(
|
11 | clone(omit(require("./options"), ["bundle-steal", "watch"])),
|
12 | {
|
13 | minify: {
|
14 | type: "boolean",
|
15 | default: undefined,
|
16 | describe: "Minify the output. Defaults to true"
|
17 | },
|
18 | quiet: {
|
19 | type: "boolean",
|
20 | describe: "Quiet output"
|
21 | },
|
22 | "split-loader": {
|
23 | type: "boolean",
|
24 | default: false,
|
25 | describe: "Writes the optimized loader in its own bundle (loader.js)"
|
26 | },
|
27 | target: {
|
28 | type: "array",
|
29 | demandOption: false,
|
30 | describe: [
|
31 | "Specifies the platform where the application is going to be deployed",
|
32 | '[choices: "web", "node", "worker"]'
|
33 | ].join("\n")
|
34 | }
|
35 | }
|
36 | );
|
37 |
|
38 | module.exports = {
|
39 | command: ["optimize"],
|
40 |
|
41 | describe: "Creates an optimized build of a module and all of its dependencies",
|
42 |
|
43 | builder: options,
|
44 |
|
45 | handler: function(argv) {
|
46 | return stealTools.optimize(makeStealConfig(argv), makeBuildOptions(argv))
|
47 | .then(function() {
|
48 | winston.info("\nOptimized build completed successfully".green);
|
49 | })
|
50 | .catch(function(e) {
|
51 | var error = isString(e) ? new Error(e) : e;
|
52 |
|
53 | winston.error(error.message.red);
|
54 | winston.error("\nOptimized build failed".red);
|
55 |
|
56 | process.exit(1);
|
57 | });
|
58 | }
|
59 | };
|