@m2c2kit/cli 0.3.32 → 0.3.34

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/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * The code in this file is adapted from a reference CLI implementation from
4
4
  * the Angular devkit repository:
5
- * https://github.com/angular/angular-cli/blob/1c2d49ec736818d22773916d7eaafd3446275ea0/packages/angular_devkit/schematics_cli/bin/schematics.ts
5
+ * https://github.com/angular/angular-cli/blob/91b9d281fc88a242aa6e5dd5495e275990d926ef/packages/angular_devkit/schematics_cli/bin/schematics.ts
6
6
  * The license for that code is as follows:
7
7
  * @license
8
8
  * Copyright Google LLC All Rights Reserved.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * The code in this file is adapted from a reference CLI implementation from
5
5
  * the Angular devkit repository:
6
- * https://github.com/angular/angular-cli/blob/1c2d49ec736818d22773916d7eaafd3446275ea0/packages/angular_devkit/schematics_cli/bin/schematics.ts
6
+ * https://github.com/angular/angular-cli/blob/91b9d281fc88a242aa6e5dd5495e275990d926ef/packages/angular_devkit/schematics_cli/bin/schematics.ts
7
7
  * The license for that code is as follows:
8
8
  * @license
9
9
  * Copyright Google LLC All Rights Reserved.
@@ -56,7 +56,7 @@ const tools_1 = require("@angular-devkit/schematics/tools");
56
56
  const ansi_colors_1 = __importDefault(require("ansi-colors"));
57
57
  const node_fs_1 = require("node:fs");
58
58
  const path = __importStar(require("node:path"));
59
- const yargs_parser_1 = __importStar(require("yargs-parser"));
59
+ const node_util_1 = require("node:util");
60
60
  /**
61
61
  * Parse the name of schematic passed in argument, and return a {collection, schematic} named
62
62
  * tuple. The user can pass in `collection-name:schematic-name`, and this function will either
@@ -193,19 +193,20 @@ function _createPromptProvider() {
193
193
  };
194
194
  }
195
195
  function findUp(names, from) {
196
- if (!Array.isArray(names)) {
197
- names = [names];
198
- }
199
- const root = path.parse(from).root;
200
- let currentDir = from;
201
- while (currentDir && currentDir !== root) {
202
- for (const name of names) {
196
+ const filenames = Array.isArray(names) ? names : [names];
197
+ let currentDir = path.resolve(from);
198
+ while (true) {
199
+ for (const name of filenames) {
203
200
  const p = path.join(currentDir, name);
204
201
  if ((0, node_fs_1.existsSync)(p)) {
205
202
  return p;
206
203
  }
207
204
  }
208
- currentDir = path.dirname(currentDir);
205
+ const parentDir = path.dirname(currentDir);
206
+ if (parentDir === currentDir) {
207
+ break;
208
+ }
209
+ currentDir = parentDir;
209
210
  }
210
211
  return null;
211
212
  }
@@ -227,16 +228,14 @@ function getPackageManagerName() {
227
228
  }
228
229
  // eslint-disable-next-line max-lines-per-function
229
230
  async function main({ args, stdout = process.stdout, stderr = process.stderr, }) {
230
- const { cliOptions, schematicOptions, _ } = parseArgs(args);
231
- // Create a separate instance to prevent unintended global changes to the color configuration
232
- const colors = ansi_colors_1.default.create();
231
+ const { cliOptions, schematicOptions, _ } = parseOptions(args);
233
232
  /** Create the DevKit Logger used through the CLI. */
234
233
  const logger = (0, node_1.createConsoleLogger)(!!cliOptions.verbose, stdout, stderr, {
235
234
  info: (s) => s,
236
235
  debug: (s) => s,
237
- warn: (s) => colors.bold.yellow(s),
238
- error: (s) => colors.bold.red(s),
239
- fatal: (s) => colors.bold.red(s),
236
+ warn: (s) => (0, node_util_1.styleText)(["bold", "yellow"], s),
237
+ error: (s) => (0, node_util_1.styleText)(["bold", "red"], s),
238
+ fatal: (s) => (0, node_util_1.styleText)(["bold", "red"], s),
240
239
  });
