@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
package/bin/ng.js CHANGED
@@ -36,19 +36,17 @@ if (version[0] % 2 === 1 && version[0] > 16) {
36
36
 
37
37
  require('./bootstrap');
38
38
  } else if (
39
- version[0] < 12 ||
40
- version[0] === 13 ||
39
+ version[0] < 14 ||
41
40
  version[0] === 15 ||
42
- (version[0] === 12 && version[1] < 20) ||
43
41
  (version[0] === 14 && version[1] < 15) ||
44
42
  (version[0] === 16 && version[1] < 10)
45
43
  ) {
46
- // Error and exit if less than 12.20 or 13.x or less than 14.15 or 15.x or less than 16.10
44
+ // Error and exit if less than 14.15 or 15.x or less than 16.10
47
45
  console.error(
48
46
  'Node.js version ' +
49
47
  process.version +
50
48
  ' detected.\n' +
51
- 'The Angular CLI requires a minimum Node.js version of either v12.20, v14.15, or v16.10.\n\n' +
49
+ 'The Angular CLI requires a minimum Node.js version of either v14.15, or v16.10.\n\n' +
52
50
  'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
53
51
  );
54
52
 
@@ -14,7 +14,7 @@ if ('NG_CLI_ANALYTICS' in process.env) {
14
14
  }
15
15
 
16
16
  try {
17
- var analytics = require('../../models/analytics');
17
+ var analytics = require('../../src/analytics/analytics');
18
18
 
19
19
  analytics
20
20
  .hasGlobalAnalyticsConfiguration()
@@ -5,7 +5,7 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- export { VERSION, Version } from '../../models/version';
8
+ export { VERSION } from '../../src/utilities/version';
9
9
  export default function (options: {
10
10
  testing?: boolean;
11
11
  cliArgs: string[];
package/lib/cli/index.js CHANGED
@@ -7,26 +7,26 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Version = exports.VERSION = void 0;
10
+ exports.VERSION = void 0;
11
11
  const node_1 = require("@angular-devkit/core/node");
12
12
  const util_1 = require("util");
13
- const command_runner_1 = require("../../models/command-runner");
14
- const color_1 = require("../../utilities/color");
15
- const config_1 = require("../../utilities/config");
16
- const log_file_1 = require("../../utilities/log-file");
17
- const project_1 = require("../../utilities/project");
18
- var version_1 = require("../../models/version");
13
+ const command_module_1 = require("../../src/command-builder/command-module");
14
+ const command_runner_1 = require("../../src/command-builder/command-runner");
15
+ const color_1 = require("../../src/utilities/color");
16
+ const config_1 = require("../../src/utilities/config");
17
+ const log_file_1 = require("../../src/utilities/log-file");
18
+ const project_1 = require("../../src/utilities/project");
19
+ var version_1 = require("../../src/utilities/version");
19
20
  Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
20
- Object.defineProperty(exports, "Version", { enumerable: true, get: function () { return version_1.Version; } });
21
21
  const debugEnv = process.env['NG_DEBUG'];
22
22
  const isDebug = debugEnv !== undefined && debugEnv !== '0' && debugEnv.toLowerCase() !== 'false';
23
23
  /* eslint-disable no-console */
24
24
  async function default_1(options) {
25
25
  // This node version check ensures that the requirements of the project instance of the CLI are met
26
- const version = process.versions.node.split('.').map((part) => Number(part));
27
- if (version[0] < 12 || (version[0] === 12 && version[1] < 20)) {
26
+ const [major, minor] = process.versions.node.split('.').map((part) => Number(part));
27
+ if (major < 14 || (major === 14 && minor < 15)) {
28
28
  process.stderr.write(`Node.js version ${process.version} detected.\n` +
29
- 'The Angular CLI requires a minimum v12.20.\n\n' +
29
+ 'The Angular CLI requires a minimum v14.15.\n\n' +
30
30
  'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n');
31
31
  return 3;
32
32
  }
@@ -67,15 +67,13 @@ async function default_1(options) {
67
67
  }
68
68
  }
69
69
  try {
70
- const maybeExitCode = await (0, command_runner_1.runCommand)(options.cliArgs, logger, workspace);
71
- if (typeof maybeExitCode === 'number') {
72
- console.assert(Number.isInteger(maybeExitCode));
73
- return maybeExitCode;
74
- }
75
- return 0;
70
+ return await (0, command_runner_1.runCommand)(options.cliArgs, logger, workspace);
76
71
  }
77
72
  catch (err) {
78
- if (err instanceof Error) {
73
+ if (err instanceof command_module_1.CommandModuleError) {
74
+ logger.fatal(`Error: ${err.message}`);
75
+ }
76
+ else if (err instanceof Error) {
79
77
  try {
80
78
  const logPath = (0, log_file_1.writeErrorToLogFile)(err);
81
79
  logger.fatal(`An unhandled exception occurred: ${err.message}\n` +
@@ -741,8 +741,7 @@
741
741
  },
742
742
  "type": {
743
743
  "type": "string",
744
- "description": "Adds a developer-defined type to the filename, in the format \"name.type.ts\".",
745
- "default": ""
744
+ "description": "Adds a developer-defined type to the filename, in the format \"name.type.ts\"."
746
745
  }
747
746
  }
748
747
  },
@@ -1129,7 +1128,6 @@
1129
1128
  },
1130
1129
  "prefix": {
1131
1130
  "type": "string",
1132
- "default": "",
1133
1131
  "description": "A prefix to apply to generated selectors."
1134
1132
  },
1135
1133
  "type": {
@@ -1751,12 +1749,11 @@
1751
1749
  },
1752
1750
  "outputPath": {
1753
1751
  "type": "string",
1754
- "description": "The full path for the new output directory, relative to the current workspace.\n\nBy default, writes output to a folder named dist/ in the current project."
1752
+ "description": "The full path for the new output directory, relative to the current workspace.\nBy default, writes output to a folder named dist/ in the current project."
1755
1753
  },
1756
1754
  "resourcesOutputPath": {
1757
1755
  "type": "string",
1758
- "description": "The path where style resources will be placed, relative to outputPath.",
1759
- "default": ""
1756
+ "description": "The path where style resources will be placed, relative to outputPath."
1760
1757
  },
1761
1758
  "aot": {
1762
1759
  "type": "boolean",
@@ -2664,8 +2661,7 @@
2664
2661
  },
2665
2662
  "resourcesOutputPath": {
2666
2663
  "type": "string",
2667
- "description": "The path where style resources will be placed, relative to outputPath.",
2668
- "default": ""
2664
+ "description": "The path where style resources will be placed, relative to outputPath."
2669
2665
  },
2670
2666
  "sourceMap": {
2671
2667
  "description": "Output source maps for scripts and styles. For more information, see https://angular.io/guide/workspace-config#source-map-configuration.",
package/lib/init.js CHANGED
@@ -31,9 +31,9 @@ require("symbol-observable");
31
31
  const fs_1 = require("fs");
32
32
  const path = __importStar(require("path"));
33
33
  const semver_1 = require("semver");
34
- const version_1 = require("../models/version");
35
- const color_1 = require("../utilities/color");
36
- const config_1 = require("../utilities/config");
34
+ const color_1 = require("../src/utilities/color");
35
+ const config_1 = require("../src/utilities/config");
36
+ const version_1 = require("../src/utilities/version");
37
37
  (async () => {
38
38
  var _a;
39
39
  /**
@@ -6,29 +6,24 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import { analytics, logging } from '@angular-devkit/core';
9
- import { AngularWorkspace } from '../utilities/config';
10
- import { Arguments, CommandContext, CommandDescription, CommandDescriptionMap, CommandScope, Option } from './interface';
9
+ import { Option } from '../src/command-builder/utilities/json-schema';
10
+ import { AngularWorkspace } from '../src/utilities/config';
11
+ import { CommandContext } from './interface';
11
12
  export interface BaseCommandOptions {
12
- help?: boolean | string;
13
+ jsonHelp?: boolean;
13
14
  }
14
- export declare abstract class Command<T extends BaseCommandOptions = BaseCommandOptions> {
15
+ export declare abstract class Command<T = {}> {
15
16
  protected readonly context: CommandContext;
16
- readonly description: CommandDescription;
17
- protected readonly logger: logging.Logger;
17
+ protected readonly commandName: string;
18
18
  protected allowMissingWorkspace: boolean;
19
19
  protected useReportAnalytics: boolean;
20
20
  readonly workspace?: AngularWorkspace;
21
- readonly analytics: analytics.Analytics;
22
- protected static commandMap: () => Promise<CommandDescriptionMap>;
23
- static setCommandMap(map: () => Promise<CommandDescriptionMap>): void;
24
- constructor(context: CommandContext, description: CommandDescription, logger: logging.Logger);
25
- initialize(options: T & Arguments): Promise<number | void>;
26
- printHelp(): Promise<number>;
27
- printJsonHelp(): Promise<number>;
28
- protected printHelpUsage(): Promise<void>;
29
- protected printHelpOptions(options?: Option[]): Promise<void>;
30
- validateScope(scope?: CommandScope): Promise<void>;
31
- reportAnalytics(paths: string[], options: Arguments, dimensions?: (boolean | number | string)[], metrics?: (boolean | number | string)[]): Promise<void>;
32
- abstract run(options: T & Arguments): Promise<number | void>;
33
- validateAndRun(options: T & Arguments): Promise<number | void>;
21
+ protected readonly analytics: analytics.Analytics;
22
+ protected readonly commandOptions: Option[];
23
+ protected readonly logger: logging.Logger;
24
+ constructor(context: CommandContext, commandName: string);
25
+ initialize(options: T): Promise<number | void>;
26
+ reportAnalytics(paths: string[], options: T, dimensions?: (boolean | number | string)[], metrics?: (boolean | number | string)[]): Promise<void>;
27
+ abstract run(options: T): Promise<number | void>;
28
+ validateAndRun(options: T): Promise<number | void>;
34
29
  }
package/models/command.js CHANGED
@@ -9,104 +9,22 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.Command = void 0;
11
11
  const core_1 = require("@angular-devkit/core");
12
- const color_1 = require("../utilities/color");
13
- const interface_1 = require("./interface");
14
12
  class Command {
15
- constructor(context, description, logger) {
13
+ constructor(context, commandName) {
16
14
  this.context = context;
17
- this.description = description;
18
- this.logger = logger;
15
+ this.commandName = commandName;
19
16
  this.allowMissingWorkspace = false;
20
17
  this.useReportAnalytics = true;
18
+ this.commandOptions = [];
21
19
  this.workspace = context.workspace;
20
+ this.logger = context.logger;
22
21
  this.analytics = context.analytics || new core_1.analytics.NoopAnalytics();
23
22
  }
24
- static setCommandMap(map) {
25
- this.commandMap = map;
26
- }
27
23
  async initialize(options) { }
28
- async printHelp() {
29
- await this.printHelpUsage();
30
- await this.printHelpOptions();
31
- return 0;
32
- }
33
- async printJsonHelp() {
34
- const replacer = (key, value) => key === 'name' ? core_1.strings.dasherize(value) : value;
35
- this.logger.info(JSON.stringify(this.description, replacer, 2));
36
- return 0;
37
- }
38
- async printHelpUsage() {
39
- this.logger.info(this.description.description);
40
- const name = this.description.name;
41
- const args = this.description.options.filter((x) => x.positional !== undefined);
42
- const opts = this.description.options.filter((x) => x.positional === undefined);
43
- const argDisplay = args && args.length > 0 ? ' ' + args.map((a) => `<${a.name}>`).join(' ') : '';
44
- const optionsDisplay = opts && opts.length > 0 ? ` [options]` : ``;
45
- this.logger.info(`usage: ng ${name}${argDisplay}${optionsDisplay}`);
46
- this.logger.info('');
47
- }
48
- async printHelpOptions(options = this.description.options) {
49
- const args = options.filter((opt) => opt.positional !== undefined);
50
- const opts = options.filter((opt) => opt.positional === undefined);
51
- const formatDescription = (description) => ` ${description.replace(/\n/g, '\n ')}`;
52
- if (args.length > 0) {
53
- this.logger.info(`arguments:`);
54
- args.forEach((o) => {
55
- this.logger.info(` ${color_1.colors.cyan(o.name)}`);
56
- if (o.description) {
57
- this.logger.info(formatDescription(o.description));
58
- }
59
- });
60
- }
61
- if (options.length > 0) {
62
- if (args.length > 0) {
63
- this.logger.info('');
64
- }
65
- this.logger.info(`options:`);
66
- opts
67
- .filter((o) => !o.hidden)
68
- .sort((a, b) => a.name.localeCompare(b.name))
69
- .forEach((o) => {
70
- const aliases = o.aliases && o.aliases.length > 0
71
- ? '(' + o.aliases.map((a) => `-${a}`).join(' ') + ')'
72
- : '';
73
- this.logger.info(` ${color_1.colors.cyan('--' + core_1.strings.dasherize(o.name))} ${aliases}`);
74
- if (o.description) {
75
- this.logger.info(formatDescription(o.description));
76
- }
77
- });
78
- }
79
- }
80
- async validateScope(scope) {
81
- switch (scope === undefined ? this.description.scope : scope) {
82
- case interface_1.CommandScope.OutProject:
83
- if (this.workspace) {
84
- this.logger.fatal(core_1.tags.oneLine `
85
- The ${this.description.name} command requires to be run outside of a project, but a
86
- project definition was found at "${this.workspace.filePath}".
87
- `);
88
- // eslint-disable-next-line no-throw-literal
89
- throw 1;
90
- }
91
- break;
92
- case interface_1.CommandScope.InProject:
93
- if (!this.workspace) {
94
- this.logger.fatal(core_1.tags.oneLine `
95
- The ${this.description.name} command requires to be run in an Angular project, but a
96
- project definition could not be found.
97
- `);
98
- // eslint-disable-next-line no-throw-literal
99
- throw 1;
100
- }
101
- break;
102
- case interface_1.CommandScope.Everywhere:
103
- // Can't miss this.
104
- break;
105
- }
106
- }
107
24
  async reportAnalytics(paths, options, dimensions = [], metrics = []) {
108
- for (const option of this.description.options) {
25
+ for (const option of this.commandOptions) {
109
26
  const ua = option.userAnalytics;
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
28
  const v = options[option.name];
111
29
  if (v !== undefined && !Array.isArray(v) && ua) {
112
30
  dimensions[ua] = v;
@@ -115,29 +33,18 @@ class Command {
115
33
  this.analytics.pageview('/command/' + paths.join('/'), { dimensions, metrics });
116
34
  }
117
35
  async validateAndRun(options) {
118
- if (!(options.help === true || options.help === 'json' || options.help === 'JSON')) {
119
- await this.validateScope();
120
- }
121
36
  let result = await this.initialize(options);
122
37
  if (typeof result === 'number' && result !== 0) {
123
38
  return result;
124
39
  }
125
- if (options.help === true) {
126
- return this.printHelp();
127
- }
128
- else if (options.help === 'json' || options.help === 'JSON') {
129
- return this.printJsonHelp();
130
- }
131
- else {
132
- const startTime = +new Date();
133
- if (this.useReportAnalytics) {
134
- await this.reportAnalytics([this.description.name], options);
135
- }
136
- result = await this.run(options);
137
- const endTime = +new Date();
138
- this.analytics.timing(this.description.name, 'duration', endTime - startTime);
139
- return result;
40
+ const startTime = +new Date();
41
+ if (this.useReportAnalytics) {
42
+ await this.reportAnalytics([this.commandName], options);
140
43
  }
44
+ result = await this.run(options);
45
+ const endTime = +new Date();
46
+ this.analytics.timing(this.commandName, 'duration', endTime - startTime);
47
+ return result;
141
48
  }
142
49
  }
143
50
  exports.Command = Command;
@@ -5,36 +5,8 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { analytics, json, logging } from '@angular-devkit/core';
9
- import { AngularWorkspace } from '../utilities/config';
10
- /**
11
- * Value type of arguments.
12
- */
13
- export declare type Value = number | string | boolean | (number | string | boolean)[];
14
- /**
15
- * An object representing parsed arguments from the command line.
16
- */
17
- export interface Arguments {
18
- [argName: string]: Value | undefined;
19
- /**
20
- * Extra arguments that were not parsed. Will be omitted if all arguments were parsed.
21
- */
22
- '--'?: string[];
23
- }
24
- /**
25
- * The base interface for Command, understood by the command runner.
26
- */
27
- export interface CommandInterface<T extends Arguments = Arguments> {
28
- printHelp(options: T): Promise<number>;
29
- printJsonHelp(options: T): Promise<number>;
30
- validateAndRun(options: T): Promise<number>;
31
- }
32
- /**
33
- * Command constructor.
34
- */
35
- export interface CommandConstructor {
36
- new (context: CommandContext, description: CommandDescription, logger: logging.Logger): CommandInterface;
37
- }
8
+ import { analytics, logging } from '@angular-devkit/core';
9
+ import { AngularWorkspace } from '../src/utilities/config';
38
10
  /**
39
11
  * A command runner context.
40
12
  */
@@ -43,154 +15,5 @@ export interface CommandContext {
43
15
  root: string;
44
16
  workspace?: AngularWorkspace;
45
17
  analytics?: analytics.Analytics;
46
- }
47
- /**
48
- * Value types of an Option.
49
- */
50
- export declare enum OptionType {
51
- Any = "any",
52
- Array = "array",
53
- Boolean = "boolean",
54
- Number = "number",
55
- String = "string"
56
- }
57
- /**
58
- * An option description. This is exposed when using `ng --help=json`.
59
- */
60
- export interface Option {
61
- /**
62
- * The name of the option.
63
- */
64
- name: string;
65
- /**
66
- * A short description of the option.
67
- */
68
- description: string;
69
- /**
70
- * The type of option value. If multiple types exist, this type will be the first one, and the
71
- * types array will contain all types accepted.
72
- */
73
- type: OptionType;
74
- /**
75
- * {@see type}
76
- */
77
- types?: OptionType[];
78
- /**
79
- * If this field is set, only values contained in this field are valid. This array can be mixed
80
- * types (strings, numbers, boolean). For example, if this field is "enum: ['hello', true]",
81
- * then "type" will be either string or boolean, types will be at least both, and the values
82
- * accepted will only be either 'hello' or true (not false or any other string).
83
- * This mean that prefixing with `no-` will not work on this field.
84
- */
85
- enum?: Value[];
86
- /**
87
- * If this option maps to a subcommand in the parent command, will contain all the subcommands
88
- * supported. There is a maximum of 1 subcommand Option per command, and the type of this
89
- * option will always be "string" (no other types). The value of this option will map into
90
- * this map and return the extra information.
91
- */
92
- subcommands?: {
93
- [name: string]: SubCommandDescription;
94
- };
95
- /**
96
- * Aliases supported by this option.
97
- */
98
- aliases: string[];
99
- /**
100
- * Whether this option is required or not.
101
- */
102
- required?: boolean;
103
- /**
104
- * Format field of this option.
105
- */
106
- format?: string;
107
- /**
108
- * Whether this option should be hidden from the help output. It will still show up in JSON help.
109
- */
110
- hidden?: boolean;
111
- /**
112
- * Default value of this option.
113
- */
114
- default?: string | number | boolean;
115
- /**
116
- * If this option can be used as an argument, the position of the argument. Otherwise omitted.
117
- */
118
- positional?: number;
119
- /**
120
- * Smart default object.
121
- */
122
- $default?: OptionSmartDefault;
123
- /**
124
- * Whether or not to report this option to the Angular Team, and which custom field to use.
125
- * If this is falsey, do not report this option.
126
- */
127
- userAnalytics?: number;
128
- /**
129
- * Deprecation. If this flag is not false a warning will be shown on the console. Either `true`
130
- * or a string to show the user as a notice.
131
- */
132
- deprecated?: boolean | string;
133
- }
134
- /**
135
- * Scope of the command.
136
- */
137
- export declare enum CommandScope {
138
- InProject = "in",
139
- OutProject = "out",
140
- Everywhere = "all",
141
- Default = "in"
142
- }
143
- /**
144
- * A description of a command and its options.
145
- */
146
- export interface SubCommandDescription {
147
- /**
148
- * The name of the subcommand.
149
- */
150
- name: string;
151
- /**
152
- * Short description (1-2 lines) of this sub command.
153
- */
154
- description: string;
155
- /**
156
- * A long description of the sub command, in Markdown format.
157
- */
158
- longDescription?: string;
159
- /**
160
- * Additional notes about usage of this sub command, in Markdown format.
161
- */
162
- usageNotes?: string;
163
- /**
164
- * List of all supported options.
165
- */
166
- options: Option[];
167
- /**
168
- * Aliases supported for this sub command.
169
- */
170
- aliases: string[];
171
- }
172
- /**
173
- * A description of a command, its metadata.
174
- */
175
- export interface CommandDescription extends SubCommandDescription {
176
- /**
177
- * Scope of the command, whether it can be executed in a project, outside of a project or
178
- * anywhere.
179
- */
180
- scope: CommandScope;
181
- /**
182
- * Whether this command should be hidden from a list of all commands.
183
- */
184
- hidden: boolean;
185
- /**
186
- * The constructor of the command, which should be extending the abstract Command<> class.
187
- */
188
- impl: CommandConstructor;
189
- }
190
- export interface OptionSmartDefault {
191
- $source: string;
192
- [key: string]: json.JsonValue;
193
- }
194
- export interface CommandDescriptionMap {
195
- [key: string]: CommandDescription;
18
+ logger: logging.Logger;
196
19
  }
@@ -7,25 +7,3 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.CommandScope = exports.OptionType = void 0;
11
- /**
12
- * Value types of an Option.
13
- */
14
- var OptionType;
15
- (function (OptionType) {
16
- OptionType["Any"] = "any";
17
- OptionType["Array"] = "array";
18
- OptionType["Boolean"] = "boolean";
19
- OptionType["Number"] = "number";
20
- OptionType["String"] = "string";
21
- })(OptionType = exports.OptionType || (exports.OptionType = {}));
22
- /**
23
- * Scope of the command.
24
- */
25
- var CommandScope;
26
- (function (CommandScope) {
27
- CommandScope["InProject"] = "in";
28
- CommandScope["OutProject"] = "out";
29
- CommandScope["Everywhere"] = "all";
30
- CommandScope["Default"] = "in";
31
- })(CommandScope = exports.CommandScope || (exports.CommandScope = {}));
@@ -5,26 +5,21 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { logging } from '@angular-devkit/core';
9
- import { workflow } from '@angular-devkit/schematics';
10
8
  import { FileSystemCollection, FileSystemEngine, FileSystemSchematic, NodeWorkflow } from '@angular-devkit/schematics/tools';
11
9
  import { BaseCommandOptions, Command } from './command';
12
- import { Arguments, CommandContext, CommandDescription, Option } from './interface';
10
+ import { CommandContext } from './interface';
13
11
  export interface BaseSchematicSchema {
14
12
  debug?: boolean;
15
13
  dryRun?: boolean;
16
14
  force?: boolean;
17
15
  interactive?: boolean;
18
16
  defaults?: boolean;
19
- packageRegistry?: string;
17
+ registry?: string;
20
18
  }
21
19
  export interface RunSchematicOptions extends BaseSchematicSchema {
22
20
  collectionName: string;
23
21
  schematicName: string;
24
- additionalOptions?: {
25
- [key: string]: {};
26
- };
27
- schematicOptions?: string[];
22
+ schematicOptions?: Record<string, unknown>;
28
23
  showNothingDone?: boolean;
29
24
  }
30
25
  export declare class UnknownCollectionError extends Error {
@@ -37,19 +32,12 @@ export declare abstract class SchematicCommand<T extends BaseSchematicSchema & B
37
32
  protected defaultCollectionName: string;
38
33
  protected collectionName: string;
39
34
  protected schematicName?: string;
40
- constructor(context: CommandContext, description: CommandDescription, logger: logging.Logger);
41
- initialize(options: T & Arguments): Promise<void>;
42
- printHelp(): Promise<number>;
43
- printHelpUsage(): Promise<void>;
35
+ constructor(context: CommandContext, commandName: string);
36
+ initialize(options: T): Promise<void>;
44
37
  protected getEngine(): FileSystemEngine;
45
38
  protected getCollection(collectionName: string): FileSystemCollection;
46
39
  protected getSchematic(collection: FileSystemCollection, schematicName: string, allowPrivate?: boolean): FileSystemSchematic;
47
- protected setPathOptions(options: Option[], workingDir: string): {
48
- [name: string]: string;
49
- };
50
- protected createWorkflow(options: BaseSchematicSchema): Promise<workflow.BaseWorkflow>;
40
+ protected createWorkflow(options: BaseSchematicSchema): Promise<NodeWorkflow>;
51
41
  protected getDefaultSchematicCollection(): Promise<string>;
52
42
  protected runSchematic(options: RunSchematicOptions): Promise<number | void>;
53
- protected parseFreeFormArguments(schematicOptions: string[]): Promise<Arguments>;
54
- protected parseArguments(schematicOptions: string[], options: Option[] | null): Promise<Arguments>;
55
43
  }