@angular-devkit/schematics-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.
package/bin/schematics.js CHANGED
@@ -26,9 +26,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  __setModuleDefault(result, mod);
27
27
  return result;
28
28
  };
29
- var __importDefault = (this && this.__importDefault) || function (mod) {
30
- return (mod && mod.__esModule) ? mod : { "default": mod };
31
- };
32
29
  Object.defineProperty(exports, "__esModule", { value: true });
33
30
  exports.main = void 0;
34
31
  // symbol polyfill must go first
@@ -39,7 +36,7 @@ const schematics_1 = require("@angular-devkit/schematics");
39
36
  const tools_1 = require("@angular-devkit/schematics/tools");
40
37
  const ansiColors = __importStar(require("ansi-colors"));
41
38
  const inquirer = __importStar(require("inquirer"));
42
- const minimist_1 = __importDefault(require("minimist"));
39
+ const yargs_parser_1 = __importStar(require("yargs-parser"));
43
40
  /**
44
41
  * Parse the name of schematic passed in argument, and return a {collection, schematic} named
45
42
  * tuple. The user can pass in `collection-name:schematic-name`, and this function will either
@@ -57,10 +54,11 @@ const minimist_1 = __importDefault(require("minimist"));
57
54
  function parseSchematicName(str) {
58
55
  let collection = '@angular-devkit/schematics-cli';
59
56
  let schematic = str;
60
- if (schematic && schematic.indexOf(':') != -1) {
57
+ if (schematic === null || schematic === void 0 ? void 0 : schematic.includes(':')) {
58
+ const lastIndexOfColon = schematic.lastIndexOf(':');
61
59
  [collection, schematic] = [
62
- schematic.slice(0, schematic.lastIndexOf(':')),
63
- schematic.substring(schematic.lastIndexOf(':') + 1),
60
+ schematic.slice(0, lastIndexOfColon),
61
+ schematic.substring(lastIndexOfColon + 1),
64
62
  ];
65
63
  }
66
64
  return { collection, schematic };
@@ -117,32 +115,32 @@ function _createPromptProvider() {
117
115
  }
118
116
  // eslint-disable-next-line max-lines-per-function
119
117
  async function main({ args, stdout = process.stdout, stderr = process.stderr, }) {
120
- const argv = parseArgs(args);
118
+ const { cliOptions, schematicOptions, _ } = parseArgs(args);
121
119
  // Create a separate instance to prevent unintended global changes to the color configuration
122
120
  // Create function is not defined in the typings. See: https://github.com/doowb/ansi-colors/pull/44
123
121
  const colors = ansiColors.create();
124
122
  /** Create the DevKit Logger used through the CLI. */
