UNPKG

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