@angular/cli 14.0.0-next.3 → 14.0.0-next.6

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 (217) hide show
  1. package/bin/ng.js +3 -5
  2. package/bin/postinstall/analytics-prompt.js +3 -3
  3. package/lib/cli/index.d.ts +1 -1
  4. package/lib/cli/index.js +16 -18
  5. package/lib/config/schema.json +8 -12
  6. package/lib/config/workspace-schema.d.ts +1 -1
  7. package/lib/init.js +8 -4
  8. package/package.json +17 -16
  9. package/{models → src/analytics}/analytics-collector.d.ts +0 -0
  10. package/{models → src/analytics}/analytics-collector.js +6 -2
  11. package/src/analytics/analytics-environment-options.d.ts +9 -0
  12. package/src/analytics/analytics-environment-options.js +20 -0
  13. package/src/analytics/analytics.d.ts +47 -0
  14. package/src/analytics/analytics.js +303 -0
  15. package/src/command-builder/architect-base-command-module.d.ts +23 -0
  16. package/src/command-builder/architect-base-command-module.js +103 -0
  17. package/src/command-builder/architect-command-module.d.ts +22 -0
  18. package/src/command-builder/architect-command-module.js +108 -0
  19. package/src/command-builder/command-module.d.ts +88 -0
  20. package/src/command-builder/command-module.js +191 -0
  21. package/src/command-builder/command-runner.d.ts +10 -0
  22. package/src/command-builder/command-runner.js +135 -0
  23. package/src/command-builder/schematics-command-module.d.ts +44 -0
  24. package/src/command-builder/schematics-command-module.js +295 -0
  25. package/src/command-builder/utilities/command.d.ts +13 -0
  26. package/src/command-builder/utilities/command.js +27 -0
  27. package/src/command-builder/utilities/json-help.d.ts +36 -0
  28. package/src/command-builder/utilities/json-help.js +94 -0
  29. package/src/command-builder/utilities/json-schema.d.ts +40 -0
  30. package/{utilities → src/command-builder/utilities}/json-schema.js +20 -121
  31. package/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +0 -0
  32. package/{models → src/command-builder/utilities}/schematic-engine-host.js +0 -0
  33. package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
  34. package/src/command-builder/utilities/schematic-workflow.js +68 -0
  35. package/src/commands/add/cli.d.ts +33 -0
  36. package/{commands/add-impl.js → src/commands/add/cli.js} +100 -72
  37. package/{commands/add.md → src/commands/add/long-description.md} +0 -0
  38. package/src/commands/analytics/cli.d.ts +16 -0
  39. package/src/commands/analytics/cli.js +35 -0
  40. package/src/commands/analytics/info/cli.d.ts +16 -0
  41. package/src/commands/analytics/info/cli.js +26 -0
  42. package/src/commands/analytics/settings/cli.d.ts +35 -0
  43. package/src/commands/analytics/settings/cli.js +61 -0
  44. package/src/commands/build/cli.d.ts +16 -0
  45. package/src/commands/build/cli.js +23 -0
  46. package/{commands/build-long.md → src/commands/build/long-description.md} +0 -0
  47. package/src/commands/config/cli.d.ts +24 -0
  48. package/{commands/config-impl.js → src/commands/config/cli.js} +102 -89
  49. package/{commands/config-long.md → src/commands/config/long-description.md} +2 -2
  50. package/src/commands/deploy/cli.d.ts +16 -0
  51. package/src/commands/deploy/cli.js +35 -0
  52. package/{commands/deploy-long.md → src/commands/deploy/long-description.md} +0 -0
  53. package/src/commands/doc/cli.d.ts +23 -0
  54. package/{commands/doc-impl.js → src/commands/doc/cli.js} +41 -12
  55. package/src/commands/e2e/cli.d.ts +17 -0
  56. package/src/commands/e2e/cli.js +34 -0
  57. package/src/commands/extract-i18n/cli.d.ts +15 -0
  58. package/src/commands/extract-i18n/cli.js +20 -0
  59. package/src/commands/generate/cli.d.ts +29 -0
  60. package/src/commands/generate/cli.js +114 -0
  61. package/src/commands/lint/cli.d.ts +16 -0
  62. package/src/commands/lint/cli.js +31 -0
  63. package/{commands/lint-long.md → src/commands/lint/long-description.md} +0 -0
  64. package/src/commands/make-this-awesome/cli.d.ts +17 -0
  65. package/{commands/easter-egg-impl.js → src/commands/make-this-awesome/cli.js} +17 -10
  66. package/src/commands/new/cli.d.ts +25 -0
  67. package/src/commands/new/cli.js +66 -0
  68. package/src/commands/run/cli.d.ts +23 -0
  69. package/src/commands/run/cli.js +59 -0
  70. package/{commands/run-long.md → src/commands/run/long-description.md} +0 -0
  71. package/src/commands/serve/cli.d.ts +16 -0
  72. package/src/commands/serve/cli.js +21 -0
  73. package/src/commands/test/cli.d.ts +16 -0
  74. package/src/commands/test/cli.js +23 -0
  75. package/{commands/test-long.md → src/commands/test/long-description.md} +0 -0
  76. package/{commands/update-impl.d.ts → src/commands/update/cli.d.ts} +25 -9
  77. package/{commands/update-impl.js → src/commands/update/cli.js} +323 -306
  78. package/{commands/update-long.md → src/commands/update/long-description.md} +0 -0
  79. package/src/commands/update/schematic/index.js +6 -2
  80. package/src/commands/version/cli.d.ts +19 -0
  81. package/{commands/version-impl.js → src/commands/version/cli.js} +57 -56
  82. package/src/typings.d.ts +2 -2
  83. package/{utilities → src/utilities}/color.d.ts +0 -0
  84. package/{utilities → src/utilities}/color.js +5 -1
  85. package/{utilities → src/utilities}/config.d.ts +2 -1
  86. package/{utilities → src/utilities}/config.js +38 -7
  87. package/{utilities → src/utilities}/find-up.d.ts +0 -0
  88. package/{utilities → src/utilities}/find-up.js +5 -1
  89. package/{utilities → src/utilities}/install-package.d.ts +2 -2
  90. package/{utilities → src/utilities}/install-package.js +1 -1
  91. package/{utilities → src/utilities}/json-file.d.ts +0 -0
  92. package/{utilities → src/utilities}/json-file.js +0 -0
  93. package/{utilities → src/utilities}/log-file.d.ts +0 -0
  94. package/{utilities → src/utilities}/log-file.js +0 -0
  95. package/{utilities → src/utilities}/package-json.d.ts +0 -0
  96. package/{utilities → src/utilities}/package-json.js +0 -0
  97. package/{utilities → src/utilities}/package-manager.d.ts +1 -1
  98. package/{utilities → src/utilities}/package-manager.js +1 -1
  99. package/{utilities → src/utilities}/package-metadata.d.ts +0 -0
  100. package/{utilities → src/utilities}/package-metadata.js +5 -1
  101. package/{utilities → src/utilities}/package-tree.d.ts +0 -0
  102. package/{utilities → src/utilities}/package-tree.js +5 -1
  103. package/{utilities → src/utilities}/project.d.ts +0 -0
  104. package/{utilities → src/utilities}/project.js +5 -1
  105. package/{utilities → src/utilities}/prompt.d.ts +0 -0
  106. package/{utilities → src/utilities}/prompt.js +5 -1
  107. package/{utilities → src/utilities}/spinner.d.ts +0 -0
  108. package/{utilities → src/utilities}/spinner.js +0 -0
  109. package/{utilities → src/utilities}/tty.d.ts +0 -0
  110. package/{utilities → src/utilities}/tty.js +0 -0
  111. package/{models → src/utilities}/version.d.ts +2 -1
  112. package/{models → src/utilities}/version.js +6 -6
  113. package/commands/add-impl.d.ts +0 -21
  114. package/commands/add.d.ts +0 -42
  115. package/commands/add.js +0 -10
  116. package/commands/add.json +0 -54
  117. package/commands/analytics-impl.d.ts +0 -13
  118. package/commands/analytics-impl.js +0 -80
  119. package/commands/analytics-long.md +0 -8
  120. package/commands/analytics.d.ts +0 -46
  121. package/commands/analytics.js +0 -31
  122. package/commands/analytics.json +0 -37
  123. package/commands/build-impl.d.ts +0 -14
  124. package/commands/build-impl.js +0 -21
  125. package/commands/build.d.ts +0 -30
  126. package/commands/build.js +0 -10
  127. package/commands/build.json +0 -16
  128. package/commands/config-impl.d.ts +0 -15
  129. package/commands/config.d.ts +0 -34
  130. package/commands/config.js +0 -10
  131. package/commands/config.json +0 -43
  132. package/commands/definitions.json +0 -66
  133. package/commands/deploy-impl.d.ts +0 -15
  134. package/commands/deploy-impl.js +0 -36
  135. package/commands/deploy.d.ts +0 -30
  136. package/commands/deploy.js +0 -10
  137. package/commands/deploy.json +0 -34
  138. package/commands/doc-impl.d.ts +0 -13
  139. package/commands/doc.d.ts +0 -39
  140. package/commands/doc.js +0 -14
  141. package/commands/doc.json +0 -46
  142. package/commands/e2e-impl.d.ts +0 -16
  143. package/commands/e2e-impl.js +0 -36
  144. package/commands/e2e-long.md +0 -4
  145. package/commands/e2e.d.ts +0 -29
  146. package/commands/e2e.js +0 -10
  147. package/commands/e2e.json +0 -17
  148. package/commands/easter-egg-impl.d.ts +0 -12
  149. package/commands/easter-egg.d.ts +0 -14
  150. package/commands/easter-egg.js +0 -10
  151. package/commands/easter-egg.json +0 -12
  152. package/commands/extract-i18n-impl.d.ts +0 -14
  153. package/commands/extract-i18n-impl.js +0 -21
  154. package/commands/extract-i18n.d.ts +0 -29
  155. package/commands/extract-i18n.js +0 -10
  156. package/commands/extract-i18n.json +0 -15
  157. package/commands/generate-impl.d.ts +0 -18
  158. package/commands/generate-impl.js +0 -89
  159. package/commands/generate.d.ts +0 -37
  160. package/commands/generate.js +0 -10
  161. package/commands/generate.json +0 -31
  162. package/commands/help-impl.d.ts +0 -12
  163. package/commands/help-impl.js +0 -26
  164. package/commands/help-long.md +0 -7
  165. package/commands/help.d.ts +0 -17
  166. package/commands/help.js +0 -10
  167. package/commands/help.json +0 -13
  168. package/commands/lint-impl.d.ts +0 -16
  169. package/commands/lint-impl.js +0 -69
  170. package/commands/lint.d.ts +0 -29
  171. package/commands/lint.js +0 -10
  172. package/commands/lint.json +0 -36
  173. package/commands/new-impl.d.ts +0 -16
  174. package/commands/new-impl.js +0 -37
  175. package/commands/new.d.ts +0 -41
  176. package/commands/new.js +0 -10
  177. package/commands/new.json +0 -34
  178. package/commands/new.md +0 -16
  179. package/commands/run-impl.d.ts +0 -13
  180. package/commands/run-impl.js +0 -22
  181. package/commands/run.d.ts +0 -30
  182. package/commands/run.js +0 -10
  183. package/commands/run.json +0 -36
  184. package/commands/serve-impl.d.ts +0 -15
  185. package/commands/serve-impl.js +0 -24
  186. package/commands/serve.d.ts +0 -29
  187. package/commands/serve.js +0 -10
  188. package/commands/serve.json +0 -17
  189. package/commands/test-impl.d.ts +0 -15
  190. package/commands/test-impl.js +0 -22
  191. package/commands/test.d.ts +0 -29
  192. package/commands/test.js +0 -10
  193. package/commands/test.json +0 -17
  194. package/commands/update.d.ts +0 -61
  195. package/commands/update.js +0 -10
  196. package/commands/update.json +0 -78
  197. package/commands/version-impl.d.ts +0 -17
  198. package/commands/version.d.ts +0 -17
  199. package/commands/version.js +0 -10
  200. package/commands/version.json +0 -13
  201. package/commands.json +0 -20
  202. package/models/analytics.d.ts +0 -58
  203. package/models/analytics.js +0 -358
  204. package/models/architect-command.d.ts +0 -35
  205. package/models/architect-command.js +0 -364
  206. package/models/command-runner.d.ts +0 -24
  207. package/models/command-runner.js +0 -241
  208. package/models/command.d.ts +0 -34
  209. package/models/command.js +0 -143
  210. package/models/interface.d.ts +0 -196
  211. package/models/interface.js +0 -31
  212. package/models/parser.d.ts +0 -39
  213. package/models/parser.js +0 -349
  214. package/models/schematic-command.d.ts +0 -55
  215. package/models/schematic-command.js +0 -485
  216. package/utilities/INITIAL_COMMIT_MESSAGE.txt +0 -8
  217. package/utilities/json-schema.d.ts +0 -17
