@vttforge/cli 0.16.0 → 0.17.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @vttforge/cli
2
2
 
3
+ ## 0.17.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 11bf7b5: Document what a module gets. The package READMEs list `registerSocket`,
8
+ `moduleApi`, `convertSubTypes` and `inject`, which shipped without reaching
9
+ any of the places a reader looks first. The core README still named
10
+ `SystemConfig`, renamed two releases ago. The CLI README's audit list was
11
+ missing the rule for socket use with no `"socket": true` in the manifest.
12
+
13
+ ## 0.17.0
14
+
15
+ ### Minor Changes
16
+
17
+ - eb61b51: A call that used to succeed now exits 1. `vttforge init` refuses a flag it
18
+ does not know and a value it does not accept, instead of carrying on. A script
19
+ or a CI job passing either one starts failing on upgrade, which is the point:
20
+ it was not doing what it asked for.
21
+
22
+ Two ways to lose. An unknown flag was collected and ignored, so
23
+ `vttforge init app --template module-ts` exited 0 and scaffolded a system: the
24
+ flag does not exist, and nothing said so. A known flag with an unrecognised
25
+ value fell back to the default, so `--type modul` also produced a system, with
26
+ `system.json` and every system template file in it. Both surface much later,
27
+ usually in Foundry.
28
+
29
+ `--type` and `--lang` now list what they take, in the error and in `--help`.
30
+ An unknown flag names itself and the command's real flags. Both exit 1 and
31
+ write nothing. Every command carries the unknown-flag check, not only `init`.
32
+
33
+ `vttforge migrate` had the same fallback on `--style` and `--lang`, where a
34
+ typo wrote the wrong kind of file. Both are checked now too.
35
+
36
+ `create-vttforge` does the same. It used to skip unknown flags on purpose, to
37
+ keep the create flow from crashing; the cost was a scaffold that silently
38
+ ignored what was asked for.
39
+
40
+ The project templates pin `@vttforge/cli` by minor, so they move to the
41
+ release that carries this.
42
+
3
43
  ## 0.16.0
4
44
 
5
45
  ### Minor Changes
package/README.md CHANGED
@@ -26,7 +26,7 @@ vttforge migrate [dir] [--write] [--strict] [--json] [--data-models] [--sheets]
26
26
 
27
27
  **`lint`** runs Biome, which ships with the CLI, over the project with a shipped config (a `biome.json` at the project root replaces it), then the audit. `--fix` writes the safe fixes and formats.
28
28
 
29
- **`audit`** checks the manifest, the source and the templates against the v14 breakages that fail quietly: the `flags.hotReload` shape, the removed grid fields, the v12 `styles` shape, `HTMLField`/`FilePathField` paths missing from `documentTypes`, `TypeDataModel` without `prepareBaseData`, a bad `_addDataFieldMigrations` override, token attributes that do not point at a `{ value, max }` field, a sheet template that opens a `<form>` the sheet already is, a declared subtype with no name in any language file, a `template.json` that erases the metadata `system.json` declares for the same type, and the v13 code v14 broke or deprecated: bare `mergeObject`-style globals, `-=` update keys, `rollMode`, whole-array `CONFIG.statusEffects` assignment, `legacyTransferral`, numeric Active Effect modes, a release workflow that zips the checkout of a project that builds to `dist/`, and a template that still calls `{{#select}}` or `{{colorPicker}}`. `--json` prints the findings as JSON, and `--strict` exits non-zero on any finding rather than only on HIGH.
29
+ **`audit`** checks the manifest, the source and the templates against the v14 breakages that fail quietly: the `flags.hotReload` shape, the removed grid fields, the v12 `styles` shape, `HTMLField`/`FilePathField` paths missing from `documentTypes`, `TypeDataModel` without `prepareBaseData`, a bad `_addDataFieldMigrations` override, token attributes that do not point at a `{ value, max }` field, a sheet template that opens a `<form>` the sheet already is, a declared subtype with no name in any language file, a `template.json` that erases the metadata `system.json` declares for the same type, and the v13 code v14 broke or deprecated: bare `mergeObject`-style globals, `-=` update keys, `rollMode`, whole-array `CONFIG.statusEffects` assignment, `legacyTransferral`, numeric Active Effect modes, a release workflow that zips the checkout of a project that builds to `dist/`, a template that still calls `{{#select}}` or `{{colorPicker}}`, and source that talks on the package socket channel while the manifest has no `"socket": true`. `--json` prints the findings as JSON, and `--strict` exits non-zero on any finding rather than only on HIGH.
30
30
 
