@vttforge/cli 0.5.2 → 0.5.3

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 (45) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +21 -23
  3. package/dist/bin.mjs +1 -1
  4. package/dist/index.d.mts +1 -1
  5. package/dist/index.mjs +1 -1
  6. package/dist/{src-CWhUNM__.mjs → src-KI6RBaTd.mjs} +90 -4
  7. package/dist/src-KI6RBaTd.mjs.map +1 -0
  8. package/package.json +1 -1
  9. package/templates/module-js/README.md +46 -22
  10. package/templates/module-js/lang/en.json +19 -1
  11. package/templates/module-js/module.json +7 -2
  12. package/templates/module-js/scripts/constants.mjs +12 -0
  13. package/templates/module-js/scripts/data/note-data.mjs +18 -0
  14. package/templates/module-js/scripts/enricher.mjs +56 -0
  15. package/templates/module-js/scripts/main.mjs +75 -53
  16. package/templates/module-js/scripts/sheets/note-sheet.mjs +69 -0
  17. package/templates/module-js/styles/main.css +70 -9
  18. package/templates/module-js/templates/item/note-sheet.hbs +34 -0
  19. package/templates/module-ts/README.md +51 -22
  20. package/templates/module-ts/lang/en.json +19 -1
  21. package/templates/module-ts/module.json +7 -2
  22. package/templates/module-ts/scripts/constants.ts +12 -0
  23. package/templates/module-ts/scripts/data/note-data.ts +19 -0
  24. package/templates/module-ts/scripts/enricher.ts +52 -0
  25. package/templates/module-ts/scripts/main.ts +73 -55
  26. package/templates/module-ts/scripts/sheets/note-sheet.ts +76 -0
  27. package/templates/module-ts/styles/main.css +70 -9
  28. package/templates/module-ts/templates/item/note-sheet.hbs +34 -0
  29. package/templates/module-ts/tsconfig.json +8 -2
  30. package/templates/system-js/README.md +45 -27
  31. package/templates/system-js/scripts/data/character-data.mjs +65 -59
  32. package/templates/system-js/scripts/data/gear-data.mjs +31 -31
  33. package/templates/system-js/scripts/main.mjs +38 -21
  34. package/templates/system-js/scripts/sheets/character-sheet.mjs +49 -50
  35. package/templates/system-js/scripts/sheets/gear-sheet.mjs +14 -12
  36. package/templates/system-js/templates/actor/character-sheet.hbs +1 -1
  37. package/templates/system-ts/README.md +45 -27
  38. package/templates/system-ts/scripts/data/character-data.ts +80 -64
  39. package/templates/system-ts/scripts/data/gear-data.ts +35 -31
  40. package/templates/system-ts/scripts/main.ts +38 -21
  41. package/templates/system-ts/scripts/sheets/character-sheet.ts +99 -98
  42. package/templates/system-ts/scripts/sheets/gear-sheet.ts +26 -20
  43. package/templates/system-ts/templates/actor/character-sheet.hbs +1 -1
  44. package/templates/system-ts/tsconfig.json +1 -0
  45. package/dist/src-CWhUNM__.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @vttforge/cli
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 578ba31: Bring the package READMEs in line with what shipped. `core`, `styles`, `types` and `vite-plugin` still described themselves as v0.0.1 placeholders with "planned" features; `cli` did not mention `audit`.
8
+ - 8fef09a: Rewrite the four `init` templates against the current SDK.
9
+
10
+ The scaffolds still showed the patterns the SDK exists to replace: `as any` on the sheet bases, sheets registered by hand with `Actors.registerSheet`, untyped data models, and module templates that never called `registerModule`. A project created today contradicted the docs from its first file.
11
+
12
+ - `system-ts` / `system-js`: data models use the typed `BaseTypeDataModel(defineSchema)` factory; sheets are declared in `registerSystem({ sheets })` with stable ids; each sheet narrows `this.document` once in an `actor` / `item` getter; `tsconfig` turns on `noImplicitOverride`.
13
+ - `module-ts` / `module-js`: built on `registerModule`. The scaffold adds a `note` Item sub-type (declared under `documentTypes`, keyed with `moduleSubType`), a sheet on `BaseItemSheet`, an `@Note[id]` enricher, a setting and a public API.
14
+ - READMEs no longer say the packages are unpublished.
15
+ - `vttforge audit` rules VTTF-AUDIT-004 and VTTF-AUDIT-007 now attribute a schema declared in a named factory (`class X extends BaseTypeDataModel(defineSchema)`) to the class that uses it. Before, a system on the typed factory was flagged for token attributes its schema did declare.
16
+ - The template test now typechecks the TypeScript variants against the workspace `@vttforge/core`, so a template that drifts from the SDK fails in CI.
17
+ - ae724e3: Read the exported `VTTFORGE_*_VERSION` constants from `package.json` at build time. They were hardcoded and had fallen behind — `vttforge --version` printed `0.1.0` on the 0.5 line.
18
+
3
19
  ## 0.5.2
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -1,39 +1,37 @@
1
1
  # @vttforge/cli
