1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | const command_1 = require("../models/command");
|
12 | const config_1 = require("../utilities/config");
|
13 | const schematics_1 = require("../utilities/schematics");
|
14 | const core_1 = require("@angular-devkit/core");
|
15 | const schematic_command_1 = require("../models/schematic-command");
|
16 | class GenerateCommand extends schematic_command_1.SchematicCommand {
|
17 | constructor() {
|
18 | super(...arguments);
|
19 | this.name = 'generate';
|
20 | this.description = 'Generates and/or modifies files based on a schematic.';
|
21 | this.scope = command_1.CommandScope.inProject;
|
22 | this.arguments = ['schematic'];
|
23 | this.options = [
|
24 | ...this.coreOptions
|
25 | ];
|
26 | this.initialized = false;
|
27 | }
|
28 | initialize(options) {
|
29 | const _super = name => super[name];
|
30 | return __awaiter(this, void 0, void 0, function* () {
|
31 | if (this.initialized) {
|
32 | return;
|
33 | }
|
34 | _super("initialize").call(this, options);
|
35 | this.initialized = true;
|
36 | const [collectionName, schematicName] = this.parseSchematicInfo(options);
|
37 | if (!!schematicName) {
|
38 | const schematicOptions = yield this.getOptions({
|
39 | schematicName,
|
40 | collectionName,
|
41 | });
|
42 | this.options = this.options.concat(schematicOptions.options);
|
43 | this.arguments = this.arguments.concat(schematicOptions.arguments.map(a => a.name));
|
44 | }
|
45 | });
|
46 | }
|
47 | validate(options) {
|
48 | if (!options._[0]) {
|
49 | this.logger.error(core_1.tags.oneLine `
|
50 | The "ng generate" command requires a
|
51 | schematic name to be specified.
|
52 | For more details, use "ng help".`);
|
53 | return false;
|
54 | }
|
55 | return true;
|
56 | }
|
57 | run(options) {
|
58 | const [collectionName, schematicName] = this.parseSchematicInfo(options);
|
59 |
|
60 | options._ = options._.slice(1);
|
61 | return this.runSchematic({
|
62 | collectionName,
|
63 | schematicName,
|
64 | schematicOptions: options,
|
65 | debug: options.debug,
|
66 | dryRun: options.dryRun,
|
67 | force: options.force,
|
68 | });
|
69 | }
|
70 | parseSchematicInfo(options) {
|
71 | let collectionName = config_1.getDefaultSchematicCollection();
|
72 | let schematicName = options._[0];
|
73 | if (schematicName) {
|
74 | if (schematicName.includes(':')) {
|
75 | [collectionName, schematicName] = schematicName.split(':', 2);
|
76 | }
|
77 | }
|
78 | return [collectionName, schematicName];
|
79 | }
|
80 | printHelp(options) {
|
81 | const schematicName = options._[0];
|
82 | if (schematicName) {
|
83 | const argDisplay = this.arguments && this.arguments.length > 0
|
84 | ? ' ' + this.arguments.filter(a => a !== 'schematic').map(a => `<${a}>`).join(' ')
|
85 | : '';
|
86 | const optionsDisplay = this.options && this.options.length > 0
|
87 | ? ' [options]'
|
88 | : '';
|
89 | this.logger.info(`usage: ng generate ${schematicName}${argDisplay}${optionsDisplay}`);
|
90 | this.printHelpOptions(options);
|
91 | }
|
92 | else {
|
93 | this.printHelpUsage(this.name, this.arguments, this.options);
|
94 | const engineHost = schematics_1.getEngineHost();
|
95 | const [collectionName] = this.parseSchematicInfo(options);
|
96 | const collection = schematics_1.getCollection(collectionName);
|
97 | const schematicNames = engineHost.listSchematics(collection);
|
98 | this.logger.info('Available schematics:');
|
99 | schematicNames.forEach(schematicName => {
|
100 | this.logger.info(` ${schematicName}`);
|
101 | });
|
102 | this.logger.warn(`\nTo see help for a schematic run:`);
|
103 | this.logger.info(core_1.terminal.cyan(` ng generate <schematic> --help`));
|
104 | }
|
105 | }
|
106 | }
|
107 | GenerateCommand.aliases = ['g'];
|
108 | exports.default = GenerateCommand;
|
109 |
|
\ | No newline at end of file |