UNPKG

1.53 kBJavaScriptView Raw
1var winston = require("winston");
2var assign = require("lodash/assign");
3var clone = require("lodash/cloneDeep");
4var stealTools = require("../../index");
5var makeStealConfig = require("./make_steal_config");
6var makeBuildOptions = require("./make_build_options");
7
8/**
9 * Disable default values for conditional properties:
10 * Default values make it impossible for the `handler` callback
11 * to tell whether the user explicitly set a value or not
12 */
13var options = assign(clone(require("./options")), {
14 minify: {
15 type: "boolean",
16 default: undefined,
17 describe: "Minify the output. Defaults to true except when used with --watch"
18 },
19 quiet: {
20 type: "boolean",
21 describe: "Quiet output",
22 default: undefined
23 }
24});
25
26module.exports = {
27 command: ["build", "*"], // `*` makes this the default command
28
29 describe: "Build a module and all of its dependencies",
30
31 builder: options,
32
33 handler: function(argv) {
34 var promise = stealTools.build(
35 makeStealConfig(argv),
36 makeBuildOptions(argv)
37 );
38
39 // If this is watch mode this is actually a stream.
40 if (promise.then) {
41 return promise.then(function() {
42 winston.info("\nBuild completed successfully".green);
43 }, function(e) {
44 // since this is a library we should throw an exception, and
45 // because it remains uncaught, will exit the node process with
46 // and exit code greater than 0
47 if (typeof e === "string") { e = new Error(e); }
48 winston.error(e.message.red);
49 winston.error("\nBuild failed".red);
50
51 process.exit(1);
52 });
53 }
54 }
55};