@angular/cli 14.0.0-next.2 → 14.0.0-next.5

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 (211) hide show
  1. package/bin/ng.js +3 -5
  2. package/bin/postinstall/analytics-prompt.js +1 -1
  3. package/lib/cli/index.d.ts +1 -1
  4. package/lib/cli/index.js +16 -18
  5. package/lib/config/schema.json +4 -8
  6. package/lib/init.js +3 -3
  7. package/models/command.d.ts +14 -19
  8. package/models/command.js +13 -106
  9. package/models/interface.d.ts +3 -180
  10. package/models/interface.js +0 -22
  11. package/models/schematic-command.d.ts +6 -18
  12. package/models/schematic-command.js +16 -123
  13. package/package.json +16 -15
  14. package/{models → src/analytics}/analytics-collector.d.ts +0 -0
  15. package/{models → src/analytics}/analytics-collector.js +1 -1
  16. package/{models → src/analytics}/analytics.d.ts +2 -0
  17. package/{models → src/analytics}/analytics.js +33 -2
  18. package/src/command-builder/architect-base-command-module.d.ts +23 -0
  19. package/src/command-builder/architect-base-command-module.js +105 -0
  20. package/src/command-builder/architect-command-module.d.ts +22 -0
  21. package/src/command-builder/architect-command-module.js +110 -0
  22. package/src/command-builder/command-module.d.ts +85 -0
  23. package/src/command-builder/command-module.js +185 -0
  24. package/src/command-builder/command-runner.d.ts +10 -0
  25. package/src/command-builder/command-runner.js +146 -0
  26. package/src/command-builder/schematics-command-module.d.ts +31 -0
  27. package/src/command-builder/schematics-command-module.js +117 -0
  28. package/src/command-builder/utilities/json-help.d.ts +34 -0
  29. package/src/command-builder/utilities/json-help.js +90 -0
  30. package/src/command-builder/utilities/json-schema.d.ts +40 -0
  31. package/{utilities → src/command-builder/utilities}/json-schema.js +20 -121
  32. package/src/commands/add/add-impl.d.ts +22 -0
  33. package/{commands → src/commands/add}/add-impl.js +24 -32
  34. package/src/commands/add/cli.d.ts +23 -0
  35. package/src/commands/add/cli.js +48 -0
  36. package/{commands/add.md → src/commands/add/long-description.md} +0 -0
  37. package/src/commands/analytics/cli.d.ts +21 -0
  38. package/src/commands/analytics/cli.js +70 -0
  39. package/src/commands/analytics/long-description.md +10 -0
  40. package/src/commands/build/cli.d.ts +16 -0
  41. package/src/commands/build/cli.js +23 -0
  42. package/{commands/build-long.md → src/commands/build/long-description.md} +0 -0
  43. package/src/commands/config/cli.d.ts +21 -0
  44. package/src/commands/config/cli.js +46 -0
  45. package/{commands → src/commands/config}/config-impl.d.ts +7 -5
  46. package/{commands → src/commands/config}/config-impl.js +3 -7
  47. package/{commands/config-long.md → src/commands/config/long-description.md} +2 -2
  48. package/src/commands/deploy/cli.d.ts +16 -0
  49. package/src/commands/deploy/cli.js +35 -0
  50. package/{commands/deploy-long.md → src/commands/deploy/long-description.md} +0 -0
  51. package/src/commands/doc/cli.d.ts +23 -0
  52. package/{commands/doc-impl.js → src/commands/doc/cli.js} +36 -11
  53. package/src/commands/e2e/cli.d.ts +17 -0
  54. package/src/commands/e2e/cli.js +34 -0
  55. package/src/commands/extract-i18n/cli.d.ts +15 -0
  56. package/src/commands/extract-i18n/cli.js +20 -0
  57. package/src/commands/generate/cli.d.ts +27 -0
  58. package/src/commands/generate/cli.js +98 -0
  59. package/src/commands/generate/generate-impl.d.ts +19 -0
  60. package/src/commands/generate/generate-impl.js +49 -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 +23 -0
  67. package/src/commands/new/cli.js +36 -0
  68. package/src/commands/new/new-impl.d.ts +18 -0
  69. package/{commands → src/commands/new}/new-impl.js +7 -6
  70. package/src/commands/run/cli.d.ts +23 -0
  71. package/src/commands/run/cli.js +59 -0
  72. package/{commands/run-long.md → src/commands/run/long-description.md} +0 -0
  73. package/src/commands/serve/cli.d.ts +16 -0
  74. package/src/commands/serve/cli.js +21 -0
  75. package/src/commands/test/cli.d.ts +16 -0
  76. package/src/commands/test/cli.js +23 -0
  77. package/{commands/test-long.md → src/commands/test/long-description.md} +0 -0
  78. package/src/commands/update/cli.d.ts +29 -0
  79. package/src/commands/update/cli.js +83 -0
  80. package/{commands/update-long.md → src/commands/update/long-description.md} +0 -0
  81. package/src/commands/update/schematic/index.js +1 -1
  82. package/{commands → src/commands/update}/update-impl.d.ts +8 -6
  83. package/{commands → src/commands/update}/update-impl.js +22 -31
  84. package/src/commands/version/cli.d.ts +19 -0
  85. package/{commands/version-impl.js → src/commands/version/cli.js} +44 -38
  86. package/src/typings.d.ts +2 -2
  87. package/{utilities → src/utilities}/color.d.ts +0 -0
  88. package/{utilities → src/utilities}/color.js +0 -0
  89. package/{utilities → src/utilities}/config.d.ts +1 -1
  90. package/{utilities → src/utilities}/config.js +2 -5
  91. package/{utilities → src/utilities}/find-up.d.ts +0 -0
  92. package/{utilities → src/utilities}/find-up.js +0 -0
  93. package/{utilities → src/utilities}/install-package.d.ts +2 -2
  94. package/{utilities → src/utilities}/install-package.js +1 -1
  95. package/{utilities → src/utilities}/json-file.d.ts +0 -0
  96. package/{utilities → src/utilities}/json-file.js +0 -0
  97. package/{utilities → src/utilities}/log-file.d.ts +0 -0
  98. package/{utilities → src/utilities}/log-file.js +0 -0
  99. package/{utilities → src/utilities}/package-json.d.ts +0 -0
  100. package/{utilities → src/utilities}/package-json.js +0 -0
  101. package/{utilities → src/utilities}/package-manager.d.ts +1 -1
  102. package/{utilities → src/utilities}/package-manager.js +1 -1
  103. package/{utilities → src/utilities}/package-metadata.d.ts +0 -0
  104. package/{utilities → src/utilities}/package-metadata.js +0 -0
  105. package/{utilities → src/utilities}/package-tree.d.ts +0 -0
  106. package/{utilities → src/utilities}/package-tree.js +0 -0
  107. package/{utilities → src/utilities}/project.d.ts +0 -0
  108. package/{utilities → src/utilities}/project.js +0 -0
  109. package/{utilities → src/utilities}/prompt.d.ts +0 -0
  110. package/{utilities → src/utilities}/prompt.js +0 -0
  111. package/{utilities → src/utilities}/spinner.d.ts +0 -0
  112. package/{utilities → src/utilities}/spinner.js +0 -0
  113. package/{utilities → src/utilities}/tty.d.ts +0 -0
  114. package/{utilities → src/utilities}/tty.js +0 -0
  115. package/{models → src/utilities}/version.d.ts +2 -1
  116. package/{models → src/utilities}/version.js +6 -6
  117. package/commands/add-impl.d.ts +0 -21
  118. package/commands/add.d.ts +0 -42
  119. package/commands/add.js +0 -10
  120. package/commands/add.json +0 -54
  121. package/commands/analytics-impl.d.ts +0 -13
  122. package/commands/analytics-impl.js +0 -80
  123. package/commands/analytics-long.md +0 -8
  124. package/commands/analytics.d.ts +0 -46
  125. package/commands/analytics.js +0 -31
  126. package/commands/analytics.json +0 -37
  127. package/commands/build-impl.d.ts +0 -14
  128. package/commands/build-impl.js +0 -21
  129. package/commands/build.d.ts +0 -30
  130. package/commands/build.js +0 -10
  131. package/commands/build.json +0 -16
  132. package/commands/config.d.ts +0 -34
  133. package/commands/config.js +0 -10
  134. package/commands/config.json +0 -43
  135. package/commands/definitions.json +0 -66
  136. package/commands/deploy-impl.d.ts +0 -15
  137. package/commands/deploy-impl.js +0 -36
  138. package/commands/deploy.d.ts +0 -30
  139. package/commands/deploy.js +0 -10
  140. package/commands/deploy.json +0 -34
  141. package/commands/doc-impl.d.ts +0 -13
  142. package/commands/doc.d.ts +0 -39
  143. package/commands/doc.js +0 -14
  144. package/commands/doc.json +0 -46
  145. package/commands/e2e-impl.d.ts +0 -16
  146. package/commands/e2e-impl.js +0 -36
  147. package/commands/e2e-long.md +0 -4
  148. package/commands/e2e.d.ts +0 -29
  149. package/commands/e2e.js +0 -10
  150. package/commands/e2e.json +0 -17
  151. package/commands/easter-egg-impl.d.ts +0 -12
  152. package/commands/easter-egg.d.ts +0 -14
  153. package/commands/easter-egg.js +0 -10
  154. package/commands/easter-egg.json +0 -12
  155. package/commands/extract-i18n-impl.d.ts +0 -14
  156. package/commands/extract-i18n-impl.js +0 -21
  157. package/commands/extract-i18n.d.ts +0 -29
  158. package/commands/extract-i18n.js +0 -10
  159. package/commands/extract-i18n.json +0 -15
  160. package/commands/generate-impl.d.ts +0 -18
  161. package/commands/generate-impl.js +0 -89
  162. package/commands/generate.d.ts +0 -37
  163. package/commands/generate.js +0 -10
  164. package/commands/generate.json +0 -31
  165. package/commands/help-impl.d.ts +0 -12
  166. package/commands/help-impl.js +0 -26
  167. package/commands/help-long.md +0 -7
  168. package/commands/help.d.ts +0 -17
  169. package/commands/help.js +0 -10
  170. package/commands/help.json +0 -13
  171. package/commands/lint-impl.d.ts +0 -16
  172. package/commands/lint-impl.js +0 -69
  173. package/commands/lint.d.ts +0 -29
  174. package/commands/lint.js +0 -10
  175. package/commands/lint.json +0 -36
  176. package/commands/new-impl.d.ts +0 -16
  177. package/commands/new.d.ts +0 -41
  178. package/commands/new.js +0 -10
  179. package/commands/new.json +0 -34
  180. package/commands/new.md +0 -16
  181. package/commands/run-impl.d.ts +0 -13
  182. package/commands/run-impl.js +0 -22
  183. package/commands/run.d.ts +0 -30
  184. package/commands/run.js +0 -10
  185. package/commands/run.json +0 -36
  186. package/commands/serve-impl.d.ts +0 -15
  187. package/commands/serve-impl.js +0 -24
  188. package/commands/serve.d.ts +0 -29
  189. package/commands/serve.js +0 -10
  190. package/commands/serve.json +0 -17
  191. package/commands/test-impl.d.ts +0 -15
  192. package/commands/test-impl.js +0 -22
  193. package/commands/test.d.ts +0 -29
  194. package/commands/test.js +0 -10
  195. package/commands/test.json +0 -17
  196. package/commands/update.d.ts +0 -61
  197. package/commands/update.js +0 -10
  198. package/commands/update.json +0 -78
  199. package/commands/version-impl.d.ts +0 -17
  200. package/commands/version.d.ts +0 -17
  201. package/commands/version.js +0 -10
  202. package/commands/version.json +0 -13
  203. package/commands.json +0 -20
  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/parser.d.ts +0 -39
  209. package/models/parser.js +0 -349
  210. package/utilities/INITIAL_COMMIT_MESSAGE.txt +0 -8
  211. package/utilities/json-schema.d.ts +0 -17
