1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const schematic_command_1 = require("../models/schematic-command");
|
4 | const color_1 = require("../utilities/color");
|
5 | const json_schema_1 = require("../utilities/json-schema");
|
6 | class GenerateCommand extends schematic_command_1.SchematicCommand {
|
7 | async initialize(options) {
|
8 |
|
9 | const [collectionName, schematicName] = await this.parseSchematicInfo(options);
|
10 | this.collectionName = collectionName;
|
11 | this.schematicName = schematicName;
|
12 | await super.initialize(options);
|
13 | const collection = this.getCollection(collectionName);
|
14 | const subcommands = {};
|
15 | const schematicNames = schematicName ? [schematicName] : collection.listSchematicNames();
|
16 |
|
17 | schematicNames.sort();
|
18 | for (const name of schematicNames) {
|
19 | const schematic = this.getSchematic(collection, name, true);
|
20 | this.longSchematicName = schematic.description.name;
|
21 | let subcommand;
|
22 | if (schematic.description.schemaJson) {
|
23 | subcommand = await json_schema_1.parseJsonSchemaToSubCommandDescription(name, schematic.description.path, this._workflow.registry, schematic.description.schemaJson);
|
24 | }
|
25 | else {
|
26 | continue;
|
27 | }
|
28 | if ((await this.getDefaultSchematicCollection()) == collectionName) {
|
29 | subcommands[name] = subcommand;
|
30 | }
|
31 | else {
|
32 | subcommands[`${collectionName}:${name}`] = subcommand;
|
33 | }
|
34 | }
|
35 | this.description.options.forEach(option => {
|
36 | if (option.name == 'schematic') {
|
37 | option.subcommands = subcommands;
|
38 | }
|
39 | });
|
40 | }
|
41 | async run(options) {
|
42 | if (!this.schematicName || !this.collectionName) {
|
43 | return this.printHelp(options);
|
44 | }
|
45 | return this.runSchematic({
|
46 | collectionName: this.collectionName,
|
47 | schematicName: this.schematicName,
|
48 | schematicOptions: options['--'] || [],
|
49 | debug: !!options.debug || false,
|
50 | dryRun: !!options.dryRun || false,
|
51 | force: !!options.force || false,
|
52 | });
|
53 | }
|
54 | async reportAnalytics(paths, options) {
|
55 | const [collectionName, schematicName] = await this.parseSchematicInfo(options);
|
56 | if (!schematicName || !collectionName) {
|
57 | return;
|
58 | }
|
59 | const escapedSchematicName = (this.longSchematicName || schematicName).replace(/\//g, '_');
|
60 | return super.reportAnalytics(['generate', collectionName.replace(/\//g, '_'), escapedSchematicName], options);
|
61 | }
|
62 | async parseSchematicInfo(options) {
|
63 | let collectionName = await this.getDefaultSchematicCollection();
|
64 | let schematicName = options.schematic;
|
65 | if (schematicName && schematicName.includes(':')) {
|
66 | [collectionName, schematicName] = schematicName.split(':', 2);
|
67 | }
|
68 | return [collectionName, schematicName];
|
69 | }
|
70 | async printHelp(options) {
|
71 | await super.printHelp(options);
|
72 | this.logger.info('');
|
73 |
|
74 | const subcommand = this.description.options.filter(x => x.subcommands)[0];
|
75 | if (Object.keys((subcommand && subcommand.subcommands) || {}).length == 1) {
|
76 | this.logger.info(`\nTo see help for a schematic run:`);
|
77 | this.logger.info(color_1.colors.cyan(` ng generate <schematic> --help`));
|
78 | }
|
79 | return 0;
|
80 | }
|
81 | }
|
82 | exports.GenerateCommand = GenerateCommand;
|