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

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 (108) hide show
  1. package/lib/cli/index.d.ts +0 -1
  2. package/lib/cli/index.js +3 -30
  3. package/lib/config/schema.json +26 -7
  4. package/lib/config/workspace-schema.d.ts +6 -1
  5. package/lib/init.js +7 -6
  6. package/package.json +17 -20
  7. package/src/analytics/analytics-collector.js +7 -1
  8. package/src/analytics/analytics.d.ts +10 -23
  9. package/src/analytics/analytics.js +99 -184
  10. package/src/command-builder/architect-base-command-module.d.ts +8 -1
  11. package/src/command-builder/architect-base-command-module.js +61 -7
  12. package/src/command-builder/architect-command-module.d.ts +0 -1
  13. package/src/command-builder/architect-command-module.js +16 -12
  14. package/src/command-builder/command-module.d.ts +5 -2
  15. package/src/command-builder/command-module.js +21 -8
  16. package/src/command-builder/command-runner.d.ts +1 -2
  17. package/src/command-builder/command-runner.js +54 -48
  18. package/src/command-builder/schematics-command-module.d.ts +19 -7
  19. package/src/command-builder/schematics-command-module.js +268 -50
  20. package/src/command-builder/utilities/command.d.ts +13 -0
  21. package/src/command-builder/utilities/command.js +27 -0
  22. package/src/command-builder/utilities/json-help.d.ts +16 -14
  23. package/src/command-builder/utilities/json-help.js +26 -22
  24. package/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +0 -0
  25. package/{models → src/command-builder/utilities}/schematic-engine-host.js +0 -0
  26. package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
  27. package/src/command-builder/utilities/schematic-workflow.js +68 -0
  28. package/src/commands/add/cli.d.ts +11 -1
  29. package/src/commands/add/cli.js +325 -6
  30. package/src/commands/add/long-description.md +1 -4
  31. package/src/commands/analytics/cli.d.ts +5 -10
  32. package/src/commands/analytics/cli.js +15 -50
  33. package/src/commands/analytics/info/cli.d.ts +16 -0
  34. package/src/commands/analytics/info/cli.js +26 -0
  35. package/src/commands/analytics/settings/cli.d.ts +35 -0
  36. package/src/commands/analytics/settings/cli.js +61 -0
  37. package/src/commands/cache/clean/cli.d.ts +17 -0
  38. package/src/commands/cache/clean/cli.js +32 -0
  39. package/src/commands/cache/cli.d.ts +17 -0
  40. package/src/commands/cache/cli.js +38 -0
  41. package/src/commands/cache/info/cli.d.ts +20 -0
  42. package/src/commands/cache/info/cli.js +82 -0
  43. package/src/commands/cache/long-description.md +53 -0
  44. package/src/commands/cache/settings/cli.d.ts +27 -0
  45. package/src/commands/cache/settings/cli.js +42 -0
  46. package/src/commands/cache/utilities.d.ts +11 -0
  47. package/src/commands/cache/utilities.js +50 -0
  48. package/src/commands/config/cli.d.ts +5 -2
  49. package/src/commands/config/cli.js +128 -6
  50. package/src/commands/deploy/cli.d.ts +2 -1
  51. package/src/commands/deploy/cli.js +27 -13
  52. package/src/commands/doc/cli.d.ts +1 -1
  53. package/src/commands/doc/cli.js +5 -1
  54. package/src/commands/e2e/cli.d.ts +3 -2
  55. package/src/commands/e2e/cli.js +14 -13
  56. package/src/commands/generate/cli.d.ts +14 -2
  57. package/src/commands/generate/cli.js +83 -36
  58. package/src/commands/lint/cli.d.ts +2 -1
  59. package/src/commands/lint/cli.js +6 -9
  60. package/src/commands/new/cli.d.ts +7 -3
  61. package/src/commands/new/cli.js +52 -6
  62. package/src/commands/update/cli.d.ts +31 -5
  63. package/src/commands/update/cli.js +709 -8
  64. package/src/commands/update/schematic/index.js +32 -19
  65. package/src/commands/version/cli.d.ts +0 -1
  66. package/src/commands/version/cli.js +19 -43
  67. package/src/typings-bazel.d.ts +14 -0
  68. package/src/typings.d.ts +0 -13
  69. package/src/utilities/color.js +5 -1
  70. package/src/utilities/config.d.ts +1 -1
  71. package/src/utilities/config.js +22 -11
  72. package/src/utilities/environment-options.d.ts +12 -0
  73. package/src/utilities/environment-options.js +24 -0
  74. package/src/utilities/find-up.js +5 -1
  75. package/src/utilities/memoize.d.ts +15 -0
  76. package/src/utilities/memoize.js +69 -0
  77. package/src/utilities/package-manager.d.ts +33 -5
  78. package/src/utilities/package-manager.js +252 -71
  79. package/src/utilities/package-metadata.d.ts +15 -37
  80. package/src/utilities/package-metadata.js +15 -27
  81. package/src/utilities/package-tree.d.ts +2 -2
  82. package/src/utilities/package-tree.js +5 -1
  83. package/src/utilities/project.js +5 -1
  84. package/src/utilities/prompt.d.ts +2 -0
  85. package/src/utilities/prompt.js +25 -4
  86. package/bin/postinstall/analytics-prompt.js +0 -27
  87. package/bin/postinstall/script.js +0 -16
  88. package/models/command.d.ts +0 -29
  89. package/models/command.js +0 -50
  90. package/models/interface.d.ts +0 -19
  91. package/models/interface.js +0 -9
  92. package/models/schematic-command.d.ts +0 -43
  93. package/models/schematic-command.js +0 -378
  94. package/src/commands/add/add-impl.d.ts +0 -22
  95. package/src/commands/add/add-impl.js +0 -331
  96. package/src/commands/analytics/long-description.md +0 -10
  97. package/src/commands/config/config-impl.d.ts +0 -17
  98. package/src/commands/config/config-impl.js +0 -151
  99. package/src/commands/generate/generate-impl.d.ts +0 -19
  100. package/src/commands/generate/generate-impl.js +0 -49
  101. package/src/commands/new/new-impl.d.ts +0 -18
  102. package/src/commands/new/new-impl.js +0 -38
  103. package/src/commands/update/update-impl.d.ts +0 -40
  104. package/src/commands/update/update-impl.js +0 -728
  105. package/src/utilities/install-package.d.ts +0 -16
  106. package/src/utilities/install-package.js +0 -193
  107. package/src/utilities/package-json.d.ts +0 -249
  108. package/src/utilities/package-json.js +0 -9