@@ -0,0 +1,85 @@
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 { Option } from './utilities/json-schema';
12
+ export declare type Options<T> = {
13
+ [key in keyof T as CamelCaseKey<key>]: T[key];
14
+ };
15
+ export declare enum CommandScope {
16
+ /** Command can only run inside an Angular workspace. */
17
+ In = 0,
18
+ /** Command can only run outside an Angular workspace. */
19
+ Out = 1,
20
+ /** Command can run inside and outside an Angular workspace. */
21
+ Both = 2
22
+ }
23
+ export interface CommandContext {
24
+ currentDirectory: string;
25
+ root: string;
26
+ workspace?: AngularWorkspace;
27
+ logger: logging.Logger;
28
+ /** Arguments parsed in free-from without parser configuration. */
29
+ args: {
30
+ positional: string[];
31
+ options: {
32
+ help: boolean;
33
+ } & Record<string, unknown>;
34
+ };
35
+ }
36
+ export declare type OtherOptions = Record<string, unknown>;
37
+ export interface CommandModuleImplementation<T extends {} = {}> extends Omit<YargsCommandModule<{}, T>, 'builder' | 'handler'> {
38
+ /** Path used to load the long description for the command in JSON help text. */
39
+ longDescriptionPath?: string;
40
+ /** Object declaring the options the command accepts, or a function accepting and returning a yargs instance. */
41
+ builder(argv: Argv): Promise<Argv<T>> | Argv<T>;
42
+ /** A function which will be passed the parsed argv. */
43
+ run(options: Options<T> & OtherOptions): Promise<number | void> | number | void;
44
+ }
45
+ export interface FullDescribe {
46
+ describe?: string;
47
+ longDescription?: string;
48
+ longDescriptionRelativePath?: string;
49
+ }
50
+ export declare abstract class CommandModule<T extends {} = {}> implements CommandModuleImplementation<T> {
51
+ protected readonly context: CommandContext;
52
+ abstract readonly command: string;
53
+ abstract readonly describe: string | false;
54
+ abstract readonly longDescriptionPath?: string;
55
+ protected shouldReportAnalytics: boolean;
56
+ static scope: CommandScope;
57
+ private readonly optionsWithAnalytics;
58
+ constructor(context: CommandContext);
59
+ /**
60
+ * Description object which contains the long command descroption.
61
+ * This is used to generate JSON help wich is used in AIO.
62
+ *
63
+ * `false` will result in a hidden command.
64
+ */
65
+ get fullDescribe(): FullDescribe | false;
66
+ protected get commandName(): string;
67
+ abstract builder(argv: Argv): Promise<Argv<T>> | Argv<T>;
68
+ abstract run(options: Options<T> & OtherOptions): Promise<number | void> | number | void;
69
+ handler(args: ArgumentsCamelCase<T> & OtherOptions): Promise<void>;
70
+ reportAnalytics(options: (Options<T> & OtherOptions) | OtherOptions, paths?: string[], dimensions?: (boolean | number | string)[]): Promise<void>;
71
+ private _analytics;
72
+ protected getAnalytics(): Promise<analytics.Analytics>;
73
+ /**
74
+ * Adds schema options to a command also this keeps track of options that are required for analytics.
75
+ * **Note:** This method should be called from the command bundler method.
76
+ */
77
+ protected addSchemaOptionsToCommand<T>(localYargs: Argv<T>, options: Option[]): Argv<T>;
78
+ protected getWorkspaceOrThrow(): AngularWorkspace;
79
+ }
80
+ /**
81
+ * Creates an known command module error.
82
+ * This is used so during executation we can filter between known validation error and real non handled errors.
83
+ */
84
+ export declare class CommandModuleError extends Error {
85
+ }
@@ -0,0 +1,185 @@
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
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.CommandModuleError = exports.CommandModule = exports.CommandScope = void 0;
30
+ const core_1 = require("@angular-devkit/core");
31
+ const fs_1 = require("fs");
32
+ const path = __importStar(require("path"));
33
+ const helpers_1 = require("yargs/helpers");
34
+ const analytics_1 = require("../analytics/analytics");
35
+ var CommandScope;
36
+ (function (CommandScope) {
37
+ /** Command can only run inside an Angular workspace. */
38
+ CommandScope[CommandScope["In"] = 0] = "In";
39
+ /** Command can only run outside an Angular workspace. */
40
+ CommandScope[CommandScope["Out"] = 1] = "Out";
41
+ /** Command can run inside and outside an Angular workspace. */
42
+ CommandScope[CommandScope["Both"] = 2] = "Both";
43
+ })(CommandScope = exports.CommandScope || (exports.CommandScope = {}));
44
+ class CommandModule {
45
+ constructor(context) {
46
+ this.context = context;
47
+ this.shouldReportAnalytics = true;
48
+ this.optionsWithAnalytics = new Map();
49
+ }
50
+ /**
51
+ * Description object which contains the long command descroption.
52
+ * This is used to generate JSON help wich is used in AIO.
53
+ *
54
+ * `false` will result in a hidden command.
55
+ */
56
+ get fullDescribe() {
57
+ return this.describe === false
58
+ ? false
59
+ : {
60
+ describe: this.describe,
61
+ ...(this.longDescriptionPath
62
+ ? {
63
+ longDescriptionRelativePath: path
64
+ .relative(path.join(__dirname, '../../../../'), this.longDescriptionPath)
65
+ .replace(/\\/g, path.posix.sep),
66
+ longDescription: (0, fs_1.readFileSync)(this.longDescriptionPath, 'utf8'),
67
+ }
68
+ : {}),
69
+ };
70
+ }
71
+ get commandName() {
72
+ return this.command.split(' ', 1)[0];
73
+ }
74
+ async handler(args) {
75
+ const { _, $0, ...options } = args;
76
+ // Camelize options as yargs will return the object in kebab-case when camel casing is disabled.
77
+ const camelCasedOptions = {};
78
+ for (const [key, value] of Object.entries(options)) {
79
+ camelCasedOptions[helpers_1.Parser.camelCase(key)] = value;
80
+ }
81
+ // Gather and report analytics.
82
+ const analytics = await this.getAnalytics();
83
+ if (this.shouldReportAnalytics) {
84
+ await this.reportAnalytics(camelCasedOptions);
85
+ }
86
+ let exitCode;
87
+ try {
88
+ // Run and time command.
89
+ const startTime = Date.now();
90
+ exitCode = await this.run(camelCasedOptions);
91
+ const endTime = Date.now();
92
+ analytics.timing(this.commandName, 'duration', endTime - startTime);
93
+ await analytics.flush();
94
+ }
95
+ catch (e) {
96
+ if (e instanceof core_1.schema.SchemaValidationException) {
97
+ this.context.logger.fatal(`Error: ${e.message}`);
98
+ exitCode = 1;
99
+ }
100
+ else {
101
+ throw e;
102
+ }
103
+ }
104
+ finally {
105
+ if (typeof exitCode === 'number' && exitCode > 0) {
106
+ process.exitCode = exitCode;
107
+ }
108
+ }
109
+ }
110
+ async reportAnalytics(options, paths = [], dimensions = []) {
111
+ for (const [name, ua] of this.optionsWithAnalytics) {
112
+ const value = options[name];
113
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
114
+ dimensions[ua] = value;
115
+ }
116
+ }
117
+ const analytics = await this.getAnalytics();
118
+ analytics.pageview('/command/' + [this.commandName, ...paths].join('/'), {
119
+ dimensions,
120
+ metrics: [],
121
+ });
122
+ }
123
+ async getAnalytics() {
124
+ if (this._analytics) {
125
+ return this._analytics;
126
+ }
127
+ return (this._analytics = await (0, analytics_1.createAnalytics)(!!this.context.workspace, this.commandName === 'update'));
128
+ }
129
+ /**
130
+ * Adds schema options to a command also this keeps track of options that are required for analytics.
131
+ * **Note:** This method should be called from the command bundler method.
132
+ */
133
+ addSchemaOptionsToCommand(localYargs, options) {
134
+ const workingDir = (0, core_1.normalize)(path.relative(this.context.root, process.cwd()));
135
+ for (const option of options) {
136
+ const { default: defaultVal, positional, deprecated, description, alias, userAnalytics, type, hidden, name, choices, format, } = option;
137
+ const sharedOptions = {
138
+ alias,
139
+ hidden,
140
+ description,
141
+ deprecated,
142
+ choices,
143
+ // This should only be done when `--help` is used otherwise default will override options set in angular.json.
144
+ ...(this.context.args.options.help ? { default: defaultVal } : {}),
145
+ };
146
+ // Special case for schematics
147
+ if (workingDir && format === 'path' && name === 'path' && hidden) {
148
+ sharedOptions.default = workingDir;
149
+ }
150
+ if (positional === undefined) {
151
+ localYargs = localYargs.option(core_1.strings.dasherize(name), {
152
+ type,
153
+ ...sharedOptions,
154
+ });
155
+ }
156
+ else {
157
+ localYargs = localYargs.positional(core_1.strings.dasherize(name), {
158
+ type: type === 'array' || type === 'count' ? 'string' : type,
159
+ ...sharedOptions,
160
+ });
161
+ }
162
+ // Record option of analytics.
163
+ if (userAnalytics !== undefined) {
164
+ this.optionsWithAnalytics.set(name, userAnalytics);
165
+ }
166
+ }
167
+ return localYargs;
168
+ }
169
+ getWorkspaceOrThrow() {
170
+ const { workspace } = this.context;
171
+ if (!workspace) {
172
+ throw new CommandModuleError('A workspace is required for this command.');
173
+ }
174
+ return workspace;
175
+ }
176
+ }
177
+ exports.CommandModule = CommandModule;
178
+ CommandModule.scope = CommandScope.Both;
179
+ /**
180
+ * Creates an known command module error.
181
+ * This is used so during executation we can filter between known validation error and real non handled errors.
182
+ */
183
+ class CommandModuleError extends Error {
184
+ }
185
+ 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,146 @@
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 command_module_1 = require("./command-module");
35
+ const json_help_1 = require("./utilities/json-help");
36
+ const COMMANDS = [
37
+ cli_17.VersionCommandModule,
38
+ cli_6.DocCommandModule,
39
+ cli_11.AwesomeCommandModule,
40
+ cli_4.ConfigCommandModule,
41
+ cli_2.AnalyticsCommandModule,
42
+ cli_1.AddCommandModule,
43
+ cli_9.GenerateCommandModule,
44
+ cli_3.BuildCommandModule,
45
+ cli_7.E2eCommandModule,
46
+ cli_15.TestCommandModule,
47
+ cli_14.ServeCommandModule,
48
+ cli_8.ExtractI18nCommandModule,
49
+ cli_5.DeployCommandModule,
50
+ cli_10.LintCommandModule,
51
+ cli_12.NewCommandModule,
52
+ cli_16.UpdateCommandModule,
53
+ cli_13.RunCommandModule,
54
+ ];
55
+ const yargsParser = helpers_1.Parser;
56
+ async function runCommand(args, logger, workspace) {
57
+ var _a, _b;
58
+ const { $0, _: positional, help = false, jsonHelp = false, ...rest } = yargsParser(args, { boolean: ['help', 'json-help'], alias: { 'collection': 'c' } });
59
+ const context = {
60
+ workspace,
61
+ logger,
62
+ currentDirectory: process.cwd(),
63
+ root: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.basePath) !== null && _a !== void 0 ? _a : process.cwd(),
64
+ args: {
65
+ positional: positional.map((v) => v.toString()),
66
+ options: {
67
+ help,
68
+ ...rest,
69
+ },
70
+ },
71
+ };
72
+ let localYargs = (0, yargs_1.default)(args);
73
+ for (const CommandModule of COMMANDS) {
74
+ if (!jsonHelp) {
75
+ // Skip scope validation when running with '--json-help' since it's easier to generate the output for all commands this way.
76
+ const scope = CommandModule.scope;
77
+ if ((scope === command_module_1.CommandScope.In && !workspace) || (scope === command_module_1.CommandScope.Out && workspace)) {
78
+ continue;
79
+ }
80
+ }
81
+ const commandModule = new CommandModule(context);
82
+ const describe = jsonHelp ? commandModule.fullDescribe : commandModule.describe;
83
+ localYargs = localYargs.command({
84
+ command: commandModule.command,
85
+ aliases: 'aliases' in commandModule ? commandModule.aliases : undefined,
86
+ describe:
87
+ // We cannot add custom fields in help, such as long command description which is used in AIO.
88
+ // Therefore, we get around this by adding a complex object as a string which we later parse when generating the help files.
89
+ describe !== undefined && typeof describe === 'object'
90
+ ? JSON.stringify(describe)
91
+ : describe,
92
+ deprecated: 'deprecated' in commandModule ? commandModule.deprecated : undefined,
93
+ builder: (argv) => commandModule.builder(argv),
94
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
+ handler: (args) => commandModule.handler(args),
96
+ });
97
+ }
98
+ if (jsonHelp) {
99
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
+ localYargs.getInternalMethods().getUsageInstance().help = () => (0, json_help_1.jsonHelpUsage)();
101
+ }
102
+ await localYargs
103
+ .scriptName('ng')
104
+ // https://github.com/yargs/yargs/blob/main/docs/advanced.md#customizing-yargs-parser
105
+ .parserConfiguration({
106
+ 'populate--': true,
107
+ 'unknown-options-as-args': false,
108
+ 'dot-notation': false,
109
+ 'boolean-negation': true,
110
+ 'strip-aliased': true,
111
+ 'strip-dashed': true,
112
+ 'camel-case-expansion': false,
113
+ })
114
+ .option('json-help', {
115
+ describe: 'Show help in JSON format.',
116
+ implies: ['help'],
117
+ hidden: true,
118
+ type: 'boolean',
119
+ })
120
+ .help('help', 'Shows a help message for this command in the console.')
121
+ // A complete list of strings can be found: https://github.com/yargs/yargs/blob/main/locales/en.json
122
+ .updateStrings({
123
+ 'Commands:': color_1.colors.cyan('Commands:'),
124
+ 'Options:': color_1.colors.cyan('Options:'),
125
+ 'Positionals:': color_1.colors.cyan('Arguments:'),
126
+ 'deprecated': color_1.colors.yellow('deprecated'),
127
+ 'deprecated: %s': color_1.colors.yellow('deprecated:') + ' %s',
128
+ 'Did you mean %s?': 'Unknown command. Did you mean %s?',
129
+ })
130
+ .demandCommand()
131
+ .recommendCommands()
132
+ .version(false)
133
+ .showHelpOnFail(false)
134
+ .strict()
135
+ .fail((msg, err) => {
136
+ throw msg
137
+ ? // Validation failed example: `Unknown argument:`
138
+ new command_module_1.CommandModuleError(msg)
139
+ : // Unknown exception, re-throw.
140
+ err;
141
+ })
142
+ .wrap(yargs_1.default.terminalWidth())
143
+ .parseAsync();
144
+ return (_b = process.exitCode) !== null && _b !== void 0 ? _b : 0;
145
+ }
146
+ exports.runCommand = runCommand;
@@ -0,0 +1,31 @@
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 } 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 declare abstract class SchematicsCommandModule extends CommandModule<SchematicsCommandArgs> implements CommandModuleImplementation<SchematicsCommandArgs> {
20
+ static scope: CommandScope;
21
+ protected readonly schematicName: string | undefined;
22
+ builder(argv: Argv): Promise<Argv<SchematicsCommandArgs>>;
23
+ /** Get schematic schema options.*/
24
+ protected getSchematicOptions(collection: Collection<FileSystemCollectionDescription, FileSystemSchematicDescription>, schematicName: string, workflow: NodeWorkflow): Promise<Option[]>;
25
+ protected getCollectionName(): Promise<string>;
26
+ private _workflow;
27
+ protected getOrCreateWorkflow(collectionName: string): NodeWorkflow;
28
+ private _defaultSchematicCollection;
29
+ protected getDefaultSchematicCollection(): Promise<string>;
30
+ protected parseSchematicInfo(schematic: string | undefined): [collectionName: string | undefined, schematicName: string | undefined];
31
+ }
@@ -0,0 +1,117 @@
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.SchematicsCommandModule = void 0;
11
+ const tools_1 = require("@angular-devkit/schematics/tools");
12
+ const schematic_engine_host_1 = require("../../models/schematic-engine-host");
13
+ const config_1 = require("../utilities/config");
14
+ const command_module_1 = require("./command-module");
15
+ const json_schema_1 = require("./utilities/json-schema");
16
+ const DEFAULT_SCHEMATICS_COLLECTION = '@schematics/angular';
17
+ class SchematicsCommandModule extends command_module_1.CommandModule {
18
+ async builder(argv) {
19
+ const localYargs = argv
20
+ .option('interactive', {
21
+ describe: 'Enable interactive input prompts.',
22
+ type: 'boolean',
23
+ default: true,
24
+ })
25
+ .option('dry-run', {
26
+ describe: 'Run through and reports activity without writing out results.',
27
+ type: 'boolean',
28
+ default: false,
29
+ })
30
+ .option('defaults', {
31
+ describe: 'Disable interactive input prompts for options with a default.',
32
+ type: 'boolean',
33
+ default: false,
34
+ })
35
+ .option('force', {
36
+ describe: 'Force overwriting of existing files.',
37
+ type: 'boolean',
38
+ default: false,
39
+ })
40
+ .strict();
41
+ if (this.schematicName) {
42
+ const collectionName = await this.getCollectionName();
43
+ const workflow = this.getOrCreateWorkflow(collectionName);
44
+ const collection = workflow.engine.createCollection(collectionName);
45
+ const options = await this.getSchematicOptions(collection, this.schematicName, workflow);
46
+ return this.addSchemaOptionsToCommand(localYargs, options);
47
+ }
48
+ return localYargs;
49
+ }
50
+ /** Get schematic schema options.*/
51
+ async getSchematicOptions(collection, schematicName, workflow) {
52
+ const schematic = collection.createSchematic(schematicName, true);
53
+ const { schemaJson } = schematic.description;
54
+ if (!schemaJson) {
55
+ return [];
56
+ }
57
+ return (0, json_schema_1.parseJsonSchemaToOptions)(workflow.registry, schemaJson);
58
+ }
59
+ async getCollectionName() {
60
+ var _a, _b;
61
+ const { options: { collection }, positional, } = this.context.args;
62
+ return ((_b = (_a = (typeof collection === 'string' ? collection : undefined)) !== null && _a !== void 0 ? _a :
63
+ // positional = [generate, lint] or [new, collection-package]
64
+ this.parseSchematicInfo(positional[1])[0]) !== null && _b !== void 0 ? _b : (await this.getDefaultSchematicCollection()));
65
+ }
66
+ getOrCreateWorkflow(collectionName) {
67
+ if (this._workflow) {
68
+ return this._workflow;
69
+ }
70
+ const { root, workspace } = this.context;
71
+ return new tools_1.NodeWorkflow(root, {
72
+ resolvePaths: workspace
73
+ ? // Workspace
74
+ collectionName === DEFAULT_SCHEMATICS_COLLECTION
75
+ ? // Favor __dirname for @schematics/angular to use the build-in version
76
+ [__dirname, process.cwd(), root]
77
+ : [process.cwd(), root, __dirname]
78
+ : // Global
79
+ [__dirname, process.cwd()],
80
+ engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
81
+ });
82
+ }
83
+ async getDefaultSchematicCollection() {
84
+ if (this._defaultSchematicCollection) {
85
+ return this._defaultSchematicCollection;
86
+ }
87
+ let workspace = await (0, config_1.getWorkspace)('local');
88
+ if (workspace) {
89
+ const project = (0, config_1.getProjectByCwd)(workspace);
90
+ if (project) {
91
+ const value = workspace.getProjectCli(project)['defaultCollection'];
92
+ if (typeof value == 'string') {
93
+ return (this._defaultSchematicCollection = value);
94
+ }
95
+ }
96
+ const value = workspace.getCli()['defaultCollection'];
97
+ if (typeof value === 'string') {
98
+ return (this._defaultSchematicCollection = value);
99
+ }
100
+ }
101
+ workspace = await (0, config_1.getWorkspace)('global');
102
+ const value = workspace === null || workspace === void 0 ? void 0 : workspace.getCli()['defaultCollection'];
103
+ if (typeof value === 'string') {
104
+ return (this._defaultSchematicCollection = value);
105
+ }
106
+ return (this._defaultSchematicCollection = DEFAULT_SCHEMATICS_COLLECTION);
107
+ }
108
+ parseSchematicInfo(schematic) {
109
+ if (schematic === null || schematic === void 0 ? void 0 : schematic.includes(':')) {
110
+ const [collectionName, schematicName] = schematic.split(':', 2);
111
+ return [collectionName, schematicName];
112
+ }
113
+ return [undefined, schematic];
114
+ }
115
+ }
116
+ exports.SchematicsCommandModule = SchematicsCommandModule;
117
+ SchematicsCommandModule.scope = command_module_1.CommandScope.In;
@@ -0,0 +1,34 @@
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
+ export interface JsonHelp {
9
+ name: string;
10
+ shortDescription?: string;
11
+ command: string;
12
+ longDescription?: string;
13
+ longDescriptionRelativePath?: string;
14
+ options: JsonHelpOption[];
15
+ subcommands?: {
16
+ name: string;
17
+ description: string;
18
+ aliases: string[];
19
+ deprecated: string | boolean;
20
+ }[];
21
+ }
22
+ interface JsonHelpOption {
23
+ name: string;
24
+ type?: string;
25
+ deprecated: boolean | string;
26
+ aliases?: string[];
27
+ default?: string;
28
+ required?: boolean;
29
+ positional?: number;
30
+ enum?: string[];
31
+ description?: string;
32
+ }
33
+ export declare function jsonHelpUsage(): string;
34
+ export {};