241
240
  if (cliOptions.help) {
242
241
  logger.info(getUsage());
@@ -246,10 +245,9 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
246
245
  const { collection: collectionName, schematic: schematicName } = parseSchematicName(_.shift() || null);
247
246
  const isLocalCollection = collectionName.startsWith(".") || collectionName.startsWith("/");
248
247
  /** Gather the arguments for later use. */
249
- const debugPresent = cliOptions.debug !== null;
250
- const debug = debugPresent ? !!cliOptions.debug : isLocalCollection;
251
- const dryRunPresent = cliOptions["dry-run"] !== null;
252
- const dryRun = dryRunPresent ? !!cliOptions["dry-run"] : debug;
248
+ const debug = cliOptions.debug ?? isLocalCollection;
249
+ const dryRunPresent = cliOptions["dry-run"] != null;
250
+ const dryRun = cliOptions["dry-run"] ?? debug;
253
251
  const force = !!cliOptions.force;
254
252
  const allowPrivate = !!cliOptions["allow-private"];
255
253
  /** Create the workflow scoped to the working directory that will be executed with this run. */
@@ -300,18 +298,18 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
300
298
  case "update":
301
299
  loggingQueue.push(
302
300
  // TODO: `as unknown` was necessary during TS 5.9 update. Figure out a long-term solution.
303
- `${colors.cyan("UPDATE")} ${eventPath} (${event.content.length} bytes)`);
301
+ `${(0, node_util_1.styleText)(["cyan"], "UPDATE")} ${eventPath} (${event.content.length} bytes)`);
304
302
  break;
305
303
  case "create":
306
304
  loggingQueue.push(
307
305
  // TODO: `as unknown` was necessary during TS 5.9 update. Figure out a long-term solution.
308
- `${colors.green("CREATE")} ${eventPath} (${event.content.length} bytes)`);
306
+ `${(0, node_util_1.styleText)(["green"], "CREATE")} ${eventPath} (${event.content.length} bytes)`);
309
307
  break;
310
308
  case "delete":
311
- loggingQueue.push(`${colors.yellow("DELETE")} ${eventPath}`);
309
+ loggingQueue.push(`${(0, node_util_1.styleText)(["yellow"], "DELETE")} ${eventPath}`);
312
310
  break;
313
311
  case "rename":
314
- loggingQueue.push(`${colors.blue("RENAME")} ${eventPath} => ${removeLeadingSlash(event.to)}`);
312
+ loggingQueue.push(`${(0, node_util_1.styleText)(["blue"], "RENAME")} ${eventPath} => ${removeLeadingSlash(event.to)}`);
315
313
  break;
316
314
  }
317
315
  });
@@ -403,52 +401,96 @@ ${colors.blue("Commands:")}
403
401
  --init Create site-config.mjs file in the current directory.