@@ -8,7 +8,11 @@
8
8
  */
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
10
  if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
12
16
  }) : (function(o, m, k, k2) {
13
17
  if (k2 === undefined) k2 = k;
14
18
  o[k2] = m[k];
@@ -18,6 +22,12 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
18
22
  }) : function(o, v) {
19
23
  o["default"] = v;
20
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
+ };
21
31
  var __importStar = (this && this.__importStar) || function (mod) {
22
32
  if (mod && mod.__esModule) return mod;
23
33
  var result = {};
@@ -32,6 +42,7 @@ const fs_1 = require("fs");
32
42
  const path = __importStar(require("path"));
33
43
  const helpers_1 = require("yargs/helpers");
34
44
  const analytics_1 = require("../analytics/analytics");
45
+ const memoize_1 = require("../utilities/memoize");
35
46
  var CommandScope;
36
47
  (function (CommandScope) {
37
48
  /** Command can only run inside an Angular workspace. */
@@ -63,7 +74,7 @@ class CommandModule {
63
74
  longDescriptionRelativePath: path
64
75
  .relative(path.join(__dirname, '../../../../'), this.longDescriptionPath)
65
76
  .replace(/\\/g, path.posix.sep),
66
- longDescription: (0, fs_1.readFileSync)(this.longDescriptionPath, 'utf8'),
77
+ longDescription: (0, fs_1.readFileSync)(this.longDescriptionPath, 'utf8').replace(/\r\n/g, '\n'),
67
78
  }
68
79
  : {}),
69
80
  };
@@ -120,11 +131,10 @@ class CommandModule {
120
131
  metrics: [],
121
132
  });
122
133
  }
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'));
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));
128
138
  }
