@angular/cli 14.0.0-next.4 → 14.0.0-next.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/bin/ng.js +3 -5
  2. package/lib/cli/index.d.ts +1 -2
  3. package/lib/cli/index.js +16 -45
  4. package/lib/config/schema.json +30 -15
  5. package/lib/config/workspace-schema.d.ts +6 -1
  6. package/lib/init.js +10 -9
  7. package/package.json +18 -20
  8. package/{models → src/analytics}/analytics-collector.d.ts +0 -0
  9. package/{models → src/analytics}/analytics-collector.js +8 -2
  10. package/src/analytics/analytics.d.ts +47 -0
  11. package/src/analytics/analytics.js +304 -0
  12. package/src/command-builder/architect-base-command-module.d.ts +23 -0
  13. package/src/command-builder/architect-base-command-module.js +103 -0
  14. package/src/command-builder/architect-command-module.d.ts +22 -0
  15. package/src/command-builder/architect-command-module.js +108 -0
  16. package/src/command-builder/command-module.d.ts +89 -0
  17. package/src/command-builder/command-module.js +191 -0
  18. package/{utilities/package-json.js → src/command-builder/command-runner.d.ts} +2 -2
  19. package/src/command-builder/command-runner.js +152 -0
  20. package/src/command-builder/schematics-command-module.d.ts +46 -0
  21. package/src/command-builder/schematics-command-module.js +335 -0
  22. package/src/command-builder/utilities/command.d.ts +13 -0
  23. package/src/command-builder/utilities/command.js +27 -0
  24. package/src/command-builder/utilities/json-help.d.ts +36 -0
  25. package/src/command-builder/utilities/json-help.js +94 -0
  26. package/src/command-builder/utilities/json-schema.d.ts +40 -0
  27. package/{utilities → src/command-builder/utilities}/json-schema.js +20 -121
  28. package/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +0 -0
  29. package/{models → src/command-builder/utilities}/schematic-engine-host.js +0 -0
  30. package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
  31. package/src/command-builder/utilities/schematic-workflow.js +68 -0
  32. package/src/commands/add/cli.d.ts +33 -0
  33. package/{commands/add-impl.js → src/commands/add/cli.js} +108 -80
  34. package/src/commands/add/long-description.md +7 -0
  35. package/src/commands/analytics/cli.d.ts +16 -0
  36. package/src/commands/analytics/cli.js +35 -0
  37. package/src/commands/analytics/info/cli.d.ts +16 -0
  38. package/src/commands/analytics/info/cli.js +26 -0
  39. package/src/commands/analytics/settings/cli.d.ts +35 -0
  40. package/src/commands/analytics/settings/cli.js +61 -0
  41. package/src/commands/build/cli.d.ts +16 -0
  42. package/src/commands/build/cli.js +23 -0
  43. package/{commands/build-long.md → src/commands/build/long-description.md} +0 -0
  44. package/src/commands/cache/clean/cli.d.ts +17 -0
  45. package/src/commands/cache/clean/cli.js +32 -0
  46. package/src/commands/cache/cli.d.ts +17 -0
  47. package/src/commands/cache/cli.js +38 -0
  48. package/src/commands/cache/info/cli.d.ts +20 -0
  49. package/src/commands/cache/info/cli.js +82 -0
  50. package/src/commands/cache/long-description.md +53 -0
  51. package/src/commands/cache/settings/cli.d.ts +27 -0
  52. package/src/commands/cache/settings/cli.js +42 -0
  53. package/src/commands/cache/utilities.d.ts +11 -0
  54. package/src/commands/cache/utilities.js +50 -0
  55. package/src/commands/config/cli.d.ts +24 -0
  56. package/{commands/config-impl.js → src/commands/config/cli.js} +102 -89
  57. package/{commands/config-long.md → src/commands/config/long-description.md} +2 -2
  58. package/src/commands/deploy/cli.d.ts +16 -0
  59. package/src/commands/deploy/cli.js +35 -0
  60. package/{commands/deploy-long.md → src/commands/deploy/long-description.md} +0 -0
  61. package/src/commands/doc/cli.d.ts +23 -0
  62. package/{commands/doc-impl.js → src/commands/doc/cli.js} +41 -12
  63. package/src/commands/e2e/cli.d.ts +17 -0
  64. package/src/commands/e2e/cli.js +34 -0
  65. package/src/commands/extract-i18n/cli.d.ts +15 -0
  66. package/src/commands/extract-i18n/cli.js +20 -0
  67. package/src/commands/generate/cli.d.ts +39 -0
  68. package/src/commands/generate/cli.js +145 -0
  69. package/src/commands/lint/cli.d.ts +16 -0
  70. package/src/commands/lint/cli.js +31 -0
  71. package/{commands/lint-long.md → src/commands/lint/long-description.md} +0 -0
  72. package/src/commands/make-this-awesome/cli.d.ts +17 -0
  73. package/{commands/easter-egg-impl.js → src/commands/make-this-awesome/cli.js} +17 -10
  74. package/src/commands/new/cli.d.ts +27 -0
  75. package/src/commands/new/cli.js +77 -0
  76. package/src/commands/run/cli.d.ts +23 -0
  77. package/src/commands/run/cli.js +59 -0
  78. package/{commands/run-long.md → src/commands/run/long-description.md} +0 -0
  79. package/src/commands/serve/cli.d.ts +16 -0
  80. package/src/commands/serve/cli.js +21 -0
  81. package/src/commands/test/cli.d.ts +16 -0
  82. package/src/commands/test/cli.js +23 -0
  83. package/{commands/test-long.md → src/commands/test/long-description.md} +0 -0
  84. package/{commands/update-impl.d.ts → src/commands/update/cli.d.ts} +26 -9
  85. package/{commands/update-impl.js → src/commands/update/cli.js} +362 -316
  86. package/{commands/update-long.md → src/commands/update/long-description.md} +0 -0
  87. package/src/commands/update/schematic/index.js +33 -20
  88. package/src/commands/version/cli.d.ts +18 -0
  89. package/{commands/version-impl.js → src/commands/version/cli.js} +56 -74
  90. package/src/typings-bazel.d.ts +14 -0
  91. package/src/typings.d.ts +1 -14
  92. package/{utilities → src/utilities}/color.d.ts +0 -0
  93. package/{utilities → src/utilities}/color.js +5 -1
  94. package/{utilities → src/utilities}/config.d.ts +2 -2
  95. package/{utilities → src/utilities}/config.js +24 -16
  96. package/src/utilities/environment-options.d.ts +12 -0
  97. package/src/utilities/environment-options.js +24 -0
  98. package/{utilities → src/utilities}/find-up.d.ts +0 -0
  99. package/{utilities → src/utilities}/find-up.js +5 -1
  100. package/{utilities → src/utilities}/json-file.d.ts +0 -0
  101. package/{utilities → src/utilities}/json-file.js +0 -0
  102. package/{utilities → src/utilities}/log-file.d.ts +0 -0
  103. package/{utilities → src/utilities}/log-file.js +0 -0
  104. package/src/utilities/package-manager.d.ts +41 -0
  105. package/src/utilities/package-manager.js +276 -0
  106. package/{utilities → src/utilities}/package-metadata.d.ts +15 -37
  107. package/{utilities → src/utilities}/package-metadata.js +15 -27
  108. package/{utilities → src/utilities}/package-tree.d.ts +2 -2
  109. package/{utilities → src/utilities}/package-tree.js +5 -1
  110. package/{utilities → src/utilities}/project.d.ts +0 -0
  111. package/{utilities → src/utilities}/project.js +5 -1
  112. package/{utilities → src/utilities}/prompt.d.ts +0 -0
  113. package/{utilities → src/utilities}/prompt.js +7 -3
  114. package/{utilities → src/utilities}/spinner.d.ts +0 -0
  115. package/{utilities → src/utilities}/spinner.js +0 -0
  116. package/{utilities → src/utilities}/tty.d.ts +0 -0
  117. package/{utilities → src/utilities}/tty.js +0 -0
  118. package/{models → src/utilities}/version.d.ts +2 -1
  119. package/{models → src/utilities}/version.js +6 -6
  120. package/bin/postinstall/analytics-prompt.js +0 -27
  121. package/bin/postinstall/script.js +0 -16
  122. package/commands/add-impl.d.ts +0 -21
  123. package/commands/add.d.ts +0 -42
  124. package/commands/add.js +0 -10
  125. package/commands/add.json +0 -54
  126. package/commands/add.md +0 -10
  127. package/commands/analytics-impl.d.ts +0 -13
  128. package/commands/analytics-impl.js +0 -80
  129. package/commands/analytics-long.md +0 -8
  130. package/commands/analytics.d.ts +0 -46
  131. package/commands/analytics.js +0 -31
  132. package/commands/analytics.json +0 -37
  133. package/commands/build-impl.d.ts +0 -14
  134. package/commands/build-impl.js +0 -21
  135. package/commands/build.d.ts +0 -30
  136. package/commands/build.js +0 -10
  137. package/commands/build.json +0 -16
  138. package/commands/config-impl.d.ts +0 -15
  139. package/commands/config.d.ts +0 -34
  140. package/commands/config.js +0 -10
  141. package/commands/config.json +0 -43
  142. package/commands/definitions.json +0 -66
  143. package/commands/deploy-impl.d.ts +0 -15
  144. package/commands/deploy-impl.js +0 -36
  145. package/commands/deploy.d.ts +0 -30
  146. package/commands/deploy.js +0 -10
  147. package/commands/deploy.json +0 -34
  148. package/commands/doc-impl.d.ts +0 -13
  149. package/commands/doc.d.ts +0 -39
  150. package/commands/doc.js +0 -14
  151. package/commands/doc.json +0 -46
  152. package/commands/e2e-impl.d.ts +0 -16
  153. package/commands/e2e-impl.js +0 -36
  154. package/commands/e2e-long.md +0 -4
  155. package/commands/e2e.d.ts +0 -29
  156. package/commands/e2e.js +0 -10
  157. package/commands/e2e.json +0 -17
  158. package/commands/easter-egg-impl.d.ts +0 -12
  159. package/commands/easter-egg.d.ts +0 -14
  160. package/commands/easter-egg.js +0 -10
  161. package/commands/easter-egg.json +0 -12
  162. package/commands/extract-i18n-impl.d.ts +0 -14
  163. package/commands/extract-i18n-impl.js +0 -21
  164. package/commands/extract-i18n.d.ts +0 -29
  165. package/commands/extract-i18n.js +0 -10
  166. package/commands/extract-i18n.json +0 -15
  167. package/commands/generate-impl.d.ts +0 -18
  168. package/commands/generate-impl.js +0 -89
  169. package/commands/generate.d.ts +0 -37
  170. package/commands/generate.js +0 -10
  171. package/commands/generate.json +0 -31
  172. package/commands/help-impl.d.ts +0 -12
  173. package/commands/help-impl.js +0 -26
  174. package/commands/help-long.md +0 -7
  175. package/commands/help.d.ts +0 -17
  176. package/commands/help.js +0 -10
  177. package/commands/help.json +0 -13
  178. package/commands/lint-impl.d.ts +0 -16
  179. package/commands/lint-impl.js +0 -69
  180. package/commands/lint.d.ts +0 -29
  181. package/commands/lint.js +0 -10
  182. package/commands/lint.json +0 -36
  183. package/commands/new-impl.d.ts +0 -16
  184. package/commands/new-impl.js +0 -37
  185. package/commands/new.d.ts +0 -41
  186. package/commands/new.js +0 -10
  187. package/commands/new.json +0 -34
  188. package/commands/new.md +0 -16
  189. package/commands/run-impl.d.ts +0 -13
  190. package/commands/run-impl.js +0 -22
  191. package/commands/run.d.ts +0 -30
  192. package/commands/run.js +0 -10
  193. package/commands/run.json +0 -36
  194. package/commands/serve-impl.d.ts +0 -15
  195. package/commands/serve-impl.js +0 -24
  196. package/commands/serve.d.ts +0 -29
  197. package/commands/serve.js +0 -10
  198. package/commands/serve.json +0 -17
  199. package/commands/test-impl.d.ts +0 -15
  200. package/commands/test-impl.js +0 -22
  201. package/commands/test.d.ts +0 -29
  202. package/commands/test.js +0 -10
  203. package/commands/test.json +0 -17
  204. package/commands/update.d.ts +0 -61
  205. package/commands/update.js +0 -10
  206. package/commands/update.json +0 -78
  207. package/commands/version-impl.d.ts +0 -17
  208. package/commands/version.d.ts +0 -17
  209. package/commands/version.js +0 -10
  210. package/commands/version.json +0 -13
  211. package/commands.json +0 -20
  212. package/models/analytics.d.ts +0 -58
  213. package/models/analytics.js +0 -358
  214. package/models/architect-command.d.ts +0 -35
  215. package/models/architect-command.js +0 -364
  216. package/models/command-runner.d.ts +0 -24
  217. package/models/command-runner.js +0 -241
  218. package/models/command.d.ts +0 -34
  219. package/models/command.js +0 -143
  220. package/models/interface.d.ts +0 -196
  221. package/models/interface.js +0 -31
  222. package/models/parser.d.ts +0 -39
  223. package/models/parser.js +0 -349
  224. package/models/schematic-command.d.ts +0 -55
  225. package/models/schematic-command.js +0 -485
  226. package/utilities/install-package.d.ts +0 -16
  227. package/utilities/install-package.js +0 -193
  228. package/utilities/json-schema.d.ts +0 -17
  229. package/utilities/package-json.d.ts +0 -249
  230. package/utilities/package-manager.d.ts +0 -13
  231. package/utilities/package-manager.js +0 -106
