@angular/cli 14.0.0-next.1 → 14.0.0-next.12

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 (239) 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 +48 -15
  5. package/lib/config/workspace-schema.d.ts +18 -1
  6. package/lib/init.js +10 -9
  7. package/package.json +21 -23
  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 +306 -0
  12. package/src/command-builder/architect-base-command-module.d.ts +30 -0
  13. package/src/command-builder/architect-base-command-module.js +165 -0
  14. package/src/command-builder/architect-command-module.d.ts +25 -0
  15. package/src/command-builder/architect-command-module.js +134 -0
  16. package/src/command-builder/command-module.d.ts +89 -0
  17. package/src/command-builder/command-module.js +198 -0
  18. package/{utilities/package-json.js → src/command-builder/command-runner.d.ts} +2 -2
  19. package/src/command-builder/command-runner.js +168 -0
  20. package/src/command-builder/schematics-command-module.d.ts +43 -0
  21. package/src/command-builder/schematics-command-module.js +333 -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/src/command-builder/utilities/normalize-options-middleware.d.ts +18 -0
  29. package/src/command-builder/utilities/normalize-options-middleware.js +59 -0
  30. package/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +2 -2
  31. package/{models → src/command-builder/utilities}/schematic-engine-host.js +33 -18
  32. package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
  33. package/src/command-builder/utilities/schematic-workflow.js +68 -0
  34. package/src/commands/add/cli.d.ts +33 -0
  35. package/{commands/add-impl.js → src/commands/add/cli.js} +108 -80
  36. package/src/commands/add/long-description.md +7 -0
  37. package/src/commands/analytics/cli.d.ts +16 -0
  38. package/src/commands/analytics/cli.js +35 -0
  39. package/src/commands/analytics/info/cli.d.ts +16 -0
  40. package/src/commands/analytics/info/cli.js +26 -0
  41. package/src/commands/analytics/settings/cli.d.ts +35 -0
  42. package/src/commands/analytics/settings/cli.js +61 -0
  43. package/src/commands/build/cli.d.ts +16 -0
  44. package/src/commands/build/cli.js +23 -0
  45. package/{commands/build-long.md → src/commands/build/long-description.md} +0 -0
  46. package/src/commands/cache/clean/cli.d.ts +17 -0
  47. package/src/commands/cache/clean/cli.js +32 -0
  48. package/src/commands/cache/cli.d.ts +17 -0
  49. package/src/commands/cache/cli.js +38 -0
  50. package/src/commands/cache/info/cli.d.ts +20 -0
  51. package/src/commands/cache/info/cli.js +82 -0
  52. package/src/commands/cache/long-description.md +53 -0
  53. package/src/commands/cache/settings/cli.d.ts +27 -0
  54. package/src/commands/cache/settings/cli.js +42 -0
  55. package/src/commands/cache/utilities.d.ts +11 -0
  56. package/src/commands/cache/utilities.js +49 -0
  57. package/src/commands/completion/cli.d.ts +16 -0
  58. package/src/commands/completion/cli.js +31 -0
  59. package/src/commands/completion/long-description.md +1 -0
  60. package/src/commands/config/cli.d.ts +24 -0
  61. package/{commands/config-impl.js → src/commands/config/cli.js} +102 -89
  62. package/{commands/config-long.md → src/commands/config/long-description.md} +2 -2
  63. package/src/commands/deploy/cli.d.ts +17 -0
  64. package/src/commands/deploy/cli.js +49 -0
  65. package/{commands/deploy-long.md → src/commands/deploy/long-description.md} +0 -0
  66. package/src/commands/doc/cli.d.ts +23 -0
  67. package/{commands/doc-impl.js → src/commands/doc/cli.js} +41 -12
  68. package/src/commands/e2e/cli.d.ts +18 -0
  69. package/src/commands/e2e/cli.js +35 -0
  70. package/src/commands/extract-i18n/cli.d.ts +15 -0
  71. package/src/commands/extract-i18n/cli.js +20 -0
  72. package/src/commands/generate/cli.d.ts +39 -0
  73. package/src/commands/generate/cli.js +145 -0
  74. package/src/commands/lint/cli.d.ts +17 -0
  75. package/src/commands/lint/cli.js +28 -0
  76. package/{commands/lint-long.md → src/commands/lint/long-description.md} +0 -0
  77. package/src/commands/make-this-awesome/cli.d.ts +17 -0
  78. package/{commands/easter-egg-impl.js → src/commands/make-this-awesome/cli.js} +17 -10
  79. package/src/commands/new/cli.d.ts +27 -0
  80. package/src/commands/new/cli.js +82 -0
  81. package/src/commands/run/cli.d.ts +25 -0
  82. package/src/commands/run/cli.js +83 -0
  83. package/{commands/run-long.md → src/commands/run/long-description.md} +0 -0
  84. package/src/commands/serve/cli.d.ts +16 -0
  85. package/src/commands/serve/cli.js +21 -0
  86. package/src/commands/test/cli.d.ts +16 -0
  87. package/src/commands/test/cli.js +23 -0
  88. package/{commands/test-long.md → src/commands/test/long-description.md} +0 -0
  89. package/{commands/update-impl.d.ts → src/commands/update/cli.d.ts} +26 -9
  90. package/{commands/update-impl.js → src/commands/update/cli.js} +363 -316
  91. package/{commands/update-long.md → src/commands/update/long-description.md} +0 -0
  92. package/src/commands/update/schematic/index.js +33 -20
  93. package/src/commands/version/cli.d.ts +18 -0
  94. package/{commands/version-impl.js → src/commands/version/cli.js} +56 -74
  95. package/src/typings-bazel.d.ts +14 -0
  96. package/src/typings.d.ts +1 -14
  97. package/{utilities → src/utilities}/color.d.ts +0 -0
  98. package/{utilities → src/utilities}/color.js +5 -1
  99. package/{utilities → src/utilities}/config.d.ts +6 -5
  100. package/{utilities → src/utilities}/config.js +33 -19
  101. package/src/utilities/environment-options.d.ts +12 -0
  102. package/src/utilities/environment-options.js +24 -0
  103. package/{utilities → src/utilities}/find-up.d.ts +0 -0
  104. package/{utilities → src/utilities}/find-up.js +5 -1
  105. package/{utilities → src/utilities}/json-file.d.ts +0 -0
  106. package/{utilities → src/utilities}/json-file.js +1 -0
  107. package/{utilities → src/utilities}/log-file.d.ts +0 -0
  108. package/{utilities → src/utilities}/log-file.js +0 -0
  109. package/src/utilities/memoize.d.ts +15 -0
  110. package/src/utilities/memoize.js +69 -0
  111. package/src/utilities/package-manager.d.ts +41 -0
  112. package/src/utilities/package-manager.js +287 -0
  113. package/{utilities → src/utilities}/package-metadata.d.ts +15 -37
  114. package/{utilities → src/utilities}/package-metadata.js +15 -27
  115. package/{utilities → src/utilities}/package-tree.d.ts +2 -2
  116. package/{utilities → src/utilities}/package-tree.js +5 -1
  117. package/{utilities → src/utilities}/project.d.ts +0 -0
  118. package/{utilities → src/utilities}/project.js +5 -1
  119. package/{utilities → src/utilities}/prompt.d.ts +2 -0
  120. package/{utilities → src/utilities}/prompt.js +25 -4
  121. package/{utilities → src/utilities}/spinner.d.ts +0 -0
  122. package/{utilities → src/utilities}/spinner.js +0 -0
  123. package/{utilities → src/utilities}/tty.d.ts +0 -0
  124. package/{utilities → src/utilities}/tty.js +0 -0
  125. package/{models → src/utilities}/version.d.ts +2 -1
  126. package/{models → src/utilities}/version.js +6 -6
  127. package/bin/postinstall/analytics-prompt.js +0 -27
  128. package/bin/postinstall/script.js +0 -16
  129. package/commands/add-impl.d.ts +0 -21
  130. package/commands/add.d.ts +0 -42
  131. package/commands/add.js +0 -10
  132. package/commands/add.json +0 -54
  133. package/commands/add.md +0 -10
  134. package/commands/analytics-impl.d.ts +0 -13
  135. package/commands/analytics-impl.js +0 -80
  136. package/commands/analytics-long.md +0 -8
  137. package/commands/analytics.d.ts +0 -46
  138. package/commands/analytics.js +0 -31
  139. package/commands/analytics.json +0 -37
  140. package/commands/build-impl.d.ts +0 -14
  141. package/commands/build-impl.js +0 -21
  142. package/commands/build.d.ts +0 -30
  143. package/commands/build.js +0 -10
  144. package/commands/build.json +0 -16
  145. package/commands/config-impl.d.ts +0 -15
  146. package/commands/config.d.ts +0 -34
  147. package/commands/config.js +0 -10
  148. package/commands/config.json +0 -43
  149. package/commands/definitions.json +0 -66
  150. package/commands/deploy-impl.d.ts +0 -15
  151. package/commands/deploy-impl.js +0 -36
  152. package/commands/deploy.d.ts +0 -30
  153. package/commands/deploy.js +0 -10
  154. package/commands/deploy.json +0 -34
  155. package/commands/doc-impl.d.ts +0 -13
  156. package/commands/doc.d.ts +0 -39
  157. package/commands/doc.js +0 -14
  158. package/commands/doc.json +0 -46
  159. package/commands/e2e-impl.d.ts +0 -16
  160. package/commands/e2e-impl.js +0 -36
  161. package/commands/e2e-long.md +0 -4
  162. package/commands/e2e.d.ts +0 -29
  163. package/commands/e2e.js +0 -10
  164. package/commands/e2e.json +0 -17
  165. package/commands/easter-egg-impl.d.ts +0 -12
  166. package/commands/easter-egg.d.ts +0 -14
  167. package/commands/easter-egg.js +0 -10
  168. package/commands/easter-egg.json +0 -12
  169. package/commands/extract-i18n-impl.d.ts +0 -14
  170. package/commands/extract-i18n-impl.js +0 -32
  171. package/commands/extract-i18n.d.ts +0 -29
  172. package/commands/extract-i18n.js +0 -10
  173. package/commands/extract-i18n.json +0 -17
  174. package/commands/generate-impl.d.ts +0 -18
  175. package/commands/generate-impl.js +0 -89
  176. package/commands/generate.d.ts +0 -37
  177. package/commands/generate.js +0 -10
  178. package/commands/generate.json +0 -31
  179. package/commands/help-impl.d.ts +0 -12
  180. package/commands/help-impl.js +0 -26
  181. package/commands/help-long.md +0 -7
  182. package/commands/help.d.ts +0 -17
  183. package/commands/help.js +0 -10
  184. package/commands/help.json +0 -13
  185. package/commands/lint-impl.d.ts +0 -16
  186. package/commands/lint-impl.js +0 -69
  187. package/commands/lint.d.ts +0 -29
  188. package/commands/lint.js +0 -10
  189. package/commands/lint.json +0 -36
  190. package/commands/new-impl.d.ts +0 -16
  191. package/commands/new-impl.js +0 -37
  192. package/commands/new.d.ts +0 -41
  193. package/commands/new.js +0 -10
  194. package/commands/new.json +0 -34
  195. package/commands/new.md +0 -16
  196. package/commands/run-impl.d.ts +0 -13
  197. package/commands/run-impl.js +0 -22
  198. package/commands/run.d.ts +0 -30
  199. package/commands/run.js +0 -10
  200. package/commands/run.json +0 -36
  201. package/commands/serve-impl.d.ts +0 -15
  202. package/commands/serve-impl.js +0 -24
  203. package/commands/serve.d.ts +0 -29
  204. package/commands/serve.js +0 -10
  205. package/commands/serve.json +0 -17
  206. package/commands/test-impl.d.ts +0 -15
  207. package/commands/test-impl.js +0 -22
  208. package/commands/test.d.ts +0 -29
  209. package/commands/test.js +0 -10
  210. package/commands/test.json +0 -17
  211. package/commands/update.d.ts +0 -61
  212. package/commands/update.js +0 -10
  213. package/commands/update.json +0 -78
  214. package/commands/version-impl.d.ts +0 -17
  215. package/commands/version.d.ts +0 -17
  216. package/commands/version.js +0 -10
  217. package/commands/version.json +0 -13
  218. package/commands.json +0 -20
  219. package/models/analytics.d.ts +0 -58
  220. package/models/analytics.js +0 -358
  221. package/models/architect-command.d.ts +0 -35
  222. package/models/architect-command.js +0 -364
  223. package/models/command-runner.d.ts +0 -24
  224. package/models/command-runner.js +0 -241
  225. package/models/command.d.ts +0 -34
  226. package/models/command.js +0 -143
  227. package/models/interface.d.ts +0 -196
  228. package/models/interface.js +0 -31
  229. package/models/parser.d.ts +0 -39
  230. package/models/parser.js +0 -349
  231. package/models/schematic-command.d.ts +0 -55
  232. package/models/schematic-command.js +0 -485
  233. package/utilities/INITIAL_COMMIT_MESSAGE.txt +0 -8
  234. package/utilities/install-package.d.ts +0 -16
  235. package/utilities/install-package.js +0 -193
  236. package/utilities/json-schema.d.ts +0 -17
  237. package/utilities/package-json.d.ts +0 -249
  238. package/utilities/package-manager.d.ts +0 -13
  239. package/utilities/package-manager.js +0 -106