129
139
  /**
130
140
  * Adds schema options to a command also this keeps track of options that are required for analytics.
@@ -174,8 +184,11 @@ class CommandModule {
174
184
  return workspace;
175
185
  }
176
186
  }
177
- exports.CommandModule = CommandModule;
178
187
  CommandModule.scope = CommandScope.Both;
188
+ __decorate([
189
+ memoize_1.memoize
190
+ ], CommandModule.prototype, "getAnalytics", null);
191
+ exports.CommandModule = CommandModule;
179
192
  /**
180
193
  * Creates an known command module error.
181
194
  * This is used so during executation we can filter between known validation error and real non handled errors.
@@ -6,5 +6,4 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
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>;
9
+ export declare function runCommand(args: string[], logger: logging.Logger): Promise<number>;
@@ -16,55 +16,76 @@ const helpers_1 = require("yargs/helpers");
16
16
  const cli_1 = require("../commands/add/cli");
17
17
  const cli_2 = require("../commands/analytics/cli");
18
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");
19
+ const cli_4 = require("../commands/cache/cli");
20
+ const cli_5 = require("../commands/config/cli");
21
+ const cli_6 = require("../commands/deploy/cli");
22
+ const cli_7 = require("../commands/doc/cli");
23
+ const cli_8 = require("../commands/e2e/cli");
24
+ const cli_9 = require("../commands/extract-i18n/cli");
25
+ const cli_10 = require("../commands/generate/cli");
26
+ const cli_11 = require("../commands/lint/cli");
27
+ const cli_12 = require("../commands/make-this-awesome/cli");
28
+ const cli_13 = require("../commands/new/cli");
29
+ const cli_14 = require("../commands/run/cli");
30
+ const cli_15 = require("../commands/serve/cli");
31
+ const cli_16 = require("../commands/test/cli");
32
+ const cli_17 = require("../commands/update/cli");
33
+ const cli_18 = require("../commands/version/cli");
33
34
  const color_1 = require("../utilities/color");
35
+ const config_1 = require("../utilities/config");
36
+ const package_manager_1 = require("../utilities/package-manager");
34
37
  const command_module_1 = require("./command-module");
38
+ const command_1 = require("./utilities/command");
35
39
  const json_help_1 = require("./utilities/json-help");
36
40
  const COMMANDS = [
37
- cli_17.VersionCommandModule,
38
- cli_6.DocCommandModule,
39
- cli_11.AwesomeCommandModule,
40
- cli_4.ConfigCommandModule,
41
+ cli_18.VersionCommandModule,
42
+ cli_7.DocCommandModule,
43
+ cli_12.AwesomeCommandModule,
44
+ cli_5.ConfigCommandModule,
41
45
  cli_2.AnalyticsCommandModule,
42
46
  cli_1.AddCommandModule,
43
- cli_9.GenerateCommandModule,
47
+ cli_10.GenerateCommandModule,
44
48
  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
- ];
49
+ cli_8.E2eCommandModule,
50
+ cli_16.TestCommandModule,
51
+ cli_15.ServeCommandModule,
52
+ cli_9.ExtractI18nCommandModule,
53
+ cli_6.DeployCommandModule,
54
+ cli_11.LintCommandModule,
55
+ cli_13.NewCommandModule,
56
+ cli_17.UpdateCommandModule,
57
+ cli_14.RunCommandModule,
58
+ cli_4.CacheCommandModule,
59
+ ].sort(); // Will be sorted by class name.
55
60
  const yargsParser = helpers_1.Parser;
56
- async function runCommand(args, logger, workspace) {
61
+ async function runCommand(args, logger) {
57
62
  var _a, _b;
58
63
  const { $0, _: positional, help = false, jsonHelp = false, ...rest } = yargsParser(args, { boolean: ['help', 'json-help'], alias: { 'collection': 'c' } });
64
+ let workspace;
65
+ let globalConfiguration;
66
+ try {
67
+ [workspace, globalConfiguration] = await Promise.all([
68
+ (0, config_1.getWorkspace)('local'),
69
+ (0, config_1.getWorkspace)('global'),
70
+ ]);
71
+ }
72
+ catch (e) {
73
+ logger.fatal(e.message);
74
+ return 1;
75
+ }
76
+ const root = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.basePath) !== null && _a !== void 0 ? _a : process.cwd();
59
77
  const context = {
78
+ globalConfiguration,
60
79
  workspace,
61
80
  logger,
62
81
  currentDirectory: process.cwd(),
63
- root: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.basePath) !== null && _a !== void 0 ? _a : process.cwd(),
82
+ root,
83
+ packageManager: new package_manager_1.PackageManagerUtils({ globalConfiguration, workspace, root }),
64
84
  args: {
65
85
  positional: positional.map((v) => v.toString()),
66
86
  options: {
67
87
  help,
88
+ jsonHelp,
68
89
  ...rest,
69
90
  },
70
91
  },
@@ -78,22 +99,7 @@ async function runCommand(args, logger, workspace) {
78
99
  continue;
79
100
  }
80
101
  }
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
- });
102
+ localYargs = (0, command_1.addCommandModuleToYargs)(localYargs, CommandModule, context);
97
103
  }
98
104
  if (jsonHelp) {
99
105
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -127,7 +133,7 @@ async function runCommand(args, logger, workspace) {
127
133
  'deprecated: %s': color_1.colors.yellow('deprecated:') + ' %s',
128
134
  'Did you mean %s?': 'Unknown command. Did you mean %s?',
129
135
  })
130
- .demandCommand()
136
+ .demandCommand(1, command_1.demandCommandFailureMessage)
131
137
  .recommendCommands()
132
138
  .version(false)
133
139
  .showHelpOnFail(false)
@@ -8,24 +8,36 @@
8
8
  import { Collection } from '@angular-devkit/schematics';
9
9
  import { FileSystemCollectionDescription, FileSystemSchematicDescription, NodeWorkflow } from '@angular-devkit/schematics/tools';
10
10
  import { Argv } from 'yargs';
11
- import { CommandModule, CommandModuleImplementation, CommandScope } from './command-module';
11
+ import { CommandModule, CommandModuleImplementation, CommandScope, Options, OtherOptions } from './command-module';
12
12
  import { Option } from './utilities/json-schema';
13
+ export declare const DEFAULT_SCHEMATICS_COLLECTION = "@schematics/angular";
13
14
  export interface SchematicsCommandArgs {
14
15
  interactive: boolean;
15
16
  force: boolean;
16
17
  'dry-run': boolean;
17
18
  defaults: boolean;
18
19
  }
20
+ export interface SchematicsExecutionOptions extends Options<SchematicsCommandArgs> {
21
+ packageRegistry?: string;
22
+ }
19
23
  export declare abstract class SchematicsCommandModule extends CommandModule<SchematicsCommandArgs> implements CommandModuleImplementation<SchematicsCommandArgs> {
20
24
  static scope: CommandScope;
21
- protected readonly schematicName: string | undefined;
25
+ protected readonly allowPrivateSchematics: boolean;
26
+ protected readonly shouldReportAnalytics = false;
22
27
  builder(argv: Argv): Promise<Argv<SchematicsCommandArgs>>;
23
28
  /** Get schematic schema options.*/
