source: trip-planner-front/node_modules/@angular/cli/commands/generate-impl.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[6a3a178]1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.GenerateCommand = void 0;
11const schematic_command_1 = require("../models/schematic-command");
12const color_1 = require("../utilities/color");
13const json_schema_1 = require("../utilities/json-schema");
14class GenerateCommand extends schematic_command_1.SchematicCommand {
15 async initialize(options) {
16 // Fill up the schematics property of the command description.
17 const [collectionName, schematicName] = await this.parseSchematicInfo(options);
18 this.collectionName = collectionName;
19 this.schematicName = schematicName;
20 await super.initialize(options);
21 const collection = this.getCollection(collectionName);
22 const subcommands = {};
23 const schematicNames = schematicName ? [schematicName] : collection.listSchematicNames();
24 // Sort as a courtesy for the user.
25 schematicNames.sort();
26 for (const name of schematicNames) {
27 const schematic = this.getSchematic(collection, name, true);
28 this.longSchematicName = schematic.description.name;
29 let subcommand;
30 if (schematic.description.schemaJson) {
31 subcommand = await json_schema_1.parseJsonSchemaToSubCommandDescription(name, schematic.description.path, this._workflow.registry, schematic.description.schemaJson);
32 }
33 else {
34 continue;
35 }
36 if ((await this.getDefaultSchematicCollection()) == collectionName) {
37 subcommands[name] = subcommand;
38 }
39 else {
40 subcommands[`${collectionName}:${name}`] = subcommand;
41 }
42 }
43 this.description.options.forEach((option) => {
44 if (option.name == 'schematic') {
45 option.subcommands = subcommands;
46 }
47 });
48 }
49 async run(options) {
50 if (!this.schematicName || !this.collectionName) {
51 return this.printHelp();
52 }
53 return this.runSchematic({
54 collectionName: this.collectionName,
55 schematicName: this.schematicName,
56 schematicOptions: options['--'] || [],
57 debug: !!options.debug || false,
58 dryRun: !!options.dryRun || false,
59 force: !!options.force || false,
60 });
61 }
62 async reportAnalytics(paths, options) {
63 if (!this.collectionName || !this.schematicName) {
64 return;
65 }
66 const escapedSchematicName = (this.longSchematicName || this.schematicName).replace(/\//g, '_');
67 return super.reportAnalytics(['generate', this.collectionName.replace(/\//g, '_'), escapedSchematicName], options);
68 }
69 async parseSchematicInfo(options) {
70 let collectionName = await this.getDefaultSchematicCollection();
71 let schematicName = options.schematic;
72 if (schematicName && schematicName.includes(':')) {
73 [collectionName, schematicName] = schematicName.split(':', 2);
74 }
75 return [collectionName, schematicName];
76 }
77 async printHelp() {
78 await super.printHelp();
79 this.logger.info('');
80 // Find the generate subcommand.
81 const subcommand = this.description.options.filter((x) => x.subcommands)[0];
82 if (Object.keys((subcommand && subcommand.subcommands) || {}).length == 1) {
83 this.logger.info(`\nTo see help for a schematic run:`);
84 this.logger.info(color_1.colors.cyan(` ng generate <schematic> --help`));
85 }
86 return 0;
87 }
88}
89exports.GenerateCommand = GenerateCommand;
Note: See TracBrowser for help on using the repository browser.