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