@@ -0,0 +1,191 @@
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.CommandModuleError = exports.CommandModule = exports.CommandScope = void 0;
34
+ const core_1 = require("@angular-devkit/core");
35
+ const fs_1 = require("fs");
36
+ const path = __importStar(require("path"));
37
+ const helpers_1 = require("yargs/helpers");
38
+ const analytics_1 = require("../analytics/analytics");
39
+ var CommandScope;
40
+ (function (CommandScope) {
41
+ /** Command can only run inside an Angular workspace. */
42
+ CommandScope[CommandScope["In"] = 0] = "In";
43
+ /** Command can only run outside an Angular workspace. */
44
+ CommandScope[CommandScope["Out"] = 1] = "Out";
45
+ /** Command can run inside and outside an Angular workspace. */
46
+ CommandScope[CommandScope["Both"] = 2] = "Both";
47
+ })(CommandScope = exports.CommandScope || (exports.CommandScope = {}));
48
+ class CommandModule {
49
+ constructor(context) {
50
+ this.context = context;
51
+ this.shouldReportAnalytics = true;
52
+ this.optionsWithAnalytics = new Map();
53
+ }
54
+ /**
55
+ * Description object which contains the long command descroption.
56
+ * This is used to generate JSON help wich is used in AIO.
57
+ *
58
+ * `false` will result in a hidden command.
59
+ */
60
+ get fullDescribe() {
61
+ return this.describe === false
62
+ ? false
63
+ : {
64
+ describe: this.describe,
65
+ ...(this.longDescriptionPath
66
+ ? {
67
+ longDescriptionRelativePath: path
68
+ .relative(path.join(__dirname, '../../../../'), this.longDescriptionPath)
69
+ .replace(/\\/g, path.posix.sep),
70
+ longDescription: (0, fs_1.readFileSync)(this.longDescriptionPath, 'utf8').replace(/\r\n/g, '\n'),
71
+ }
72
+ : {}),
73
+ };
74
+ }
75
+ get commandName() {
76
+ return this.command.split(' ', 1)[0];
77
+ }
78
+ async handler(args) {
79
+ const { _, $0, ...options } = args;
80
+ // Camelize options as yargs will return the object in kebab-case when camel casing is disabled.
81
+ const camelCasedOptions = {};
82
+ for (const [key, value] of Object.entries(options)) {
83
+ camelCasedOptions[helpers_1.Parser.camelCase(key)] = value;
84
+ }
85
+ // Gather and report analytics.
86
+ const analytics = await this.getAnalytics();
87
+ if (this.shouldReportAnalytics) {
88
+ await this.reportAnalytics(camelCasedOptions);
89
+ }
90
+ let exitCode;
91
+ try {
92
+ // Run and time command.
93
+ const startTime = Date.now();
94
+ exitCode = await this.run(camelCasedOptions);
95
+ const endTime = Date.now();
96
+ analytics.timing(this.commandName, 'duration', endTime - startTime);
97
+ await analytics.flush();
98
+ }
99
+ catch (e) {
100
+ if (e instanceof core_1.schema.SchemaValidationException) {
101
+ this.context.logger.fatal(`Error: ${e.message}`);
102
+ exitCode = 1;
103
+ }
104
+ else {
105
+ throw e;
106
+ }
107
+ }
108
+ finally {
109
+ if (typeof exitCode === 'number' && exitCode > 0) {
110
+ process.exitCode = exitCode;
111
+ }
112
+ }
113
+ }
114
+ async reportAnalytics(options, paths = [], dimensions = []) {
115
+ for (const [name, ua] of this.optionsWithAnalytics) {
116
+ const value = options[name];
117
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
118
+ dimensions[ua] = value;
119
+ }
120
+ }
121
+ const analytics = await this.getAnalytics();
122
+ analytics.pageview('/command/' + [this.commandName, ...paths].join('/'), {
123
+ dimensions,
124
+ metrics: [],
125
+ });
126
+ }
127
+ async getAnalytics() {
128
+ if (this._analytics) {
129
+ return this._analytics;
130
+ }
131
+ return (this._analytics = await (0, analytics_1.createAnalytics)(!!this.context.workspace,
132
+ // Don't prompt for `ng update` and `ng analytics` commands.
133
+ ['update', 'analytics'].includes(this.commandName)));
134
+ }
135
+ /**
136
+ * Adds schema options to a command also this keeps track of options that are required for analytics.
137
+ * **Note:** This method should be called from the command bundler method.
138
+ */
139
+ addSchemaOptionsToCommand(localYargs, options) {
140
+ const workingDir = (0, core_1.normalize)(path.relative(this.context.root, process.cwd()));
141
+ for (const option of options) {
142
+ const { default: defaultVal, positional, deprecated, description, alias, userAnalytics, type, hidden, name, choices, format, } = option;
143
+ const sharedOptions = {
144
+ alias,
145
+ hidden,
146
+ description,
147
+ deprecated,
148
+ choices,
149
+ // This should only be done when `--help` is used otherwise default will override options set in angular.json.
150
+ ...(this.context.args.options.help ? { default: defaultVal } : {}),
151
+ };
152
+ // Special case for schematics
153
+ if (workingDir && format === 'path' && name === 'path' && hidden) {
154
+ sharedOptions.default = workingDir;
155
+ }
156
+ if (positional === undefined) {
157
+ localYargs = localYargs.option(core_1.strings.dasherize(name), {
158
+ type,
159
+ ...sharedOptions,
160
+ });
161
+ }
162
+ else {
163
+ localYargs = localYargs.positional(core_1.strings.dasherize(name), {
164
+ type: type === 'array' || type === 'count' ? 'string' : type,
165
+ ...sharedOptions,
166
+ });
167
+ }
168
+ // Record option of analytics.
169
+ if (userAnalytics !== undefined) {
170
+ this.optionsWithAnalytics.set(name, userAnalytics);
171
+ }
172
+ }
173
+ return localYargs;
174
+ }
175
+ getWorkspaceOrThrow() {
176
+ const { workspace } = this.context;
177
+ if (!workspace) {
178
+ throw new CommandModuleError('A workspace is required for this command.');
179
+ }
180
+ return workspace;
181
+ }
182
+ }
183
+ exports.CommandModule = CommandModule;
184
+ CommandModule.scope = CommandScope.Both;
185
+ /**
186
+ * Creates an known command module error.
187
+ * This is used so during executation we can filter between known validation error and real non handled errors.
188
+ */
189
+ class CommandModuleError extends Error {
190
+ }
191
+ exports.CommandModuleError = CommandModuleError;
@@ -0,0 +1,10 @@
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 { logging } from '@angular-devkit/core';
9
+ import { AngularWorkspace } from '../utilities/config';
10
+ export declare function runCommand(args: string[], logger: logging.Logger, workspace: AngularWorkspace | undefined): Promise<number>;
@@ -0,0 +1,135 @@
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.runCommand = void 0;
14
+ const yargs_1 = __importDefault(require("yargs"));
15
+ const helpers_1 = require("yargs/helpers");
16
+ const cli_1 = require("../commands/add/cli");
17
+ const cli_2 = require("../commands/analytics/cli");
18
+ const cli_3 = require("../commands/build/cli");
19
+ const cli_4 = require("../commands/config/cli");
20
+ const cli_5 = require("../commands/deploy/cli");
21
+ const cli_6 = require("../commands/doc/cli");
22
+ const cli_7 = require("../commands/e2e/cli");
23
+ const cli_8 = require("../commands/extract-i18n/cli");
24
+ const cli_9 = require("../commands/generate/cli");
25
+ const cli_10 = require("../commands/lint/cli");
26
+ const cli_11 = require("../commands/make-this-awesome/cli");
27
+ const cli_12 = require("../commands/new/cli");
28
+ const cli_13 = require("../commands/run/cli");
29
+ const cli_14 = require("../commands/serve/cli");
30
+ const cli_15 = require("../commands/test/cli");
31
+ const cli_16 = require("../commands/update/cli");
32
+ const cli_17 = require("../commands/version/cli");
33
+ const color_1 = require("../utilities/color");
34
+ const package_manager_1 = require("../utilities/package-manager");
35
+ const command_module_1 = require("./command-module");
36
+ const command_1 = require("./utilities/command");
37
+ const json_help_1 = require("./utilities/json-help");
38
+ const COMMANDS = [
39
+ cli_17.VersionCommandModule,
40
+ cli_6.DocCommandModule,
41
+ cli_11.AwesomeCommandModule,
42
+ cli_4.ConfigCommandModule,
43
+ cli_2.AnalyticsCommandModule,
44
+ cli_1.AddCommandModule,
45
+ cli_9.GenerateCommandModule,
46
+ cli_3.BuildCommandModule,
47
+ cli_7.E2eCommandModule,
48
+ cli_15.TestCommandModule,
49
+ cli_14.ServeCommandModule,
50
+ cli_8.ExtractI18nCommandModule,
51
+ cli_5.DeployCommandModule,
52
+ cli_10.LintCommandModule,
53
+ cli_12.NewCommandModule,
54
+ cli_16.UpdateCommandModule,
55
+ cli_13.RunCommandModule,
56
+ ].sort(); // Will be sorted by class name.
57
+ const yargsParser = helpers_1.Parser;
58
+ async function runCommand(args, logger, workspace) {
59
+ var _a, _b, _c;
60
+ const { $0, _: positional, help = false, jsonHelp = false, ...rest } = yargsParser(args, { boolean: ['help', 'json-help'], alias: { 'collection': 'c' } });
61
+ const context = {
62
+ workspace,
63
+ logger,
64
+ currentDirectory: process.cwd(),
65
+ root: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.basePath) !== null && _a !== void 0 ? _a : process.cwd(),
66
+ packageManager: await (0, package_manager_1.getPackageManager)((_b = workspace === null || workspace === void 0 ? void 0 : workspace.basePath) !== null && _b !== void 0 ? _b : process.cwd()),
67
+ args: {
68
+ positional: positional.map((v) => v.toString()),
69
+ options: {
70
+ help,
71
+ jsonHelp,
72
+ ...rest,
73
+ },
74
+ },
75
+ };
76
+ let localYargs = (0, yargs_1.default)(args);
77
+ for (const CommandModule of COMMANDS) {
78
+ if (!jsonHelp) {
79
+ // Skip scope validation when running with '--json-help' since it's easier to generate the output for all commands this way.
80
+ const scope = CommandModule.scope;
81
+ if ((scope === command_module_1.CommandScope.In && !workspace) || (scope === command_module_1.CommandScope.Out && workspace)) {
82
+ continue;
83
+ }
84
+ }
85
+ localYargs = (0, command_1.addCommandModuleToYargs)(localYargs, CommandModule, context);
86
+ }
87
+ if (jsonHelp) {
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+ localYargs.getInternalMethods().getUsageInstance().help = () => (0, json_help_1.jsonHelpUsage)();
90
+ }
91
+ await localYargs
92
+ .scriptName('ng')
93
+ // https://github.com/yargs/yargs/blob/main/docs/advanced.md#customizing-yargs-parser
94
+ .parserConfiguration({
95
+ 'populate--': true,
96
+ 'unknown-options-as-args': false,
97
+ 'dot-notation': false,
98
+ 'boolean-negation': true,
99
+ 'strip-aliased': true,
100
+ 'strip-dashed': true,
101
+ 'camel-case-expansion': false,
102
+ })
103
+ .option('json-help', {
104
+ describe: 'Show help in JSON format.',
105
+ implies: ['help'],
106
+ hidden: true,
107
+ type: 'boolean',
108
+ })
109
+ .help('help', 'Shows a help message for this command in the console.')
110
+ // A complete list of strings can be found: https://github.com/yargs/yargs/blob/main/locales/en.json
111
+ .updateStrings({
112
+ 'Commands:': color_1.colors.cyan('Commands:'),
113
+ 'Options:': color_1.colors.cyan('Options:'),
114
+ 'Positionals:': color_1.colors.cyan('Arguments:'),
115
+ 'deprecated': color_1.colors.yellow('deprecated'),
116
+ 'deprecated: %s': color_1.colors.yellow('deprecated:') + ' %s',
117
+ 'Did you mean %s?': 'Unknown command. Did you mean %s?',
118
+ })
119
+ .demandCommand(1, command_1.demandCommandFailureMessage)
120
+ .recommendCommands()
121
+ .version(false)
122
+ .showHelpOnFail(false)
123
+ .strict()
124
+ .fail((msg, err) => {
125
+ throw msg
126
+ ? // Validation failed example: `Unknown argument:`
127
+ new command_module_1.CommandModuleError(msg)
128
+ : // Unknown exception, re-throw.
129
+ err;
130
+ })
131
+ .wrap(yargs_1.default.terminalWidth())
132
+ .parseAsync();
133
+ return (_c = process.exitCode) !== null && _c !== void 0 ? _c : 0;
134
+ }
135
+ exports.runCommand = runCommand;
@@ -0,0 +1,44 @@
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 { Collection } from '@angular-devkit/schematics';
9
+ import { FileSystemCollectionDescription, FileSystemSchematicDescription, NodeWorkflow } from '@angular-devkit/schematics/tools';
10
+ import { Argv } from 'yargs';
11
+ import { CommandModule, CommandModuleImplementation, CommandScope, Options, OtherOptions } from './command-module';
12
+ import { Option } from './utilities/json-schema';
13
+ export interface SchematicsCommandArgs {
14
+ interactive: boolean;
15
+ force: boolean;
16
+ 'dry-run': boolean;
17
+ defaults: boolean;
18
+ }
19
+ export interface SchematicsExecutionOptions extends Options<SchematicsCommandArgs> {
20
+ packageRegistry?: string;
21
+ }
22
+ export declare abstract class SchematicsCommandModule extends CommandModule<SchematicsCommandArgs> implements CommandModuleImplementation<SchematicsCommandArgs> {
23
+ static scope: CommandScope;
24
+ protected readonly allowPrivateSchematics: boolean;
25
+ protected readonly shouldReportAnalytics = false;
26
+ builder(argv: Argv): Promise<Argv<SchematicsCommandArgs>>;
27
+ /** Get schematic schema options.*/
28
+ protected getSchematicOptions(collection: Collection<FileSystemCollectionDescription, FileSystemSchematicDescription>, schematicName: string, workflow: NodeWorkflow): Promise<Option[]>;
29
+ private _workflowForBuilder;
30
+ protected getOrCreateWorkflowForBuilder(collectionName: string): NodeWorkflow;
31
+ private _workflowForExecution;
32
+ protected getOrCreateWorkflowForExecution(collectionName: string, options: SchematicsExecutionOptions): Promise<NodeWorkflow>;
33
+ private _defaultSchematicCollection;
34
+ protected getDefaultSchematicCollection(): Promise<string>;
35
+ protected parseSchematicInfo(schematic: string | undefined): [collectionName: string | undefined, schematicName: string | undefined];
36
+ protected runSchematic(options: {
37
+ executionOptions: SchematicsExecutionOptions;
38
+ schematicOptions: OtherOptions;
39
+ collectionName: string;
40
+ schematicName: string;
41
+ }): Promise<number>;
42
+ private getProjectName;
43
+ private getResolvePaths;
44
+ }
@@ -0,0 +1,295 @@
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.SchematicsCommandModule = void 0;
14
+ const core_1 = require("@angular-devkit/core");
15
+ const schematics_1 = require("@angular-devkit/schematics");
16
+ const tools_1 = require("@angular-devkit/schematics/tools");
17
+ const inquirer_1 = __importDefault(require("inquirer"));
18
+ const config_1 = require("../utilities/config");
19
+ const tty_1 = require("../utilities/tty");
20
+ const command_module_1 = require("./command-module");
21
+ const json_schema_1 = require("./utilities/json-schema");
22
+ const schematic_engine_host_1 = require("./utilities/schematic-engine-host");
23
+ const schematic_workflow_1 = require("./utilities/schematic-workflow");
24
+ const DEFAULT_SCHEMATICS_COLLECTION = '@schematics/angular';
25
+ class SchematicsCommandModule extends command_module_1.CommandModule {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.allowPrivateSchematics = false;
29
+ this.shouldReportAnalytics = false;
30
+ }
31
+ async builder(argv) {
32
+ return argv
33
+ .option('interactive', {
34
+ describe: 'Enable interactive input prompts.',
35
+ type: 'boolean',
36
+ default: true,
37
+ })
38
+ .option('dry-run', {
39
+ describe: 'Run through and reports activity without writing out results.',
40
+ type: 'boolean',
41
+ default: false,
42
+ })
43
+ .option('defaults', {
44
+ describe: 'Disable interactive input prompts for options with a default.',
45
+ type: 'boolean',
46
+ default: false,
47
+ })
48
+ .option('force', {
49
+ describe: 'Force overwriting of existing files.',
50
+ type: 'boolean',
51
+ default: false,
52
+ })
53
+ .strict();
54
+ }
55
+ /** Get schematic schema options.*/
56
+ async getSchematicOptions(collection, schematicName, workflow) {
57
+ const schematic = collection.createSchematic(schematicName, true);
58
+ const { schemaJson } = schematic.description;
59
+ if (!schemaJson) {
60
+ return [];
61
+ }
62
+ return (0, json_schema_1.parseJsonSchemaToOptions)(workflow.registry, schemaJson);
63
+ }
64
+ getOrCreateWorkflowForBuilder(collectionName) {
65
+ if (this._workflowForBuilder) {
66
+ return this._workflowForBuilder;
67
+ }
68
+ return (this._workflowForBuilder = new tools_1.NodeWorkflow(this.context.root, {
69
+ resolvePaths: this.getResolvePaths(collectionName),
70
+ engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
71
+ }));
72
+ }
73
+ async getOrCreateWorkflowForExecution(collectionName, options) {
74
+ if (this._workflowForExecution) {
75
+ return this._workflowForExecution;
76
+ }
77
+ const { logger, root, packageManager } = this.context;
78
+ const { force, dryRun, packageRegistry } = options;
79
+ const workflow = new tools_1.NodeWorkflow(root, {
80
+ force,
81
+ dryRun,
82
+ packageManager,
83
+ // A schema registry is required to allow customizing addUndefinedDefaults
84
+ registry: new core_1.schema.CoreSchemaRegistry(schematics_1.formats.standardFormats),
85
+ packageRegistry,
86
+ resolvePaths: this.getResolvePaths(collectionName),
87
+ schemaValidation: true,
88
+ optionTransforms: [
89
+ // Add configuration file defaults
90
+ async (schematic, current) => {
91
+ const projectName = typeof current.project === 'string'
92
+ ? current.project
93
+ : this.getProjectName();
94
+ return {
95
+ ...(await (0, config_1.getSchematicDefaults)(schematic.collection.name, schematic.name, projectName)),
96
+ ...current,
97
+ };
98
+ },
99
+ ],
100
+ engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
101
+ });
102
+ workflow.registry.addPostTransform(core_1.schema.transforms.addUndefinedDefaults);
103
+ workflow.registry.addSmartDefaultProvider('projectName', () => this.getProjectName());
104
+ workflow.registry.useXDeprecatedProvider((msg) => logger.warn(msg));
105
+ let shouldReportAnalytics = true;
106
+ workflow.engineHost.registerOptionsTransform(async (schematic, options) => {
107
+ var _a;
108
+ if (shouldReportAnalytics) {
109
+ shouldReportAnalytics = false;
110
+ // ng generate lib -> ng generate
111
+ const commandName = (_a = this.command) === null || _a === void 0 ? void 0 : _a.split(' ', 1)[0];
112
+ await this.reportAnalytics(options, [
113
+ commandName,
114
+ schematic.collection.name.replace(/\//g, '_'),
115
+ schematic.name.replace(/\//g, '_'),
116
+ ]);
117
+ }
118
+ return options;
119
+ });
120
+ if (options.interactive !== false && (0, tty_1.isTTY)()) {
121
+ workflow.registry.usePromptProvider((definitions) => {
122
+ const questions = definitions
123
+ .filter((definition) => !options.defaults || definition.default === undefined)
124
+ .map((definition) => {
125
+ var _a;
126
+ const question = {
127
+ name: definition.id,
128
+ message: definition.message,
129
+ default: definition.default,
130
+ };
131
+ const validator = definition.validator;
132
+ if (validator) {
133
+ question.validate = (input) => validator(input);
134
+ // Filter allows transformation of the value prior to validation
135
+ question.filter = async (input) => {
136
+ for (const type of definition.propertyTypes) {
137
+ let value;
138
+ switch (type) {
139
+ case 'string':
140
+ value = String(input);
141
+ break;
142
+ case 'integer':
143
+ case 'number':
144
+ value = Number(input);
145
+ break;
146
+ default:
147
+ value = input;
148
+ break;
149
+ }
150
+ // Can be a string if validation fails
151
+ const isValid = (await validator(value)) === true;
152
+ if (isValid) {
153
+ return value;
154
+ }
155
+ }
156
+ return input;
157
+ };
158
+ }
159
+ switch (definition.type) {
160
+ case 'confirmation':
161
+ question.type = 'confirm';
162
+ break;
163
+ case 'list':
164
+ question.type = definition.multiselect ? 'checkbox' : 'list';
165
+ question.choices = (_a = definition.items) === null || _a === void 0 ? void 0 : _a.map((item) => {
166
+ return typeof item == 'string'
167
+ ? item
168
+ : {
169
+ name: item.label,
170
+ value: item.value,
171
+ };
172
+ });
173
+ break;
174
+ default:
175
+ question.type = definition.type;
176
+ break;
177
+ }
178
+ return question;
179
+ });
180
+ return inquirer_1.default.prompt(questions);
181
+ });
182
+ }
183
+ return (this._workflowForExecution = workflow);
184
+ }
185
+ async getDefaultSchematicCollection() {
186
+ if (this._defaultSchematicCollection) {
187
+ return this._defaultSchematicCollection;
188
+ }
189
+ let workspace = await (0, config_1.getWorkspace)('local');
190
+ if (workspace) {
191
+ const project = (0, config_1.getProjectByCwd)(workspace);
192
+ if (project) {
193
+ const value = workspace.getProjectCli(project)['defaultCollection'];
194
+ if (typeof value == 'string') {
195
+ return (this._defaultSchematicCollection = value);
196
+ }
197
+ }
198
+ const value = workspace.getCli()['defaultCollection'];
199
+ if (typeof value === 'string') {
200
+ return (this._defaultSchematicCollection = value);
201
+ }
202
+ }
203
+ workspace = await (0, config_1.getWorkspace)('global');
204
+ const value = workspace === null || workspace === void 0 ? void 0 : workspace.getCli()['defaultCollection'];
205
+ if (typeof value === 'string') {
206
+ return (this._defaultSchematicCollection = value);
207
+ }
208
+ return (this._defaultSchematicCollection = DEFAULT_SCHEMATICS_COLLECTION);
209
+ }
210
+ parseSchematicInfo(schematic) {
211
+ if (schematic === null || schematic === void 0 ? void 0 : schematic.includes(':')) {
212
+ const [collectionName, schematicName] = schematic.split(':', 2);
213
+ return [collectionName, schematicName];
214
+ }
215
+ return [undefined, schematic];
216
+ }
217
+ async runSchematic(options) {
218
+ const { logger } = this.context;
219
+ const { schematicOptions, executionOptions, collectionName, schematicName } = options;
220
+ const workflow = await this.getOrCreateWorkflowForExecution(collectionName, executionOptions);
221
+ if (!schematicName) {
222
+ throw new Error('schematicName cannot be undefined.');
223
+ }
224
+ const { unsubscribe, files } = (0, schematic_workflow_1.subscribeToWorkflow)(workflow, logger);
225
+ try {
226
+ await workflow
227
+ .execute({
228
+ collection: collectionName,
229
+ schematic: schematicName,
230
+ options: schematicOptions,
231
+ logger,
232
+ allowPrivate: this.allowPrivateSchematics,
233
+ })
234
+ .toPromise();
235
+ if (!files.size) {
236
+ logger.info('Nothing to be done.');
237
+ }
238
+ if (executionOptions.dryRun) {
239
+ logger.warn(`\nNOTE: The "--dry-run" option means no changes were made.`);
240
+ }
241
+ }
242
+ catch (err) {
243
+ // In case the workflow was not successful, show an appropriate error message.
244
+ if (err instanceof schematics_1.UnsuccessfulWorkflowExecution) {
245
+ // "See above" because we already printed the error.
246
+ logger.fatal('The Schematic workflow failed. See above.');
247
+ return 1;
248
+ }
249
+ else {
250
+ throw err;
251
+ }
252
+ }
253
+ finally {
254
+ unsubscribe();
255
+ }
256
+ return 0;
257
+ }
258
+ getProjectName() {
259
+ const { workspace, logger } = this.context;
260
+ if (!workspace) {
261
+ return undefined;
262
+ }
263
+ const projectNames = (0, config_1.getProjectsByPath)(workspace, process.cwd(), workspace.basePath);
264
+ if (projectNames.length === 1) {
265
+ return projectNames[0];
266
+ }
267
+ else {
268
+ if (projectNames.length > 1) {
269
+ logger.warn(core_1.tags.oneLine `
270
+ Two or more projects are using identical roots.
271
+ Unable to determine project using current working directory.
272
+ Using default workspace project instead.
273
+ `);
274
+ }
275
+ const defaultProjectName = workspace.extensions['defaultProject'];
276
+ if (typeof defaultProjectName === 'string' && defaultProjectName) {
277
+ return defaultProjectName;
278
+ }
279
+ }
280
+ return undefined;
281
+ }
282
+ getResolvePaths(collectionName) {
283
+ const { workspace, root } = this.context;
284
+ return workspace
285
+ ? // Workspace
286
+ collectionName === DEFAULT_SCHEMATICS_COLLECTION
287
+ ? // Favor __dirname for @schematics/angular to use the build-in version
288
+ [__dirname, process.cwd(), root]
289
+ : [process.cwd(), root, __dirname]
290
+ : // Global
291
+ [__dirname, process.cwd()];
292
+ }
293
+ }
294
+ exports.SchematicsCommandModule = SchematicsCommandModule;
295
+ SchematicsCommandModule.scope = command_module_1.CommandScope.In;