@@ -0,0 +1,89 @@
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 { analytics, logging } from '@angular-devkit/core';
9
+ import { ArgumentsCamelCase, Argv, CamelCaseKey, CommandModule as YargsCommandModule } from 'yargs';
10
+ import { AngularWorkspace } from '../utilities/config';
11
+ import { PackageManagerUtils } from '../utilities/package-manager';
12
+ import { Option } from './utilities/json-schema';
13
+ export declare type Options<T> = {
14
+ [key in keyof T as CamelCaseKey<key>]: T[key];
15
+ };
16
+ export declare enum CommandScope {
17
+ /** Command can only run inside an Angular workspace. */
18
+ In = 0,
19
+ /** Command can only run outside an Angular workspace. */
20
+ Out = 1,
21
+ /** Command can run inside and outside an Angular workspace. */
22
+ Both = 2
23
+ }
24
+ export interface CommandContext {
25
+ currentDirectory: string;
26
+ root: string;
27
+ workspace?: AngularWorkspace;
28
+ globalConfiguration?: AngularWorkspace;
29
+ logger: logging.Logger;
30
+ packageManager: PackageManagerUtils;
31
+ /** Arguments parsed in free-from without parser configuration. */
32
+ args: {
33
+ positional: string[];
34
+ options: {
35
+ help: boolean;
36
+ jsonHelp: boolean;
37
+ getYargsCompletions: boolean;
38
+ } & Record<string, unknown>;
39
+ };
40
+ }
41
+ export declare type OtherOptions = Record<string, unknown>;
42
+ export interface CommandModuleImplementation<T extends {} = {}> extends Omit<YargsCommandModule<{}, T>, 'builder' | 'handler'> {
43
+ /** Path used to load the long description for the command in JSON help text. */
44
+ longDescriptionPath?: string;
45
+ /** Object declaring the options the command accepts, or a function accepting and returning a yargs instance. */
46
+ builder(argv: Argv): Promise<Argv<T>> | Argv<T>;
47
+ /** A function which will be passed the parsed argv. */
48
+ run(options: Options<T> & OtherOptions): Promise<number | void> | number | void;
49
+ }
50
+ export interface FullDescribe {
51
+ describe?: string;
52
+ longDescription?: string;
53
+ longDescriptionRelativePath?: string;
54
+ }
55
+ export declare abstract class CommandModule<T extends {} = {}> implements CommandModuleImplementation<T> {
56
+ protected readonly context: CommandContext;
57
+ abstract readonly command: string;
58
+ abstract readonly describe: string | false;
59
+ abstract readonly longDescriptionPath?: string;
60
+ protected readonly shouldReportAnalytics: boolean;
61
+ static scope: CommandScope;
62
+ private readonly optionsWithAnalytics;
63
+ constructor(context: CommandContext);
64
+ /**
65
+ * Description object which contains the long command descroption.
66
+ * This is used to generate JSON help wich is used in AIO.
67
+ *
68
+ * `false` will result in a hidden command.
69
+ */
70
+ get fullDescribe(): FullDescribe | false;
71
+ protected get commandName(): string;
72
+ abstract builder(argv: Argv): Promise<Argv<T>> | Argv<T>;
73
+ abstract run(options: Options<T> & OtherOptions): Promise<number | void> | number | void;
74
+ handler(args: ArgumentsCamelCase<T> & OtherOptions): Promise<void>;
75
+ reportAnalytics(options: (Options<T> & OtherOptions) | OtherOptions, paths?: string[], dimensions?: (boolean | number | string)[]): Promise<void>;
76
+ protected getAnalytics(): Promise<analytics.Analytics>;
77
+ /**
78
+ * Adds schema options to a command also this keeps track of options that are required for analytics.
79
+ * **Note:** This method should be called from the command bundler method.
80
+ */
81
+ protected addSchemaOptionsToCommand<T>(localYargs: Argv<T>, options: Option[]): Argv<T>;
82
+ protected getWorkspaceOrThrow(): AngularWorkspace;
83
+ }
84
+ /**
85
+ * Creates an known command module error.
86
+ * This is used so during executation we can filter between known validation error and real non handled errors.
87
+ */
88
+ export declare class CommandModuleError extends Error {
89
+ }
@@ -0,0 +1,198 @@
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
26
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
27
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
29
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
30
+ };
31
+ var __importStar = (this && this.__importStar) || function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.CommandModuleError = exports.CommandModule = exports.CommandScope = void 0;
40
+ const core_1 = require("@angular-devkit/core");
41
+ const fs_1 = require("fs");
42
+ const path = __importStar(require("path"));
43
+ const helpers_1 = require("yargs/helpers");
44
+ const analytics_1 = require("../analytics/analytics");
45
+ const memoize_1 = require("../utilities/memoize");
46
+ var CommandScope;
47
+ (function (CommandScope) {
48
+ /** Command can only run inside an Angular workspace. */
49
+ CommandScope[CommandScope["In"] = 0] = "In";
50
+ /** Command can only run outside an Angular workspace. */
51
+ CommandScope[CommandScope["Out"] = 1] = "Out";
52
+ /** Command can run inside and outside an Angular workspace. */
53
+ CommandScope[CommandScope["Both"] = 2] = "Both";
54
+ })(CommandScope = exports.CommandScope || (exports.CommandScope = {}));
55
+ class CommandModule {
56
+ constructor(context) {
57
+ this.context = context;
58
+ this.shouldReportAnalytics = true;
59
+ this.optionsWithAnalytics = new Map();
60
+ }
61
+ /**
62
+ * Description object which contains the long command descroption.
63
+ * This is used to generate JSON help wich is used in AIO.
64
+ *
65
+ * `false` will result in a hidden command.
66
+ */
67
+ get fullDescribe() {
68
+ return this.describe === false
69
+ ? false
70
+ : {
71
+ describe: this.describe,
72
+ ...(this.longDescriptionPath
73
+ ? {
74
+ longDescriptionRelativePath: path
75
+ .relative(path.join(__dirname, '../../../../'), this.longDescriptionPath)
76
+ .replace(/\\/g, path.posix.sep),
77
+ longDescription: (0, fs_1.readFileSync)(this.longDescriptionPath, 'utf8').replace(/\r\n/g, '\n'),
78
+ }
79
+ : {}),
80
+ };
81
+ }
82
+ get commandName() {
83
+ return this.command.split(' ', 1)[0];
84
+ }
85
+ async handler(args) {
86
+ const { _, $0, ...options } = args;
87
+ // Camelize options as yargs will return the object in kebab-case when camel casing is disabled.
88
+ const camelCasedOptions = {};
89
+ for (const [key, value] of Object.entries(options)) {
90
+ camelCasedOptions[helpers_1.Parser.camelCase(key)] = value;
91
+ }
92
+ // Gather and report analytics.
93
+ const analytics = await this.getAnalytics();
94
+ if (this.shouldReportAnalytics) {
95
+ await this.reportAnalytics(camelCasedOptions);
96
+ }
97
+ let exitCode;
98
+ try {
99
+ // Run and time command.
100
+ const startTime = Date.now();
101
+ exitCode = await this.run(camelCasedOptions);
102
+ const endTime = Date.now();
103
+ analytics.timing(this.commandName, 'duration', endTime - startTime);
104
+ await analytics.flush();
105
+ }
106
+ catch (e) {
107
+ if (e instanceof core_1.schema.SchemaValidationException) {
108
+ this.context.logger.fatal(`Error: ${e.message}`);
109
+ exitCode = 1;
110
+ }
111
+ else {
112
+ throw e;
113
+ }
114
+ }
115
+ finally {
116
+ if (typeof exitCode === 'number' && exitCode > 0) {
117
+ process.exitCode = exitCode;
118
+ }
119
+ }
120
+ }
121
+ async reportAnalytics(options, paths = [], dimensions = []) {
122
+ for (const [name, ua] of this.optionsWithAnalytics) {
123
+ const value = options[name];
124
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
125
+ dimensions[ua] = value;
126
+ }
127
+ }
128
+ const analytics = await this.getAnalytics();
129
+ analytics.pageview('/command/' + [this.commandName, ...paths].join('/'), {
130
+ dimensions,
131
+ metrics: [],
132
+ });
133
+ }
134
+ getAnalytics() {
135
+ return (0, analytics_1.createAnalytics)(!!this.context.workspace,
136
+ // Don't prompt for `ng update` and `ng analytics` commands.
137
+ ['update', 'analytics'].includes(this.commandName));
138
+ }
139
+ /**
140
+ * Adds schema options to a command also this keeps track of options that are required for analytics.
141
+ * **Note:** This method should be called from the command bundler method.
142
+ */
143
+ addSchemaOptionsToCommand(localYargs, options) {
144
+ const workingDir = (0, core_1.normalize)(path.relative(this.context.root, process.cwd()));
145
+ for (const option of options) {
146
+ const { default: defaultVal, positional, deprecated, description, alias, userAnalytics, type, hidden, name, choices, format, } = option;
147
+ const sharedOptions = {
148
+ alias,
149
+ hidden,
150
+ description,
151
+ deprecated,
152
+ choices,
153
+ // This should only be done when `--help` is used otherwise default will override options set in angular.json.
154
+ ...(this.context.args.options.help ? { default: defaultVal } : {}),
155
+ };
156
+ // Special case for schematics
157
+ if (workingDir && format === 'path' && name === 'path' && hidden) {
158
+ sharedOptions.default = workingDir;
159
+ }
160
+ if (positional === undefined) {
161
+ localYargs = localYargs.option(core_1.strings.dasherize(name), {
162
+ type,
163
+ ...sharedOptions,
164
+ });
165
+ }
166
+ else {
167
+ localYargs = localYargs.positional(core_1.strings.dasherize(name), {
168
+ type: type === 'array' || type === 'count' ? 'string' : type,
169
+ ...sharedOptions,
170
+ });
171
+ }
172
+ // Record option of analytics.
173
+ if (userAnalytics !== undefined) {
174
+ this.optionsWithAnalytics.set(name, userAnalytics);
175
+ }
176
+ }
177
+ return localYargs;
178
+ }
179
+ getWorkspaceOrThrow() {
180
+ const { workspace } = this.context;
181
+ if (!workspace) {
182
+ throw new CommandModuleError('A workspace is required for this command.');
183
+ }
184
+ return workspace;
185
+ }
186
+ }
187
+ CommandModule.scope = CommandScope.Both;
188
+ __decorate([
189
+ memoize_1.memoize
190
+ ], CommandModule.prototype, "getAnalytics", null);
191
+ exports.CommandModule = CommandModule;
192
+ /**
193
+ * Creates an known command module error.
194
+ * This is used so during executation we can filter between known validation error and real non handled errors.
195
+ */
196
+ class CommandModuleError extends Error {
197
+ }
198
+ exports.CommandModuleError = CommandModuleError;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,4 +5,5 @@
6
5
  * Use of this source code is governed by an MIT-style license that can be
