UNPKG

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