24
29
  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 getOrCreateWorkflowForBuilder(collectionName: string): NodeWorkflow;
31
+ protected getOrCreateWorkflowForExecution(collectionName: string, options: SchematicsExecutionOptions): Promise<NodeWorkflow>;
32
+ protected getSchematicCollections(): Promise<Set<string>>;
30
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;
31
43
  }
@@ -6,17 +6,57 @@
6
6
  * Use of this source code is governed by an MIT-style license that can be
7
7
  * found in the LICENSE file at https://angular.io/license
8
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
+ };
9
38
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.SchematicsCommandModule = void 0;
39
+ exports.SchematicsCommandModule = exports.DEFAULT_SCHEMATICS_COLLECTION = void 0;
40
+ const core_1 = require("@angular-devkit/core");
41
+ const schematics_1 = require("@angular-devkit/schematics");
11
42
  const tools_1 = require("@angular-devkit/schematics/tools");
12
- const schematic_engine_host_1 = require("../../models/schematic-engine-host");
13
43
  const config_1 = require("../utilities/config");
44
+ const memoize_1 = require("../utilities/memoize");
45
+ const tty_1 = require("../utilities/tty");
14
46
  const command_module_1 = require("./command-module");
15
47
  const json_schema_1 = require("./utilities/json-schema");