7
6
  * found in the LICENSE file at https://angular.io/license
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
8
+ import { logging } from '@angular-devkit/core';
9
+ export declare function runCommand(args: string[], logger: logging.Logger): Promise<number>;
@@ -0,0 +1,168 @@
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/cache/cli");
20
+ const cli_5 = require("../commands/completion/cli");
21
+ const cli_6 = require("../commands/config/cli");
22
+ const cli_7 = require("../commands/deploy/cli");
23
+ const cli_8 = require("../commands/doc/cli");
24
+ const cli_9 = require("../commands/e2e/cli");
25
+ const cli_10 = require("../commands/extract-i18n/cli");
26
+ const cli_11 = require("../commands/generate/cli");
27
+ const cli_12 = require("../commands/lint/cli");
28
+ const cli_13 = require("../commands/make-this-awesome/cli");
29
+ const cli_14 = require("../commands/new/cli");
30
+ const cli_15 = require("../commands/run/cli");
31
+ const cli_16 = require("../commands/serve/cli");
32
+ const cli_17 = require("../commands/test/cli");
33
+ const cli_18 = require("../commands/update/cli");
34
+ const cli_19 = require("../commands/version/cli");
35
+ const color_1 = require("../utilities/color");
36
+ const config_1 = require("../utilities/config");
37
+ const package_manager_1 = require("../utilities/package-manager");
38
+ const command_module_1 = require("./command-module");
39
+ const command_1 = require("./utilities/command");
40
+ const json_help_1 = require("./utilities/json-help");
41
+ const normalize_options_middleware_1 = require("./utilities/normalize-options-middleware");
42
+ const COMMANDS = [
43
+ cli_19.VersionCommandModule,
44
+ cli_8.DocCommandModule,
45
+ cli_13.AwesomeCommandModule,
46
+ cli_6.ConfigCommandModule,
47
+ cli_2.AnalyticsCommandModule,
48
+ cli_1.AddCommandModule,
49
+ cli_11.GenerateCommandModule,
50
+ cli_3.BuildCommandModule,
51
+ cli_9.E2eCommandModule,
52
+ cli_17.TestCommandModule,
53
+ cli_16.ServeCommandModule,
54
+ cli_10.ExtractI18nCommandModule,
55
+ cli_7.DeployCommandModule,
56
+ cli_12.LintCommandModule,
57
+ cli_14.NewCommandModule,
58
+ cli_18.UpdateCommandModule,
59
+ cli_15.RunCommandModule,
60
+ cli_4.CacheCommandModule,
61
+ cli_5.CompletionCommandModule,
62
+ ].sort(); // Will be sorted by class name.
63
+ const yargsParser = helpers_1.Parser;
64
+ async function runCommand(args, logger) {
65
+ var _a, _b;
66
+ const { $0, _, help = false, jsonHelp = false, getYargsCompletions = false, ...rest } = yargsParser(args, {
67
+ boolean: ['help', 'json-help', 'get-yargs-completions'],
68
+ alias: { 'collection': 'c' },
69
+ });
70
+ // When `getYargsCompletions` is true the scriptName 'ng' at index 0 is not removed.
71
+ const positional = getYargsCompletions ? _.slice(1) : _;
72
+ let workspace;
73
+ let globalConfiguration;
74
+ try {
75
+ [workspace, globalConfiguration] = await Promise.all([
76
+ (0, config_1.getWorkspace)('local'),
77
+ (0, config_1.getWorkspace)('global'),
78
+ ]);
79
+ }
80
+ catch (e) {
81
+ logger.fatal(e.message);
82
+ return 1;
83
+ }
84
+ const root = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.basePath) !== null && _a !== void 0 ? _a : process.cwd();
85
+ const context = {
86
+ globalConfiguration,
87
+ workspace,
88
+ logger,
89
+ currentDirectory: process.cwd(),
90
+ root,
91
+ packageManager: new package_manager_1.PackageManagerUtils({ globalConfiguration, workspace, root }),
92
+ args: {
93
+ positional: positional.map((v) => v.toString()),
94
+ options: {
95
+ help,
96
+ jsonHelp,
97
+ getYargsCompletions,
98
+ ...rest,
99
+ },
100
+ },
101
+ };
102
+ let localYargs = (0, yargs_1.default)(args);
103
+ for (const CommandModule of COMMANDS) {
104
+ if (!jsonHelp) {
105
+ // Skip scope validation when running with '--json-help' since it's easier to generate the output for all commands this way.
106
+ const scope = CommandModule.scope;
107
+ if ((scope === command_module_1.CommandScope.In && !workspace) || (scope === command_module_1.CommandScope.Out && workspace)) {
108
+ continue;
109
+ }
110
+ }
111
+ localYargs = (0, command_1.addCommandModuleToYargs)(localYargs, CommandModule, context);
112
+ }
113
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
+ const usageInstance = localYargs.getInternalMethods().getUsageInstance();
115
+ if (jsonHelp) {
116
+ usageInstance.help = () => (0, json_help_1.jsonHelpUsage)();
117
+ }
118
+ if (getYargsCompletions) {
119
+ // When in auto completion mode avoid printing description as it causes a slugish
120
+ // experience when there are a large set of options.
121
+ usageInstance.getDescriptions = () => ({});
122
+ }
123
+ await localYargs
124
+ .scriptName('ng')
125
+ // https://github.com/yargs/yargs/blob/main/docs/advanced.md#customizing-yargs-parser
126
+ .parserConfiguration({
127
+ 'populate--': true,
128
+ 'unknown-options-as-args': false,
129
+ 'dot-notation': false,
130
+ 'boolean-negation': true,
131
+ 'strip-aliased': true,
132
+ 'strip-dashed': true,
133
+ 'camel-case-expansion': false,
134
+ })
135
+ .option('json-help', {
136
+ describe: 'Show help in JSON format.',
137
+ implies: ['help'],
138
+ hidden: true,
139
+ type: 'boolean',
140
+ })
141
+ .help('help', 'Shows a help message for this command in the console.')
142
+ // A complete list of strings can be found: https://github.com/yargs/yargs/blob/main/locales/en.json
143
+ .updateStrings({
144
+ 'Commands:': color_1.colors.cyan('Commands:'),
145
+ 'Options:': color_1.colors.cyan('Options:'),
146
+ 'Positionals:': color_1.colors.cyan('Arguments:'),
147
+ 'deprecated': color_1.colors.yellow('deprecated'),
148
+ 'deprecated: %s': color_1.colors.yellow('deprecated:') + ' %s',
149
+ 'Did you mean %s?': 'Unknown command. Did you mean %s?',
150
+ })
151
+ .demandCommand(1, command_1.demandCommandFailureMessage)
152
+ .recommendCommands()
153
+ .middleware(normalize_options_middleware_1.normalizeOptionsMiddleware)
154
+ .version(false)
155
+ .showHelpOnFail(false)
156
+ .strict()
157
+ .fail((msg, err) => {
158
+ throw msg
159
+ ? // Validation failed example: `Unknown argument:`
160
+ new command_module_1.CommandModuleError(msg)
161
+ : // Unknown exception, re-throw.
162
+ err;
163
+ })
164
+ .wrap(yargs_1.default.terminalWidth())
165
+ .parseAsync();
166
+ return (_b = process.exitCode) !== null && _b !== void 0 ? _b : 0;
167
+ }
168
+ exports.runCommand = runCommand;
@@ -0,0 +1,43 @@
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 declare const DEFAULT_SCHEMATICS_COLLECTION = "@schematics/angular";
14
+ export interface SchematicsCommandArgs {
15
+ interactive: boolean;
16
+ force: boolean;
17
+ 'dry-run': boolean;
18
+ defaults: boolean;
19
+ }
20
+ export interface SchematicsExecutionOptions extends Options<SchematicsCommandArgs> {
21
+ packageRegistry?: string;
22
+ }
23
+ export declare abstract class SchematicsCommandModule extends CommandModule<SchematicsCommandArgs> implements CommandModuleImplementation<SchematicsCommandArgs> {
24
+ static scope: CommandScope;
25
+ protected readonly allowPrivateSchematics: boolean;
26
+ protected readonly shouldReportAnalytics = false;
27
+ builder(argv: Argv): Promise<Argv<SchematicsCommandArgs>>;
28
+ /** Get schematic schema options.*/
29
+ protected getSchematicOptions(collection: Collection<FileSystemCollectionDescription, FileSystemSchematicDescription>, schematicName: string, workflow: NodeWorkflow): Promise<Option[]>;
30
+ protected getOrCreateWorkflowForBuilder(collectionName: string): NodeWorkflow;
31
+ protected getOrCreateWorkflowForExecution(collectionName: string, options: SchematicsExecutionOptions): Promise<NodeWorkflow>;
32
+ protected getSchematicCollections(): Promise<Set<string>>;
33
+ protected parseSchematicInfo(schematic: string | undefined): [collectionName: string | undefined, schematicName: string | undefined];
34
+ protected runSchematic(options: {
35
+ executionOptions: SchematicsExecutionOptions;
36
+ schematicOptions: OtherOptions;
37
+ collectionName: string;
38
+ schematicName: string;
39
+ }): Promise<number>;
40
+ private defaultProjectDeprecationWarningShown;
41
+ private getProjectName;
42
+ private getResolvePaths;
43
+ }