125
- const logger = (0, node_1.createConsoleLogger)(argv['verbose'], stdout, stderr, {
123
+ const logger = (0, node_1.createConsoleLogger)(!!cliOptions.verbose, stdout, stderr, {
126
124
  info: (s) => s,
127
125
  debug: (s) => s,
128
126
  warn: (s) => colors.bold.yellow(s),
129
127
  error: (s) => colors.bold.red(s),
130
128
  fatal: (s) => colors.bold.red(s),
131
129
  });
132
- if (argv.help) {
130
+ if (cliOptions.help) {
133
131
  logger.info(getUsage());
134
132
  return 0;
135
133
  }
136
134
  /** Get the collection an schematic name from the first argument. */
137
- const { collection: collectionName, schematic: schematicName } = parseSchematicName(argv._.shift() || null);
135
+ const { collection: collectionName, schematic: schematicName } = parseSchematicName(_.shift() || null);
138
136
  const isLocalCollection = collectionName.startsWith('.') || collectionName.startsWith('/');
139
137
  /** Gather the arguments for later use. */
140
- const debugPresent = argv['debug'] !== null;
141
- const debug = debugPresent ? !!argv['debug'] : isLocalCollection;
142
- const dryRunPresent = argv['dry-run'] !== null;
143
- const dryRun = dryRunPresent ? !!argv['dry-run'] : debug;
144
- const force = argv['force'];
145
- const allowPrivate = argv['allow-private'];
138
+ const debugPresent = cliOptions.debug !== null;
139
+ const debug = debugPresent ? !!cliOptions.debug : isLocalCollection;
140
+ const dryRunPresent = cliOptions['dry-run'] !== null;
141
+ const dryRun = dryRunPresent ? !!cliOptions['dry-run'] : debug;
142
+ const force = !!cliOptions.force;
143
+ const allowPrivate = !!cliOptions['allow-private'];
146
144
  /** Create the workflow scoped to the working directory that will be executed with this run. */
147
145
  const workflow = new tools_1.NodeWorkflow(process.cwd(), {
148
146
  force,
@@ -151,7 +149,7 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
151
149
  schemaValidation: true,
152
150
  });
153
151
  /** If the user wants to list schematics, we simply show all the schematic names. */
154
- if (argv['list-schematics']) {
152
+ if (cliOptions['list-schematics']) {
155
153
  return _listSchematics(workflow, collectionName, logger);
156
154
  }
157
155
  if (!schematicName) {
@@ -216,35 +214,12 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
216
214
  error = false;
217
215
  }
218
216
  });
219
- /**
220
- * Remove every options from argv that we support in schematics itself.
221
- */
222
- const parsedArgs = Object.assign({}, argv);
223
- delete parsedArgs['--'];
224
- for (const key of booleanArgs) {
225
- delete parsedArgs[key];
226
- }
227
- /**
228
- * Add options from `--` to args.
229
- */
230
- const argv2 = (0, minimist_1.default)(argv['--']);
231
- for (const key of Object.keys(argv2)) {
232
- parsedArgs[key] = argv2[key];
233
- }
234
217
  // Show usage of deprecated options
235
218
  workflow.registry.useXDeprecatedProvider((msg) => logger.warn(msg));
236
219
  // Pass the rest of the arguments as the smart default "argv". Then delete it.
237
- workflow.registry.addSmartDefaultProvider('argv', (schema) => {
238
- if ('index' in schema) {
239
- return argv._[Number(schema['index'])];
240
- }
241
- else {
242
- return argv._;
243
- }
244
- });
245
- delete parsedArgs._;
220
+ workflow.registry.addSmartDefaultProvider('argv', (schema) => 'index' in schema ? _[Number(schema['index'])] : _);
246
221
  // Add prompts.
247
- if (argv['interactive'] && isTTY()) {
222
+ if (cliOptions.interactive && isTTY()) {
248
223
  workflow.registry.usePromptProvider(_createPromptProvider());
249
224
  }
250
225
  /**
@@ -260,7 +235,7 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
260
235
  .execute({
261
236
  collection: collectionName,
262
237
  schematic: schematicName,
263
- options: parsedArgs,
238
+ options: schematicOptions,
264
239
  allowPrivate: allowPrivate,
265
240
  debug: debug,
266
241
  logger: logger,
@@ -280,10 +255,10 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
280
255
  logger.fatal('The Schematic workflow failed. See above.');
281
256
  }
282
257
  else if (debug) {
283
- logger.fatal('An error occured:\n' + err.stack);
258
+ logger.fatal(`An error occured:\n${err.stack}`);
284
259
  }
285
260
  else {
286
- logger.fatal(err.stack || err.message);
261
+ logger.fatal(`Error: ${err.message}`);
287
262
  }
288
263
  return 1;
289
264
  }
@@ -294,7 +269,7 @@ exports.main = main;
294
269
  */
295
270
  function getUsage() {
296
271
  return core_1.tags.stripIndent `
297
- schematics [CollectionName:]SchematicName [options, ...]
272
+ schematics [collection-name:]schematic-name [options, ...]
298
273
 
299
274
  By default, if the collection name is not specified, use the internal collection provided
300
275
  by the Schematics CLI.
@@ -325,33 +300,51 @@ function getUsage() {
325
300
  }
326
301
  /** Parse the command line. */
327
302
  const booleanArgs = [
328
- 'allowPrivate',
329
303
  'allow-private',
330
304
  'debug',
331
305
  'dry-run',
332
- 'dryRun',
333
306
  'force',
334
307
  'help',
335
308
  'list-schematics',
336
- 'listSchematics',
337
309
  'verbose',
338
310
  'interactive',
339
311
  ];
312
+ /** Parse the command line. */
340
313
  function parseArgs(args) {
341
- return (0, minimist_1.default)(args, {
314
+ const { _, ...options } = (0, yargs_parser_1.default)(args, {
342
315
  boolean: booleanArgs,
343
- alias: {
344
- 'dryRun': 'dry-run',
345
- 'listSchematics': 'list-schematics',
346
- 'allowPrivate': 'allow-private',
347
- },
348
316
  default: {
349
317
  'interactive': true,
350
318
  'debug': null,
351
- 'dryRun': null,
319
+ 'dry-run': null,
320
+ },
321
+ configuration: {
322
+ 'dot-notation': false,
323
+ 'boolean-negation': true,
324
+ 'strip-aliased': true,
325
+ 'camel-case-expansion': false,
352
326
  },
353
- '--': true,
354
327
  });
328
+ // Camelize options as yargs will return the object in kebab-case when camel casing is disabled.
329
+ const schematicOptions = {};
330
+ const cliOptions = {};
331
+ const isCliOptions = (key) => booleanArgs.includes(key);
332
+ for (const [key, value] of Object.entries(options)) {
333
+ if (/[A-Z]/.test(key)) {
334
+ throw new Error(`Unknown argument ${key}. Did you mean ${(0, yargs_parser_1.decamelize)(key)}?`);
335
+ }
336
+ if (isCliOptions(key)) {
337
+ cliOptions[key] = value;
338
+ }
339
+ else {
340
+ schematicOptions[(0, yargs_parser_1.camelCase)(key)] = value;
341
+ }
342
+ }
343
+ return {
344
+ _: _.map((v) => v.toString()),
345
+ schematicOptions,
346
+ cliOptions,
347
+ };
355
348
  }
356
349
  function isTTY() {
357
350
  const isTruthy = (value) => {
@@ -18,7 +18,7 @@
18
18
  "typescript": "~4.5.2"
19
19
  },
20
20
  "devDependencies": {
21
- "@types/node": "^12.11.1",
21
+ "@types/node": "^14.15.0",
22
22
  "@types/jasmine": "~3.10.0",
23
23
  "jasmine": "^4.0.0"
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-devkit/schematics-cli",
3
- "version": "14.0.0-next.2",
3
+ "version": "14.0.0-next.5",
4
4
  "description": "Angular Schematics - CLI",
5
5
  "homepage": "https://github.com/angular/angular-cli",
6
6
  "bin": {
@@ -21,19 +21,19 @@
21
21
  ],
22
22
  "schematics": "./collection.json",
23
23
  "dependencies": {
24
- "@angular-devkit/core": "14.0.0-next.2",
25
- "@angular-devkit/schematics": "14.0.0-next.2",
24
+ "@angular-devkit/core": "14.0.0-next.5",
25
+ "@angular-devkit/schematics": "14.0.0-next.5",
26
26
  "ansi-colors": "4.1.1",
27
- "inquirer": "8.2.0",
28
- "minimist": "1.2.5",
29
- "symbol-observable": "4.0.0"
27
+ "inquirer": "8.2.1",
28
+ "symbol-observable": "4.0.0",
29
+ "yargs-parser": "21.0.1"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",
33
33
  "url": "https://github.com/angular/angular-cli.git"
34
34
  },
35
35
  "engines": {
36
- "node": "^12.20.0 || ^14.15.0 || >=16.10.0",
36
+ "node": "^14.15.0 || >=16.10.0",
37
37
  "npm": "^6.11.0 || ^7.5.6 || >=8.0.0",
38
38
  "yarn": ">= 1.13.0"
39
39
  },
@@ -18,7 +18,7 @@
18
18
  "typescript": "~4.5.2"
19
19
  },
20
20
  "devDependencies": {
21
- "@types/node": "^12.11.1",
21
+ "@types/node": "^14.15.0",
22
22
  "@types/jasmine": "~3.10.0",
23
23
  "jasmine": "~4.0.0"
24
24
  }