404
402
  `;
405
403
  }
404
+ const CLI_OPTION_DEFINITIONS = {
405
+ "allow-private": { type: "boolean" },
406
+ debug: { type: "boolean" },
407
+ "dry-run": { type: "boolean" },
408
+ force: { type: "boolean" },
409
+ help: { type: "boolean" },
410
+ "list-schematics": { type: "boolean" },
411
+ verbose: { type: "boolean" },
412
+ interactive: { type: "boolean", default: true },
413
+ };
406
414
  /** Parse the command line. */
407
- const booleanArgs = [
408
- "allow-private",
409
- "debug",
410
- "dry-run",
411
- "force",
412
- "help",
413
- "list-schematics",
414
- "verbose",
415
- "interactive",
416
- ];
417
- /** Parse the command line. */
418
- function parseArgs(args) {
419
- const { _, ...options } = (0, yargs_parser_1.default)(args, {
420
- boolean: booleanArgs,
421
- default: {
422
- interactive: true,
423
- debug: null,
424
- "dry-run": null,
425
- },
426
- configuration: {
427
- "dot-notation": false,
428
- "boolean-negation": true,
429
- "strip-aliased": true,
430
- "camel-case-expansion": false,
431
- },
415
+ function parseOptions(args) {
416
+ const { values, tokens } = (0, node_util_1.parseArgs)({
417
+ args,
418
+ strict: false,
419
+ tokens: true,
420
+ allowPositionals: true,
421
+ allowNegative: true,
422
+ options: CLI_OPTION_DEFINITIONS,
432
423
  });
433
- // Camelize options as yargs will return the object in kebab-case when camel casing is disabled.
434
424
  const schematicOptions = {};
435
- const cliOptions = {};
436
- const isCliOptions = (key) => booleanArgs.includes(key);
437
- for (const [key, value] of Object.entries(options)) {
438
- if (/[A-Z]/.test(key)) {
439
- throw new Error(`Unknown argument ${key}. Did you mean ${(0, yargs_parser_1.decamelize)(key)}?`);
425
+ const positionals = [];
426
+ for (let i = 0; i < tokens.length; i++) {
427
+ const token = tokens[i];
428
+ if (token.kind === "positional") {
429
+ positionals.push(token.value);
430
+ continue;
431
+ }
432
+ if (token.kind !== "option") {
433
+ continue;
434
+ }
435
+ const name = token.name;
436
+ let value = token.value ?? true;
437
+ // `parseArgs` already handled known boolean args and their --no- forms.
438
+ // Only process options not in CLI_OPTION_DEFINITIONS here.
439
+ if (name in CLI_OPTION_DEFINITIONS) {
440
+ continue;
441
+ }
442
+ if (/[A-Z]/.test(name)) {
443
+ throw new Error(`Unknown argument ${name}. Did you mean ${schematics_1.strings.decamelize(name).replace(/_/g, "-")}?`);
444
+ }
445
+ // Handle --no-flag for unknown options, treating it as false
446
+ if (name.startsWith("no-")) {
447
+ const realName = name.slice(3);
448
+ schematicOptions[schematics_1.strings.camelize(realName)] = false;
449
+ continue;
440
450
  }
441
- if (isCliOptions(key)) {
442
- cliOptions[key] = value;
451
+ // Handle value for unknown options
452
+ if (token.inlineValue === undefined) {
453
+ // Look ahead
454
+ const nextToken = tokens[i + 1];
455
+ if (nextToken?.kind === "positional") {
456
+ value = nextToken.value;
457
+ i++; // Consume next token
458
+ }
459
+ else {
460
+ value = true; // Treat as boolean if no value follows
461
+ }
462
+ }
463
+ if (typeof value === "string") {
464
+ if (!isNaN(Number(value))) {
465
+ // Type inference for numbers
466
+ value = Number(value);
467
+ }
468
+ else if (value === "true") {
469
+ // Type inference for booleans
470
+ value = true;
471
+ }
472
+ else if (value === "false") {
473
+ value = false;
474
+ }
475
+ }
476
+ const camelName = schematics_1.strings.camelize(name);
477
+ if (Object.prototype.hasOwnProperty.call(schematicOptions, camelName)) {
478
+ const existing = schematicOptions[camelName];
479
+ if (Array.isArray(existing)) {
480
+ existing.push(value);
481
+ }
482
+ else {
483
+ schematicOptions[camelName] = [existing, value];
484
+ }
443
485
  }
444
486
  else {
445
- schematicOptions[(0, yargs_parser_1.camelCase)(key)] = value;
487
+ schematicOptions[camelName] = value;
446
488
  }
447
489
  }
448
490
  return {
449
- _: _.map((v) => v.toString()),
491
+ _: positionals,
450
492
  schematicOptions,
451
- cliOptions,
493
+ cliOptions: values,
452
494
  };
453
495
  }
454
496
  function isTTY() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m2c2kit/cli",
3
- "version": "0.3.32",
3
+ "version": "0.3.34",
4
4
  "description": "Command line interface to create new m2c2kit apps",
5
5
  "files": [
6
6
  "dist/**"
@@ -25,17 +25,17 @@
25
25
  },
26
26
  "homepage": "https://m2c2-project.github.io/m2c2kit",
27
27
  "dependencies": {
28
- "@angular-devkit/core": "^20.3.4",
29
- "@angular-devkit/schematics": "^20.3.4",
30
- "@inquirer/prompts": "7.8.6",
31
- "@m2c2kit/schematics": "0.1.32",
32
- "@schematics/angular": "^20.3.4",
28
+ "@angular-devkit/core": "^21.1.2",
29
+ "@angular-devkit/schematics": "^21.1.2",
30
+ "@inquirer/prompts": "7.10.1",
31
+ "@m2c2kit/schematics": "0.1.34",
32
+ "@schematics/angular": "^21.1.2",
33
33
  "ansi-colors": "4.1.3",
34
34
  "yargs-parser": "22.0.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/inquirer": "9.0.9",
38
- "rimraf": "6.0.1",
38
+ "rimraf": "6.1.2",
39
39
  "typescript": "5.9.3"
40
40
  },
41
41
  "engines": {