31
31
  **`migrate`** rewrites a v13 project for v14: the removed globals, `-=` keys, `rollMode`, context-menu keys, numeric effect modes, whole-array `CONFIG.statusEffects`, `legacyTransferral`, the core-sheet unregister lines, and the manifest's `type` and `compatibility`. It reports by default, writes with `--write` (every file computed before the first write), lists the changes it will not decide for you, and with `--strict` exits 1 while any is left. `--data-models` writes a data model per `template.json` type; `--sheets` writes a V2 sheet file on the SDK bases next to each Application v1 sheet class, with the `data-action` attributes its templates need.
32
32
 
package/dist/bin.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { a as runDev, b as maskComments, g as definesName, h as bareUsePattern, i as runInit, m as LEGACY_GLOBALS, n as runLintCommand, p as REMOVED_UTILS, r as ScaffoldError, s as runBuild, t as VTTFORGE_CLI_VERSION, u as runAuditCommand, v as _internal, x as runReleaseRules } from "./src-DK2hXzBk.mjs";
2
+ import { a as runDev, b as maskComments, g as definesName, h as bareUsePattern, i as runInit, m as LEGACY_GLOBALS, n as runLintCommand, p as REMOVED_UTILS, r as ScaffoldError, s as runBuild, t as VTTFORGE_CLI_VERSION, u as runAuditCommand, v as _internal, x as runReleaseRules } from "./src-wuBV0ItE.mjs";
3
3
  import { existsSync } from "node:fs";
4
4
  import { dirname, join, relative, resolve } from "node:path";
5
5
  import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
6
- import { defineCommand, runMain } from "citty";
6
+ import { defineCittyPlugin, defineCommand, runMain } from "citty";
7
7
  import { parse } from "@babel/parser";
8
8
  //#region src/migrate/data-models.ts
9
9
  const RICH_TEXT_KEYS = /^(description|biography|bio|notes|details)$/i;
@@ -2514,6 +2514,65 @@ async function runMigrateCommand(options = {}) {
2514
2514
  };
2515
2515
  }
2516
2516
  //#endregion
2517
+ //#region src/strict-args.ts
2518
+ /**
2519
+ * Refuse a flag the command does not define.
2520
+ *
2521
+ * The argument parser collects anything that looks like a flag, whether or
2522
+ * not the command declared it, and hands the whole lot to `run`. A command
2523
+ * reads the keys it knows and never looks at the rest, so a typo does
2524
+ * nothing and says nothing: `vttforge init app --typ module` scaffolds a
2525
+ * system, exit code 0. The user finds out much later, usually from Foundry.
2526
+ *
2527
+ * This plugin runs before the command and stops on the first unknown flag.
2528
+ */
2529
+ /**
2530
+ * One spelling of a flag name, for comparison.
2531
+ *
2532
+ * The parser answers to a flag under several keys: the declared name, its
2533
+ * aliases, and the camelCase and kebab-case forms of each. Folding case and
2534
+ * dropping the dashes covers all of them with one rule. It accepts a few
2535
+ * spellings the parser would not produce on its own, which is the safe
2536
+ * direction to be loose in: this check can then never reject a flag the
2537
+ * command really does define.
2538
+ */
2539
+ function fold(name) {
2540
+ return name.toLowerCase().replaceAll("-", "");
2541
+ }
2542
+ function acceptedNames(argsDef) {
2543
+ const accepted = /* @__PURE__ */ new Set();
2544
+ for (const [name, def] of Object.entries(argsDef)) {
2545
+ accepted.add(fold(name));
2546
+ const alias = def.alias;
2547
+ for (const entry of Array.isArray(alias) ? alias : alias ? [alias] : []) accepted.add(fold(entry));
2548
+ }
2549
+ return accepted;
2550
+ }
2551
+ /** The flags passed that the command does not define, in the order given. */
2552
+ function unknownArgs(args, argsDef) {
2553
+ const accepted = acceptedNames(argsDef);
2554
+ return Object.keys(args).filter((key) => key !== "_" && !accepted.has(fold(key)));
2555
+ }
2556
+ /**
2557
+ * Add to a command's `plugins`. It has to go on each command rather than on
2558
+ * the root: a subcommand runs through its own plugin list, not its parent's.
2559
+ */
2560
+ const strictArgs = defineCittyPlugin({
2561
+ name: "vttforge:strict-args",
2562
+ setup({ args, cmd }) {
2563
+ const argsDef = typeof cmd.args === "object" && cmd.args !== null ? cmd.args : {};
2564
+ const unknown = unknownArgs(args, argsDef);
2565
+ if (unknown.length === 0) return;
2566
+ const named = unknown.map((flag) => `--${flag}`).join(", ");
2567
+ const known = Object.keys(argsDef).filter((name) => argsDef[name].type !== "positional").map((name) => `--${name}`).join(", ");
2568
+ const meta = cmd.meta;
2569
+ const label = meta?.name ? ` ${meta.name}` : "";
2570
+ console.error(`Unknown ${unknown.length === 1 ? "flag" : "flags"} for \`vttforge${label}\`: ${named}.`);
2571
+ console.error(`This command takes: ${known}.`);
2572
+ process.exit(1);
2573
+ }
2574
+ });
2575
+ //#endregion
2517
2576
  //#region src/cli.ts