@@ -0,0 +1,335 @@
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
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.SchematicsCommandModule = exports.DEFAULT_SCHEMATICS_COLLECTION = void 0;
34
+ const core_1 = require("@angular-devkit/core");
35
+ const schematics_1 = require("@angular-devkit/schematics");
36
+ const tools_1 = require("@angular-devkit/schematics/tools");
37
+ const config_1 = require("../utilities/config");
38
+ const tty_1 = require("../utilities/tty");
39
+ const command_module_1 = require("./command-module");
40
+ const json_schema_1 = require("./utilities/json-schema");
41
+ const schematic_engine_host_1 = require("./utilities/schematic-engine-host");
42
+ const schematic_workflow_1 = require("./utilities/schematic-workflow");
43
+ exports.DEFAULT_SCHEMATICS_COLLECTION = '@schematics/angular';
44
+ class SchematicsCommandModule extends command_module_1.CommandModule {
45
+ constructor() {
46
+ super(...arguments);
47
+ this.allowPrivateSchematics = false;
48
+ this.shouldReportAnalytics = false;
49
+ this._workflowForBuilder = new Map();
50
+ this.defaultProjectDeprecationWarningShown = false;
51
+ }
52
+ async builder(argv) {
53
+ return argv
54
+ .option('interactive', {
55
+ describe: 'Enable interactive input prompts.',
56
+ type: 'boolean',
57
+ default: true,
58
+ })
59
+ .option('dry-run', {
60
+ describe: 'Run through and reports activity without writing out results.',
61
+ type: 'boolean',
62
+ default: false,
63
+ })
64
+ .option('defaults', {
65
+ describe: 'Disable interactive input prompts for options with a default.',
66
+ type: 'boolean',
67
+ default: false,
68
+ })
69
+ .option('force', {
70
+ describe: 'Force overwriting of existing files.',
71
+ type: 'boolean',
72
+ default: false,
73
+ })
74
+ .strict();
75
+ }
76
+ /** Get schematic schema options.*/
77
+ async getSchematicOptions(collection, schematicName, workflow) {
78
+ const schematic = collection.createSchematic(schematicName, true);
79
+ const { schemaJson } = schematic.description;
80
+ if (!schemaJson) {
81
+ return [];
82
+ }
83
+ return (0, json_schema_1.parseJsonSchemaToOptions)(workflow.registry, schemaJson);
84
+ }
85
+ getOrCreateWorkflowForBuilder(collectionName) {
86
+ const cached = this._workflowForBuilder.get(collectionName);
87
+ if (cached) {
88
+ return cached;
89
+ }
90
+ const workflow = new tools_1.NodeWorkflow(this.context.root, {
91
+ resolvePaths: this.getResolvePaths(collectionName),
92
+ engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
93
+ });
94
+ this._workflowForBuilder.set(collectionName, workflow);
95
+ return workflow;
96
+ }
97
+ async getOrCreateWorkflowForExecution(collectionName, options) {
98
+ if (this._workflowForExecution) {
99
+ return this._workflowForExecution;
100
+ }
101
+ const { logger, root, packageManager } = this.context;
102
+ const { force, dryRun, packageRegistry } = options;
103
+ const workflow = new tools_1.NodeWorkflow(root, {
104
+ force,
105
+ dryRun,
106
+ packageManager: packageManager.name,
107
+ // A schema registry is required to allow customizing addUndefinedDefaults
108
+ registry: new core_1.schema.CoreSchemaRegistry(schematics_1.formats.standardFormats),
109
+ packageRegistry,
110
+ resolvePaths: this.getResolvePaths(collectionName),
111
+ schemaValidation: true,
112
+ optionTransforms: [
113
+ // Add configuration file defaults
114
+ async (schematic, current) => {
115
+ const projectName = typeof current.project === 'string'
116
+ ? current.project
117
+ : this.getProjectName();
118
+ return {
119
+ ...(await (0, config_1.getSchematicDefaults)(schematic.collection.name, schematic.name, projectName)),
120
+ ...current,
121
+ };
122
+ },
123
+ ],
124
+ engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
125
+ });
126
+ workflow.registry.addPostTransform(core_1.schema.transforms.addUndefinedDefaults);
127
+ workflow.registry.addSmartDefaultProvider('projectName', () => this.getProjectName());
128
+ workflow.registry.useXDeprecatedProvider((msg) => logger.warn(msg));
129
+ let shouldReportAnalytics = true;
130
+ workflow.engineHost.registerOptionsTransform(async (schematic, options) => {
131
+ var _a;
132
+ if (shouldReportAnalytics) {
133
+ shouldReportAnalytics = false;
134
+ // ng generate lib -> ng generate
135
+ const commandName = (_a = this.command) === null || _a === void 0 ? void 0 : _a.split(' ', 1)[0];
136
+ await this.reportAnalytics(options, [
137
+ commandName,
138
+ schematic.collection.name.replace(/\//g, '_'),
139
+ schematic.name.replace(/\//g, '_'),
140
+ ]);
141
+ }
142
+ return options;
143
+ });
144
+ if (options.interactive !== false && (0, tty_1.isTTY)()) {
145
+ workflow.registry.usePromptProvider(async (definitions) => {
146
+ const questions = definitions
147
+ .filter((definition) => !options.defaults || definition.default === undefined)
148
+ .map((definition) => {
149
+ var _a;
150
+ const question = {
151
+ name: definition.id,
152
+ message: definition.message,
153
+ default: definition.default,
154
+ };
155
+ const validator = definition.validator;
156
+ if (validator) {
157
+ question.validate = (input) => validator(input);
158
+ // Filter allows transformation of the value prior to validation
159
+ question.filter = async (input) => {
160
+ for (const type of definition.propertyTypes) {
161
+ let value;
162
+ switch (type) {
163
+ case 'string':
164
+ value = String(input);
165
+ break;
166
+ case 'integer':
167
+ case 'number':
168
+ value = Number(input);
169
+ break;
170
+ default:
171
+ value = input;
172
+ break;
173
+ }
174
+ // Can be a string if validation fails
175
+ const isValid = (await validator(value)) === true;
176
+ if (isValid) {
177
+ return value;
178
+ }
179
+ }
180
+ return input;
181
+ };
182
+ }
183
+ switch (definition.type) {
184
+ case 'confirmation':
185
+ question.type = 'confirm';
186
+ break;
187
+ case 'list':
188
+ question.type = definition.multiselect ? 'checkbox' : 'list';
189
+ question.choices = (_a = definition.items) === null || _a === void 0 ? void 0 : _a.map((item) => {
190
+ return typeof item == 'string'
191
+ ? item
192
+ : {
193
+ name: item.label,
194
+ value: item.value,
195
+ };
196
+ });
197
+ break;
198
+ default:
199
+ question.type = definition.type;
200
+ break;
201
+ }
202
+ return question;
203
+ });
204
+ if (questions.length) {
205
+ const { prompt } = await Promise.resolve().then(() => __importStar(require('inquirer')));
206
+ return prompt(questions);
207
+ }
208
+ else {
209
+ return {};
210
+ }
211
+ });
212
+ }
213
+ return (this._workflowForExecution = workflow);
214
+ }
215
+ async getSchematicCollections() {
216
+ var _a;
217
+ if (this._schematicCollections) {
218
+ return this._schematicCollections;
219
+ }
220
+ const getSchematicCollections = (configSection) => {
221
+ if (!configSection) {
222
+ return undefined;
223
+ }
224
+ const { schematicCollections, defaultCollection } = configSection;
225
+ if (Array.isArray(schematicCollections)) {
226
+ return new Set(schematicCollections);
227
+ }
228
+ else if (typeof defaultCollection === 'string') {
229
+ return new Set([defaultCollection]);
230
+ }
231
+ return undefined;
232
+ };
233
+ const { workspace, globalConfiguration } = this.context;
234
+ if (workspace) {
235
+ const project = (0, config_1.getProjectByCwd)(workspace);
236
+ if (project) {
237
+ const value = getSchematicCollections(workspace.getProjectCli(project));
238
+ if (value) {
239
+ this._schematicCollections = value;
240
+ return value;
241
+ }
242
+ }
243
+ }
244
+ const value = (_a = getSchematicCollections(workspace === null || workspace === void 0 ? void 0 : workspace.getCli())) !== null && _a !== void 0 ? _a : getSchematicCollections(globalConfiguration === null || globalConfiguration === void 0 ? void 0 : globalConfiguration.getCli());
245
+ if (value) {
246
+ this._schematicCollections = value;
247
+ return value;
248
+ }
249
+ this._schematicCollections = new Set([exports.DEFAULT_SCHEMATICS_COLLECTION]);
250
+ return this._schematicCollections;
251
+ }
252
+ parseSchematicInfo(schematic) {
253
+ if (schematic === null || schematic === void 0 ? void 0 : schematic.includes(':')) {
254
+ const [collectionName, schematicName] = schematic.split(':', 2);
255
+ return [collectionName, schematicName];
256
+ }
257
+ return [undefined, schematic];
258
+ }
259
+ async runSchematic(options) {
260
+ const { logger } = this.context;
261
+ const { schematicOptions, executionOptions, collectionName, schematicName } = options;
262
+ const workflow = await this.getOrCreateWorkflowForExecution(collectionName, executionOptions);
263
+ if (!schematicName) {
264
+ throw new Error('schematicName cannot be undefined.');
265
+ }
266
+ const { unsubscribe, files } = (0, schematic_workflow_1.subscribeToWorkflow)(workflow, logger);
267
+ try {
268
+ await workflow
269
+ .execute({
270
+ collection: collectionName,
271
+ schematic: schematicName,
272
+ options: schematicOptions,
273
+ logger,
274
+ allowPrivate: this.allowPrivateSchematics,
275
+ })
276
+ .toPromise();
277
+ if (!files.size) {
278
+ logger.info('Nothing to be done.');
279
+ }
280
+ if (executionOptions.dryRun) {
281
+ logger.warn(`\nNOTE: The "--dry-run" option means no changes were made.`);
282
+ }
283
+ }
284
+ catch (err) {
285
+ // In case the workflow was not successful, show an appropriate error message.
286
+ if (err instanceof schematics_1.UnsuccessfulWorkflowExecution) {
287
+ // "See above" because we already printed the error.
288
+ logger.fatal('The Schematic workflow failed. See above.');
289
+ return 1;
290
+ }
291
+ else {
292
+ throw err;
293
+ }
294
+ }
295
+ finally {
296
+ unsubscribe();
297
+ }
298
+ return 0;
299
+ }
300
+ getProjectName() {
301
+ const { workspace, logger } = this.context;
302
+ if (!workspace) {
303
+ return undefined;
304
+ }
305
+ const projectName = (0, config_1.getProjectByCwd)(workspace);
306
+ if (projectName) {
307
+ return projectName;
308
+ }
309
+ const defaultProjectName = workspace.extensions['defaultProject'];
310
+ if (typeof defaultProjectName === 'string' && defaultProjectName) {
311
+ if (!this.defaultProjectDeprecationWarningShown) {
312
+ logger.warn(core_1.tags.oneLine `
313
+ DEPRECATED: The 'defaultProject' workspace option has been deprecated.
314
+ The project to use will be determined from the current working directory.
315
+ `);
316
+ this.defaultProjectDeprecationWarningShown = true;
317
+ }
318
+ return defaultProjectName;
319
+ }
320
+ return undefined;
321
+ }
322
+ getResolvePaths(collectionName) {
323
+ const { workspace, root } = this.context;
324
+ return workspace
325
+ ? // Workspace
326
+ collectionName === exports.DEFAULT_SCHEMATICS_COLLECTION
327
+ ? // Favor __dirname for @schematics/angular to use the build-in version
328
+ [__dirname, process.cwd(), root]
329
+ : [process.cwd(), root, __dirname]
330
+ : // Global
331
+ [__dirname, process.cwd()];
332
+ }
333
+ }
334
+ exports.SchematicsCommandModule = SchematicsCommandModule;
335
+ SchematicsCommandModule.scope = command_module_1.CommandScope.In;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Argv } from 'yargs';
9
+ import { CommandContext, CommandModule, CommandModuleImplementation } from '../command-module';
10
+ export declare const demandCommandFailureMessage = "You need to specify a command before moving on. Use '--help' to view the available commands.";
11
+ export declare function addCommandModuleToYargs<T, U extends Partial<CommandModuleImplementation> & {
12
+ new (context: CommandContext): Partial<CommandModuleImplementation> & CommandModule;
13
+ }>(localYargs: Argv<T>, commandModule: U, context: CommandContext): Argv<T>;
@@ -0,0 +1,27 @@
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
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.addCommandModuleToYargs = exports.demandCommandFailureMessage = void 0;
11
+ exports.demandCommandFailureMessage = `You need to specify a command before moving on. Use '--help' to view the available commands.`;
12
+ function addCommandModuleToYargs(localYargs, commandModule, context) {
13
+ const cmd = new commandModule(context);
14
+ const describe = context.args.options.jsonHelp ? cmd.fullDescribe : cmd.describe;
15
+ return localYargs.command({
16
+ command: cmd.command,
17
+ aliases: cmd.aliases,
18
+ describe:
19
+ // We cannot add custom fields in help, such as long command description which is used in AIO.
20
+ // Therefore, we get around this by adding a complex object as a string which we later parse when generating the help files.
21
+ typeof describe === 'object' ? JSON.stringify(describe) : describe,
22
+ deprecated: cmd.deprecated,
23
+ builder: (argv) => cmd.builder(argv),
24
+ handler: (args) => cmd.handler(args),
25
+ });
26
+ }
27
+ exports.addCommandModuleToYargs = addCommandModuleToYargs;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ interface JsonHelpOption {
9
+ name: string;
10
+ type?: string;
11
+ deprecated: boolean | string;
12
+ aliases?: string[];
13
+ default?: string;
14
+ required?: boolean;
15
+ positional?: number;
16
+ enum?: string[];
17
+ description?: string;
18
+ }
19
+ interface JsonHelpDescription {
20
+ shortDescription?: string;
21
+ longDescription?: string;
22
+ longDescriptionRelativePath?: string;
23
+ }
24
+ interface JsonHelpSubcommand extends JsonHelpDescription {
25
+ name: string;
26
+ aliases: string[];
27
+ deprecated: string | boolean;
28
+ }
29
+ export interface JsonHelp extends JsonHelpDescription {
30
+ name: string;
31
+ command: string;
32
+ options: JsonHelpOption[];
33
+ subcommands?: JsonHelpSubcommand[];
34
+ }
35
+ export declare function jsonHelpUsage(): string;
36
+ export {};
@@ -0,0 +1,94 @@
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
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.jsonHelpUsage = void 0;
14
+ const yargs_1 = __importDefault(require("yargs"));
15
+ const yargsDefaultCommandRegExp = /^\$0|\*/;
16
+ function jsonHelpUsage() {
17
+ var _a, _b, _c, _d, _e;
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ const localYargs = yargs_1.default;
20
+ const { deprecatedOptions, alias: aliases, array, string, boolean, number, choices, demandedOptions, default: defaultVal, hiddenOptions = [], } = localYargs.getOptions();
21
+ const internalMethods = localYargs.getInternalMethods();
22
+ const usageInstance = internalMethods.getUsageInstance();
23
+ const context = internalMethods.getContext();
24
+ const descriptions = usageInstance.getDescriptions();
25
+ const groups = localYargs.getGroups();
26
+ const positional = groups[usageInstance.getPositionalGroupName()];
27
+ const hidden = new Set(hiddenOptions);
28
+ const normalizeOptions = [];
29
+ const allAliases = new Set([...Object.values(aliases).flat()]);
30
+ for (const [names, type] of [
31
+ [array, 'array'],
32
+ [string, 'string'],
33
+ [boolean, 'boolean'],
34
+ [number, 'number'],
35
+ ]) {
36
+ for (const name of names) {
37
+ if (allAliases.has(name) || hidden.has(name)) {
38
+ // Ignore hidden, aliases and already visited option.
39
+ continue;
40
+ }
41
+ const positionalIndex = (_a = positional === null || positional === void 0 ? void 0 : positional.indexOf(name)) !== null && _a !== void 0 ? _a : -1;
42
+ const alias = aliases[name];
43
+ normalizeOptions.push({
44
+ name,
45
+ type,
46
+ deprecated: deprecatedOptions[name],
47
+ aliases: (alias === null || alias === void 0 ? void 0 : alias.length) > 0 ? alias : undefined,
48
+ default: defaultVal[name],
49
+ required: demandedOptions[name],
50
+ enum: choices[name],
51
+ description: (_b = descriptions[name]) === null || _b === void 0 ? void 0 : _b.replace('__yargsString__:', ''),
52
+ positional: positionalIndex >= 0 ? positionalIndex : undefined,
53
+ });
54
+ }
55
+ }
56
+ // https://github.com/yargs/yargs/blob/00e4ebbe3acd438e73fdb101e75b4f879eb6d345/lib/usage.ts#L124
57
+ const subcommands = usageInstance.getCommands()
58
+ .map(([name, rawDescription, isDefault, aliases, deprecated]) => ({
59
+ name: name.split(' ', 1)[0].replace(yargsDefaultCommandRegExp, ''),
60
+ command: name.replace(yargsDefaultCommandRegExp, ''),
61
+ default: isDefault || undefined,
62
+ ...parseDescription(rawDescription),
63
+ aliases,
64
+ deprecated,
65
+ }))
66
+ .sort((a, b) => a.name.localeCompare(b.name));
67
+ const [command, rawDescription] = (_c = usageInstance.getUsage()[0]) !== null && _c !== void 0 ? _c : [];
68
+ const defaultSubCommand = (_e = (_d = subcommands.find((x) => x.default)) === null || _d === void 0 ? void 0 : _d.command) !== null && _e !== void 0 ? _e : '';
69
+ const otherSubcommands = subcommands.filter((s) => !s.default);
70
+ const output = {
71
+ name: [...context.commands].pop(),
72
+ command: `${command === null || command === void 0 ? void 0 : command.replace(yargsDefaultCommandRegExp, localYargs['$0'])}${defaultSubCommand}`,
73
+ ...parseDescription(rawDescription),
74
+ options: normalizeOptions.sort((a, b) => a.name.localeCompare(b.name)),
75
+ subcommands: otherSubcommands.length ? otherSubcommands : undefined,
76
+ };
77
+ return JSON.stringify(output, undefined, 2);
78
+ }
79
+ exports.jsonHelpUsage = jsonHelpUsage;
80
+ function parseDescription(rawDescription) {
81
+ try {
82
+ const { longDescription, describe: shortDescription, longDescriptionRelativePath, } = JSON.parse(rawDescription);
83
+ return {
84
+ shortDescription,
85
+ longDescriptionRelativePath,
86
+ longDescription,
87
+ };
88
+ }
89
+ catch {
90
+ return {
91
+ shortDescription: rawDescription,
92
+ };
93
+ }
94
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { json } from '@angular-devkit/core';
9
+ import yargs from 'yargs';
10
+ /**
11
+ * An option description.
12
+ */
13
+ export interface Option extends yargs.Options {
14
+ /**
15
+ * The name of the option.
16
+ */
17
+ name: string;
18
+ /**
19
+ * Whether this option is required or not.
20
+ */
21
+ required?: boolean;
22
+ /**
23
+ * Format field of this option.
24
+ */
25
+ format?: string;
26
+ /**
27
+ * Whether this option should be hidden from the help output. It will still show up in JSON help.
28
+ */
29
+ hidden?: boolean;
30
+ /**
31
+ * If this option can be used as an argument, the position of the argument. Otherwise omitted.
32
+ */
33
+ positional?: number;
34
+ /**
35
+ * Whether or not to report this option to the Angular Team, and which custom field to use.
36
+ * If this is falsey, do not report this option.
37
+ */
38
+ userAnalytics?: number;
39
+ }
40
+ export declare function parseJsonSchemaToOptions(registry: json.schema.SchemaRegistry, schema: json.JsonObject, interactive?: boolean): Promise<Option[]>;