UNPKG

2.61 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const build_1 = require("../lib/build");
4const color_1 = require("../lib/color");
5const command_1 = require("../lib/command");
6const errors_1 = require("../lib/errors");
7class BuildCommand extends command_1.Command {
8 async getMetadata() {
9 const groups = [];
10 const options = [];
11 const footnotes = [];
12 const exampleCommands = [''];
13 let description = `${color_1.input('ionic build')} will perform an Ionic build, which compiles web assets and prepares them for deployment.`;
14 const runner = this.project && await this.project.getBuildRunner();
15 if (runner) {
16 const libmetadata = await runner.getCommandMetadata();
17 groups.push(...libmetadata.groups || []);
18 options.push(...libmetadata.options || []);
19 description += libmetadata.description ? `\n\n${libmetadata.description.trim()}` : '';
20 footnotes.push(...libmetadata.footnotes || []);
21 exampleCommands.push(...libmetadata.exampleCommands || []);
22 }
23 options.push(...build_1.COMMON_BUILD_COMMAND_OPTIONS);
24 return {
25 name: 'build',
26 type: 'project',
27 summary: 'Build web assets and prepare your app for any platform targets',
28 description,
29 footnotes,
30 groups,
31 exampleCommands,
32 options,
33 };
34 }
35 async preRun(inputs, options) {
36 if (inputs.length > 0 && ['android', 'ios', 'wp8', 'windows', 'browser'].includes(inputs[0])) {
37 this.env.log.warn(`${color_1.input('ionic build')} is for building web assets and takes no arguments. See ${color_1.input('ionic build --help')}.\n` +
38 `Ignoring argument ${color_1.input(inputs[0])}. Perhaps you meant ${color_1.input('ionic cordova build ' + inputs[0])}?\n`);
39 inputs.splice(0);
40 }
41 }
42 async run(inputs, options, runinfo) {
43 if (!this.project) {
44 throw new errors_1.FatalException(`Cannot run ${color_1.input('ionic build')} outside a project directory.`);
45 }
46 try {
47 const runner = await this.project.requireBuildRunner();
48 const runnerOpts = runner.createOptionsFromCommandLine(inputs, options);
49 await runner.run(runnerOpts);
50 }
51 catch (e) {
52 if (e instanceof errors_1.RunnerException) {
53 throw new errors_1.FatalException(e.message);
54 }
55 throw e;
56 }
57 }
58}
59exports.BuildCommand = BuildCommand;