2518
2577
  /**
2519
2578
  * vttforge command tree.
@@ -2525,6 +2584,7 @@ async function runMigrateCommand(options = {}) {
2525
2584
  * lets the suite parse real argv against the real definitions.
2526
2585
  */
2527
2586
  const init = defineCommand({
2587
+ plugins: [strictArgs],
2528
2588
  meta: {
2529
2589
  name: "init",
2530
2590
  description: "Scaffold a new Foundry VTT system or module from a VTTForge template"
@@ -2536,11 +2596,13 @@ const init = defineCommand({
2536
2596
  required: false
2537
2597
  },
2538
2598
  type: {
2539
- type: "string",
2599
+ type: "enum",
2600
+ options: ["system", "module"],
2540
2601
  description: "Package type: system | module"
2541
2602
  },
2542
2603
  lang: {
2543
- type: "string",
2604
+ type: "enum",
2605
+ options: ["ts", "js"],
2544
2606
  description: "Language: ts | js"
2545
2607
  },
2546
2608
  id: {
@@ -2602,6 +2664,7 @@ const init = defineCommand({
2602
2664
  }
2603
2665
  });
2604
2666
  const dev = defineCommand({
2667
+ plugins: [strictArgs],
2605
2668
  meta: {
2606
2669
  name: "dev",
2607
2670
  description: "Symlink dist/ into Foundry Data and run vite build --watch"
@@ -2637,6 +2700,7 @@ const dev = defineCommand({
2637
2700
  }
2638
2701
  });
2639
2702
  const build = defineCommand({
2703
+ plugins: [strictArgs],
2640
2704
  meta: {
2641
2705
  name: "build",
2642
2706
  description: "Run vite build (production) and emit <id>-<version>.zip for foundryvtt.com"
@@ -2651,6 +2715,7 @@ const build = defineCommand({
2651
2715
  }
2652
2716
  });
2653
2717
  const lint = defineCommand({
2718
+ plugins: [strictArgs],
2654
2719
  meta: {
2655
2720
  name: "lint",
2656
2721
  description: "Run Biome (shipped with the CLI) over the project, then the v14 audit"
@@ -2693,6 +2758,7 @@ const lint = defineCommand({
2693
2758
  }
2694
2759
  });
2695
2760
  const audit = defineCommand({
2761
+ plugins: [strictArgs],
2696
2762
  meta: {
2697
2763
  name: "audit",
2698
2764
  description: "Scan a system/module project for the v14 manifest, source and template breakages that fail quietly"
@@ -2729,6 +2795,7 @@ const audit = defineCommand({
2729
2795
  }
2730
2796
  });
2731
2797
  const migrate = defineCommand({
2798
+ plugins: [strictArgs],
2732
2799
  meta: {
2733
2800
  name: "migrate",
2734
2801
  description: "Rewrite a v13 system or module for Foundry v14 (preview by default); --data-models and --sheets write the v16 replacements"
@@ -2760,12 +2827,14 @@ const migrate = defineCommand({
2760
2827
  description: "Also generate a data model per template.json type (template.json is deprecated since v14)"
2761
2828
  },
2762
2829
  style: {
2763
- type: "string",
2830
+ type: "enum",
2831
+ options: ["plain", "sdk"],
2764
2832
  default: "plain",
2765
2833
  description: "For --data-models: \"plain\" Foundry classes, or \"sdk\" classes on @vttforge/core"
2766
2834
  },
2767
2835
  lang: {
2768
- type: "string",
2836
+ type: "enum",
2837
+ options: ["js", "ts"],
2769
2838
  default: "js",
2770
2839
  description: "For --data-models and --sheets: \"js\" writes .mjs, \"ts\" writes .ts"
2771
2840
  },