2
2
 
3
- VTTForge CLI — scaffolding, dev loop, and release builds for Foundry VTT v13+ systems and modules.
3
+ Scaffold, dev loop, release build and audit for Foundry VTT v13+ systems and modules.
4
+
5
+ ```bash
6
+ pnpm create vttforge my-system # same as: npx @vttforge/cli init my-system
7
+ ```
4
8
 
5
9
  ## Commands
6
10
 
7
11
  ```bash
8
- vttforge init <name> [--type system|module] [--lang ts|js] [--no-install] [--no-git]
9
- vttforge dev [--foundry-data <path>]
12
+ vttforge init <name> [--type system|module] [--lang ts|js] [--id] [--title] [--description]
13
+ [--author] [--license] [--yes] [--no-install] [--no-git]
14
+ vttforge dev [--foundry-data <path>] [--port <n>]
10
15
  vttforge build
16
+ vttforge audit [dir] [--json] [--strict]
11
17
  ```
12
18
 
13
- - `vttforge init` — interactive scaffolder. Asks for package id, title, author, license, Foundry compatibility version, and writes a runnable system/module starter into `<name>/`. Detects the calling package manager (`pnpm`, `npm`, `bun`, `yarn`) via `npm_config_user_agent` and offers to install deps + `git init`. Equivalent UX from `pnpm create vttforge <name>` via the `create-vttforge` package.
14
- - `vttforge dev` — one-shot `vite build`, then symlink `dist/` into your Foundry user-data directory under `Data/<systems|modules>/<id>/`, then `vite build --watch` with inherited stdio. Cleans up the symlink on `Ctrl-C`. First run prompts for the Foundry data dir and saves the choice to `.vttforge/config.json`; subsequent runs skip the prompt. Override with `--foundry-data <path>` (alias: `--data-dir`) or set `FOUNDRY_DATA_DIR` in your environment.
15
- - `vttforge build` — production `vite build` followed by `<id>-<version>.zip` emission at the project root. Pulls `LICENSE`, `README.md`, and `CHANGELOG.md` from the project root into the zip when present.
19
+ **`init`** writes a runnable system or module into `<name>/` from one of four templates (`system-ts`, `system-js`, `module-ts`, `module-js`). It asks for what you did not pass, or takes defaults with `--yes`, so it works in CI. It detects the package manager that invoked it (`pnpm`, `npm`, `bun`, `yarn`), installs, and runs `git init`.
16
20
 
17
- ## Library exports
21
+ **`dev`** builds once, links `dist/` into Foundry's data directory under `Data/<systems|modules>/<id>/`, installs the `@vttforge/dev-module` companion, and watches. Save a template and the open sheet redraws in place; save a stylesheet and the CSS swaps. The first run asks where Foundry keeps its data and saves the answer to `.vttforge/config.json`; `--foundry-data` or `FOUNDRY_DATA_DIR` overrides it. If Foundry runs in a container it cannot follow the symlink, and the command prints the compose mount to use instead.
18
22
 
19
- `@vttforge/cli` also exposes its internals for consumers building higher-level tooling:
23
+ **`build`** runs the production build and writes `<id>-<version>.zip` at the project root with the manifest at the top level, which is what foundryvtt.com expects. `LICENSE`, `README.md` and `CHANGELOG.md` go in when present.
20
24
 
21
- ```ts
22
- import {
23
- runInit, runDev, runBuild,
24
- scaffold, substitute, templatesRoot,
25
- resolveFoundryDataDir, foundryPackagesDir,
26
- readManifest, emitZip,
27
- createLink, removeLink, readLinkTarget,
28
- resolveViteInvocation, runViteBuildOnce, spawnViteWatch,
29
- detectPackageManager, detectProjectPackageManager, execInvocation, installCommand,
30
- } from '@vttforge/cli';
31
- ```
25
+ **`audit`** checks the manifest and source against seven v13 breakages that fail quietly: the `flags.hotReload` shape, deprecated grid fields, the v12 `styles` shape, `HTMLField`/`FilePathField` paths missing from `documentTypes`, `TypeDataModel` without `prepareBaseData`, a bad `_addDataFieldMigrations` override, and token attributes that do not point at a `{ value, max }` field. `--json` for machines; `--strict` exits non-zero on any finding rather than only on HIGH.
26
+
27
+ ## As a library
32
28
 