16
- const DEFAULT_SCHEMATICS_COLLECTION = '@schematics/angular';
48
+ const schematic_engine_host_1 = require("./utilities/schematic-engine-host");
49
+ const schematic_workflow_1 = require("./utilities/schematic-workflow");
50
+ exports.DEFAULT_SCHEMATICS_COLLECTION = '@schematics/angular';
17
51
  class SchematicsCommandModule extends command_module_1.CommandModule {
52
+ constructor() {
53
+ super(...arguments);
54
+ this.allowPrivateSchematics = false;
55
+ this.shouldReportAnalytics = false;
56
+ this.defaultProjectDeprecationWarningShown = false;
57
+ }
18
58
  async builder(argv) {
19
- const localYargs = argv
59
+ return argv
20
60
  .option('interactive', {
21
61
  describe: 'Enable interactive input prompts.',
22
62
  type: 'boolean',
@@ -38,14 +78,6 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
38
78
  default: false,
39
79
  })
40
80
  .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
81
  }
50
82
  /** Get schematic schema options.*/
51
83
  async getSchematicOptions(collection, schematicName, workflow) {
@@ -56,54 +88,157 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
56
88
  }
57
89
  return (0, json_schema_1.parseJsonSchemaToOptions)(workflow.registry, schemaJson);
58
90
  }
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()],
91
+ getOrCreateWorkflowForBuilder(collectionName) {
92
+ return new tools_1.NodeWorkflow(this.context.root, {
93
+ resolvePaths: this.getResolvePaths(collectionName),
80
94
  engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
81
95
  });
82
96
  }
