UNPKG

2.31 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const color_1 = require("../lib/color");
4const command_1 = require("../lib/command");
5const errors_1 = require("../lib/errors");
6const project_1 = require("../lib/project");
7class GenerateCommand extends command_1.Command {
8 async getMetadata() {
9 const inputs = [];
10 const options = [];
11 const exampleCommands = [''];
12 const footnotes = [];
13 const groups = [];
14 let description = this.project
15 ? color_1.failure(`Generators are not supported in this project type (${color_1.strong(project_1.prettyProjectName(this.project.type))}).`)
16 : color_1.failure('Generators help is available within an Ionic project directory.');
17 const runner = this.project && await this.project.getGenerateRunner();
18 if (runner) {
19 const libmetadata = await runner.getCommandMetadata();
20 groups.push(...libmetadata.groups || []);
21 inputs.push(...libmetadata.inputs || []);
22 options.push(...libmetadata.options || []);
23 description = (libmetadata.description || '').trim();
24 footnotes.push(...libmetadata.footnotes || []);
25 exampleCommands.push(...libmetadata.exampleCommands || []);
26 }
27 else {
28 groups.push("hidden" /* HIDDEN */);
29 }
30 return {
31 name: 'generate',
32 type: 'project',
33 summary: 'Automatically create framework features',
34 description,
35 footnotes,
36 inputs,
37 options,
38 groups,
39 exampleCommands,
40 };
41 }
42 async preRun(inputs, options) {
43 const runner = this.project && await this.project.getGenerateRunner();
44 if (runner) {
45 await runner.ensureCommandLine(inputs, options);
46 }
47 }
48 async run(inputs, options) {
49 if (!this.project) {
50 throw new errors_1.FatalException(`Cannot run ${color_1.input('ionic generate')} outside a project directory.`);
51 }
52 const runner = await this.project.requireGenerateRunner();
53 const opts = runner.createOptionsFromCommandLine(inputs, options);
54 await runner.run(opts);
55 }
56}
57exports.GenerateCommand = GenerateCommand;