33
- ## Foundry-aware HMR
29
+ Every command is exported for tooling built on top: `runInit`, `runDev`, `runBuild`, `runAudit`, `emitReleaseZip`, `resolveFoundryDataDir`, `readManifest`, and the scaffold helpers.
34
30
 
35
- Run Foundry with `--hotReload` (e.g. `foundryvtt --hotReload`) and `vttforge dev` becomes a live-reload loop without further setup: Foundry's built-in chokidar watcher follows the symlink, and its dispatcher swaps CSS / Handlebars / JSON files in place when vite re-emits them.
31
+ ## Docs
36
32
 
37
- ## Stack
33
+ - [Getting started](https://vttforge.dev/docs/guide/getting-started)
34
+ - [The dev loop](https://vttforge.dev/docs/guide/dev-loop)
35
+ - [CLI reference](https://vttforge.dev/docs/guide/cli)
38
36
 
39
- Citty (commands) + Clack (prompts) + Archiver (zip).
37
+ Node 26+.
package/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { M as runAuditCommand, c as runDev, n as ScaffoldError, r as runInit, t as VTTFORGE_CLI_VERSION, x as runBuild } from "./src-CWhUNM__.mjs";
2
+ import { M as runAuditCommand, c as runDev, n as ScaffoldError, r as runInit, t as VTTFORGE_CLI_VERSION, x as runBuild } from "./src-KI6RBaTd.mjs";
3
3
  import { defineCommand, runMain } from "citty";
4
4
  //#region src/cli.ts
5
5
  /**
package/dist/index.d.mts CHANGED
@@ -490,7 +490,7 @@ interface EmitZipResult {
490
490
  declare function emitZip(opts: EmitZipOptions): Promise<EmitZipResult>;
491
491
  //#endregion
492
492
  //#region src/index.d.ts
493
- declare const VTTFORGE_CLI_VERSION = "0.1.0";
493
+ declare const VTTFORGE_CLI_VERSION: string;
494
494
  //#endregion
495
495
  export { type AuditOptions, type AuditReport, type AuditResult, type BuildOptions, type CreateLinkOptions, type DevOptions, type EmitZipOptions, type EmitZipResult, type FoundryManifest, type InitOptions, type PackageManager, type PackageType, type ReportFormat, type ResolveDataDirOptions, type ResolvedInitOptions, type RuleFn, type RuleResult, SEVERITY_RANK, ScaffoldError, type ScaffoldOptions, type ScaffoldVars, type Severity, type TemplateVariant, VTTFORGE_CLI_VERSION, type VTTForgeConfig, ViteNotInstalledError, autoDetectFoundryDataDir, cleanupDevSymlink, configPath, createLink, detectPackageManager, detectProjectPackageManager, emitReleaseZip, emitZip, execInvocation, formatReport, foundryPackagesDir, installCommand, loadConfig, looksLikeFoundryDataDir, readLinkTarget, readManifest, removeLink, resolveFoundryDataDir, resolveViteInvocation, runAudit, runAuditCommand, runBuild, runDev, runInit, runManifestRules, runSourceRules, runViteBuildOnce, saveConfig, scaffold, setupDevSymlink, spawnViteWatch, substitute, templatesRoot };
496
496
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { A as installCommand, C as ViteNotInstalledError, D as detectPackageManager, E as spawnViteWatch, F as SEVERITY_RANK, I as runSourceRules, L as runManifestRules, M as runAuditCommand, N as formatReport, O as detectProjectPackageManager, P as runAudit, S as emitZip, T as runViteBuildOnce, _ as createLink, a as substitute, b as emitReleaseZip, c as runDev, d as configPath, f as foundryPackagesDir, g as saveConfig, h as resolveFoundryDataDir, i as scaffold, j as readManifest, k as execInvocation, l as setupDevSymlink, m as looksLikeFoundryDataDir, n as ScaffoldError, o as templatesRoot, p as loadConfig, r as runInit, s as cleanupDevSymlink, t as VTTFORGE_CLI_VERSION, u as autoDetectFoundryDataDir, v as readLinkTarget, w as resolveViteInvocation, x as runBuild, y as removeLink } from "./src-CWhUNM__.mjs";
1
+ import { A as installCommand, C as ViteNotInstalledError, D as detectPackageManager, E as spawnViteWatch, F as SEVERITY_RANK, I as runSourceRules, L as runManifestRules, M as runAuditCommand, N as formatReport, O as detectProjectPackageManager, P as runAudit, S as emitZip, T as runViteBuildOnce, _ as createLink, a as substitute, b as emitReleaseZip, c as runDev, d as configPath, f as foundryPackagesDir, g as saveConfig, h as resolveFoundryDataDir, i as scaffold, j as readManifest, k as execInvocation, l as setupDevSymlink, m as looksLikeFoundryDataDir, n as ScaffoldError, o as templatesRoot, p as loadConfig, r as runInit, s as cleanupDevSymlink, t as VTTFORGE_CLI_VERSION, u as autoDetectFoundryDataDir, v as readLinkTarget, w as resolveViteInvocation, x as runBuild, y as removeLink } from "./src-KI6RBaTd.mjs";
2
2
  export { SEVERITY_RANK, ScaffoldError, VTTFORGE_CLI_VERSION, ViteNotInstalledError, autoDetectFoundryDataDir, cleanupDevSymlink, configPath, createLink, detectPackageManager, detectProjectPackageManager, emitReleaseZip, emitZip, execInvocation, formatReport, foundryPackagesDir, installCommand, loadConfig, looksLikeFoundryDataDir, readLinkTarget, readManifest, removeLink, resolveFoundryDataDir, resolveViteInvocation, runAudit, runAuditCommand, runBuild, runDev, runInit, runManifestRules, runSourceRules, runViteBuildOnce, saveConfig, scaffold, setupDevSymlink, spawnViteWatch, substitute, templatesRoot };
@@ -9,6 +9,9 @@ import { createHash } from "node:crypto";
9
9
  import { createServer } from "node:http";
10
10
  import { homedir } from "node:os";
11
11
  import { promisify } from "node:util";
12
+ //#region package.json
13
+ var version = "0.5.3";
14
+ //#endregion
12
15
  //#region src/audit/manifest-rules.ts
13
16
  /**
14
17
  * Manifest-scope audit rules.
@@ -341,6 +344,82 @@ function findEnclosingClass(ranges, idx) {
341
344
  }
342
345
  }
343
346
  /**
347
+ * A class built on the `BaseTypeDataModel(defineSchema)` factory keeps its
348
+ * schema in a function outside the class body. Rules that ask "which class
349
+ * owns this field" would otherwise see the field as unowned. So the body of
350
+ * that function is reported as a range owned by the class, alongside the
351
+ * class's own body.
352
+ *
353
+ * Both the arrow and the `function` form are recognised, as long as the
354
+ * function is named and passed by name. An inline arrow is already inside
355
+ * the `class ... {` match and needs no help.
356
+ */
357
+ function findSchemaFactoryRanges(content) {
358
+ const out = [];
359
+ for (const match of content.matchAll(/class\s+(\w+)\s+extends\s+(?:[\w.]+\.)?BaseTypeDataModel\s*\(\s*(\w+)\s*\)/g)) {
360
+ const className = match[1];
361
+ const fnName = match[2];
362
+ if (!className || !fnName) continue;
363
+ const fnMatch = new RegExp(String.raw`(?:(?:const|let|var)\s+${fnName}\s*=\s*(?:async\s*)?(?:\([^)]*\)|\w+)\s*(?::[^=]*?)?=>\s*\(?\s*\{|function\s+${fnName}\s*\([^)]*\)\s*(?::[^{]*?)?\{)`).exec(content);
364
+ if (fnMatch === null) continue;
365
+ const openIdx = fnMatch.index + fnMatch[0].length - 1;
366
+ const endIdx = findMatchingBrace(content, openIdx);
367
+ if (endIdx < 0) continue;
368
+ let line = 1;
369
+ for (let i = 0; i < fnMatch.index; i += 1) if (content[i] === "\n") line += 1;
370
+ out.push({
371
+ className,
372
+ startLine: line,
373
+ openIdx,
374
+ endIdx
375
+ });
376
+ }
377
+ return out;
378
+ }
379
+ /** Every range whose fields belong to a class: class bodies, then factory bodies. */
380
+ function findSchemaOwnerRanges(content) {
381
+ return [...findClassRanges(content), ...findSchemaFactoryRanges(content)];
382
+ }
383
+ /**
384
+ * Index of the `}` that closes the `{` at `openIdx`, skipping braces inside
385
+ * string literals, template literals and comments. Returns -1 when unbalanced.
386
+ */
387
+ function findMatchingBrace(content, openIdx) {
388
+ let depth = 0;
389
+ let i = openIdx;
390
+ while (i < content.length) {
391
+ const ch = content[i];
392
+ const next = content[i + 1];
393
+ if (ch === "/" && next === "/") {
394
+ i = content.indexOf("\n", i);
395
+ if (i < 0) return -1;
396
+ continue;
397
+ }
398
+ if (ch === "/" && next === "*") {
399
+ i = content.indexOf("*/", i + 2);
400
+ if (i < 0) return -1;
401
+ i += 2;
402
+ continue;
403
+ }
404
+ if (ch === "'" || ch === "\"" || ch === "`") {
405
+ i += 1;
406
+ while (i < content.length && content[i] !== ch) {
407
+ if (content[i] === "\\") i += 1;
408
+ i += 1;
409
+ }
410
+ i += 1;
411
+ continue;
412
+ }
413
+ if (ch === "{") depth += 1;
414
+ else if (ch === "}") {
415
+ depth -= 1;
416
+ if (depth === 0) return i;
417
+ }
418
+ i += 1;
419
+ }
420
+ return -1;
421
+ }
422
+ /**
344
423
  * One `<subtype>: <Class>` entry inside a dataModels object literal.
345
424
  *
346
425
  * The key is bare for a system (`character`) and quoted for a module
@@ -516,7 +595,7 @@ function lookupSubtype(declared, doc, subtype) {
516
595
  * declare anything" case without false positives on advanced setups).
517
596
  */
518
597
  function rule004(filePath, content, declared, classToSubtypes) {
519
- const usages = findRichFields(content, findClassRanges(content));
598
+ const usages = findRichFields(content, findSchemaOwnerRanges(content));
520
599
  const out = [];
521
600
  for (const usage of usages) {
522
601
  const declaredBucketName = usage.type === "HTMLField" ? "htmlFields" : "filePathFields";
@@ -617,7 +696,7 @@ async function sourceHasValueMaxSchemaAtPath(sourceFiles, targetPath, actorClass
617
696
  } catch {
618
697
  continue;
619
698
  }
620
- const classes = findClassRanges(content);
699
+ const classes = findSchemaOwnerRanges(content);
621
700
  for (const decl of findAllSchemaFields(content)) {
622
701
  if (decl.path !== targetPath) continue;
623
702
  if (actorClasses.size > 0) {
@@ -2436,8 +2515,15 @@ function runInstall(pm, cwd) {
2436
2515
  }
2437
2516
  //#endregion
2438
2517
  //#region src/index.ts
2439
- const VTTFORGE_CLI_VERSION = "0.1.0";
2518
+ /**
2519
+ * @vttforge/cli — public library exports.
2520
+ *
2521
+ * The CLI is intended to be used as a bin (`vttforge` command). These
2522
+ * exports exist for consumers who want to programmatically invoke the
2523
+ * scaffolder (e.g. from another CLI, a test harness, or a custom tool).
2524
+ */
2525
+ const VTTFORGE_CLI_VERSION = version;
2440
2526
  //#endregion
2441
2527
  export { installCommand as A, ViteNotInstalledError as C, detectPackageManager as D, spawnViteWatch as E, SEVERITY_RANK as F, runSourceRules as I, runManifestRules as L, runAuditCommand as M, formatReport as N, detectProjectPackageManager as O, runAudit as P, emitZip as S, runViteBuildOnce as T, createLink as _, substitute as a, emitReleaseZip as b, runDev as c, configPath as d, foundryPackagesDir as f, saveConfig as g, resolveFoundryDataDir as h, scaffold as i, readManifest as j, execInvocation as k, setupDevSymlink as l, looksLikeFoundryDataDir as m, ScaffoldError as n, templatesRoot as o, loadConfig as p, runInit as r, cleanupDevSymlink as s, VTTFORGE_CLI_VERSION as t, autoDetectFoundryDataDir as u, readLinkTarget as v, resolveViteInvocation as w, runBuild as x, removeLink as y };
2442
2528
 
2443
- //# sourceMappingURL=src-CWhUNM__.mjs.map
2529
+ //# sourceMappingURL=src-KI6RBaTd.mjs.map