83
- async getDefaultSchematicCollection() {
84
- if (this._defaultSchematicCollection) {
85
- return this._defaultSchematicCollection;
97
+ async getOrCreateWorkflowForExecution(collectionName, options) {
98
+ const { logger, root, packageManager } = this.context;
99
+ const { force, dryRun, packageRegistry } = options;
100
+ const workflow = new tools_1.NodeWorkflow(root, {
101
+ force,
102
+ dryRun,
103
+ packageManager: packageManager.name,
104
+ // A schema registry is required to allow customizing addUndefinedDefaults
105
+ registry: new core_1.schema.CoreSchemaRegistry(schematics_1.formats.standardFormats),
106
+ packageRegistry,
107
+ resolvePaths: this.getResolvePaths(collectionName),
108
+ schemaValidation: true,
109
+ optionTransforms: [
110
+ // Add configuration file defaults
111
+ async (schematic, current) => {
112
+ const projectName = typeof current.project === 'string'
113
+ ? current.project
114
+ : this.getProjectName();
115
+ return {
116
+ ...(await (0, config_1.getSchematicDefaults)(schematic.collection.name, schematic.name, projectName)),
117
+ ...current,
118
+ };
119
+ },
120
+ ],
121
+ engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
122
+ });
123
+ workflow.registry.addPostTransform(core_1.schema.transforms.addUndefinedDefaults);
124
+ workflow.registry.addSmartDefaultProvider('projectName', () => this.getProjectName());
125
+ workflow.registry.useXDeprecatedProvider((msg) => logger.warn(msg));
126
+ let shouldReportAnalytics = true;
127
+ workflow.engineHost.registerOptionsTransform(async (schematic, options) => {
128
+ var _a;
129
+ if (shouldReportAnalytics) {
130
+ shouldReportAnalytics = false;
131
+ // ng generate lib -> ng generate
132
+ const commandName = (_a = this.command) === null || _a === void 0 ? void 0 : _a.split(' ', 1)[0];
133
+ await this.reportAnalytics(options, [
134
+ commandName,
135
+ schematic.collection.name.replace(/\//g, '_'),
136
+ schematic.name.replace(/\//g, '_'),
137
+ ]);
138
+ }
139
+ return options;
140
+ });
141
+ if (options.interactive !== false && (0, tty_1.isTTY)()) {
142
+ workflow.registry.usePromptProvider(async (definitions) => {
143
+ const questions = definitions
144
+ .filter((definition) => !options.defaults || definition.default === undefined)
145
+ .map((definition) => {
146
+ var _a;
147
+ const question = {
148
+ name: definition.id,
149
+ message: definition.message,
150
+ default: definition.default,
151
+ };
152
+ const validator = definition.validator;
153
+ if (validator) {
154
+ question.validate = (input) => validator(input);
155
+ // Filter allows transformation of the value prior to validation
156
+ question.filter = async (input) => {
157
+ for (const type of definition.propertyTypes) {
158
+ let value;
159
+ switch (type) {
160
+ case 'string':
161
+ value = String(input);
162
+ break;
163
+ case 'integer':
164
+ case 'number':
165
+ value = Number(input);
166
+ break;
167
+ default:
168
+ value = input;
169
+ break;
170
+ }
171
+ // Can be a string if validation fails
172
+ const isValid = (await validator(value)) === true;
173
+ if (isValid) {
174
+ return value;
175
+ }
176
+ }
177
+ return input;
178
+ };
179
+ }
180
+ switch (definition.type) {
181
+ case 'confirmation':
182
+ question.type = 'confirm';
183
+ break;
184
+ case 'list':
185
+ question.type = definition.multiselect ? 'checkbox' : 'list';
186
+ question.choices = (_a = definition.items) === null || _a === void 0 ? void 0 : _a.map((item) => {
187
+ return typeof item == 'string'
188
+ ? item
189
+ : {
190
+ name: item.label,
191
+ value: item.value,
192
+ };
193
+ });
194
+ break;
195
+ default:
196
+ question.type = definition.type;
197
+ break;
198
+ }
199
+ return question;
200
+ });
201
+ if (questions.length) {
202
+ const { prompt } = await Promise.resolve().then(() => __importStar(require('inquirer')));
203
+ return prompt(questions);
204
+ }
205
+ else {
206
+ return {};
207
+ }
208
+ });
86
209
  }
87
- let workspace = await (0, config_1.getWorkspace)('local');
210
+ return workflow;
211
+ }
212
+ async getSchematicCollections() {
213
+ var _a;
214
+ const getSchematicCollections = (configSection) => {
215
+ if (!configSection) {
216
+ return undefined;
217
+ }
218
+ const { schematicCollections, defaultCollection } = configSection;
219
+ if (Array.isArray(schematicCollections)) {
220
+ return new Set(schematicCollections);
221
+ }
222
+ else if (typeof defaultCollection === 'string') {
223
+ return new Set([defaultCollection]);
224
+ }
225
+ return undefined;
226
+ };
227
+ const { workspace, globalConfiguration } = this.context;
88
228
  if (workspace) {
89
229
  const project = (0, config_1.getProjectByCwd)(workspace);
90
230
  if (project) {
91
- const value = workspace.getProjectCli(project)['defaultCollection'];
92
- if (typeof value == 'string') {
93
- return (this._defaultSchematicCollection = value);
231
+ const value = getSchematicCollections(workspace.getProjectCli(project));
232
+ if (value) {
233
+ return value;
94
234
  }
95
235
  }
96
- const value = workspace.getCli()['defaultCollection'];
97
- if (typeof value === 'string') {
98
- return (this._defaultSchematicCollection = value);
99
- }
100
236
  }
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);
237
+ const value = (_a = getSchematicCollections(workspace === null || workspace === void 0 ? void 0 : workspace.getCli())) !== null && _a !== void 0 ? _a : getSchematicCollections(globalConfiguration === null || globalConfiguration === void 0 ? void 0 : globalConfiguration.getCli());
238
+ if (value) {
239
+ return value;
105
240
  }
106
- return (this._defaultSchematicCollection = DEFAULT_SCHEMATICS_COLLECTION);
241
+ return new Set([exports.DEFAULT_SCHEMATICS_COLLECTION]);
107
242
  }
108
243
  parseSchematicInfo(schematic) {
109
244
  if (schematic === null || schematic === void 0 ? void 0 : schematic.includes(':')) {
@@ -112,6 +247,89 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
112
247
  }
113
248
  return [undefined, schematic];
114
249
  }
250
+ async runSchematic(options) {
251
+ const { logger } = this.context;
252
+ const { schematicOptions, executionOptions, collectionName, schematicName } = options;
253
+ const workflow = await this.getOrCreateWorkflowForExecution(collectionName, executionOptions);
254
+ if (!schematicName) {
255
+ throw new Error('schematicName cannot be undefined.');
256
+ }
257
+ const { unsubscribe, files } = (0, schematic_workflow_1.subscribeToWorkflow)(workflow, logger);
258
+ try {
259
+ await workflow
260
+ .execute({
261
+ collection: collectionName,
262
+ schematic: schematicName,
263
+ options: schematicOptions,
264
+ logger,
265
+ allowPrivate: this.allowPrivateSchematics,
266
+ })
267
+ .toPromise();
268
+ if (!files.size) {
269
+ logger.info('Nothing to be done.');
270
+ }
271
+ if (executionOptions.dryRun) {
272
+ logger.warn(`\nNOTE: The "--dry-run" option means no changes were made.`);
273
+ }
274
+ }
275
+ catch (err) {
276
+ // In case the workflow was not successful, show an appropriate error message.
277
+ if (err instanceof schematics_1.UnsuccessfulWorkflowExecution) {
278
+ // "See above" because we already printed the error.
279
+ logger.fatal('The Schematic workflow failed. See above.');
280
+ return 1;
281
+ }
282
+ else {
283
+ throw err;
284
+ }
285
+ }
286
+ finally {
287
+ unsubscribe();
288
+ }
289
+ return 0;
290
+ }
291
+ getProjectName() {
292
+ const { workspace, logger } = this.context;
293
+ if (!workspace) {
294
+ return undefined;
295
+ }
296
+ const projectName = (0, config_1.getProjectByCwd)(workspace);
297
+ if (projectName) {
298
+ return projectName;
299
+ }
300
+ const defaultProjectName = workspace.extensions['defaultProject'];
301
+ if (typeof defaultProjectName === 'string' && defaultProjectName) {
302
+ if (!this.defaultProjectDeprecationWarningShown) {
303
+ logger.warn(core_1.tags.oneLine `
304
+ DEPRECATED: The 'defaultProject' workspace option has been deprecated.
305
+ The project to use will be determined from the current working directory.
306
+ `);
307
+ this.defaultProjectDeprecationWarningShown = true;
308
+ }
309
+ return defaultProjectName;
310
+ }
311
+ return undefined;
312
+ }
313
+ getResolvePaths(collectionName) {
314
+ const { workspace, root } = this.context;
315
+ return workspace
316
+ ? // Workspace
317
+ collectionName === exports.DEFAULT_SCHEMATICS_COLLECTION
318
+ ? // Favor __dirname for @schematics/angular to use the build-in version
319
+ [__dirname, process.cwd(), root]
320
+ : [process.cwd(), root, __dirname]
321
+ : // Global
322
+ [__dirname, process.cwd()];
323
+ }
115
324
  }
116
- exports.SchematicsCommandModule = SchematicsCommandModule;
117
325
  SchematicsCommandModule.scope = command_module_1.CommandScope.In;
326
+ __decorate([
327
+ memoize_1.memoize
328
+ ], SchematicsCommandModule.prototype, "getOrCreateWorkflowForBuilder", null);
329
+ __decorate([
330
+ memoize_1.memoize
331
+ ], SchematicsCommandModule.prototype, "getOrCreateWorkflowForExecution", null);
332
+ __decorate([
333
+ memoize_1.memoize
334
+ ], SchematicsCommandModule.prototype, "getSchematicCollections", null);
335
+ exports.SchematicsCommandModule = SchematicsCommandModule;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Argv } from 'yargs';
9
+ import { CommandContext, CommandModule, CommandModuleImplementation } from '../command-module';
10
+ export declare const demandCommandFailureMessage = "You need to specify a command before moving on. Use '--help' to view the available commands.";
11
+ export declare function addCommandModuleToYargs<T, U extends Partial<CommandModuleImplementation> & {
12
+ new (context: CommandContext): Partial<CommandModuleImplementation> & CommandModule;
13
+ }>(localYargs: Argv<T>, commandModule: U, context: CommandContext): Argv<T>;