@sf-kmods/kdataforgejs-cli 2026.4.24 → 2026.4.30
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/README.md +42 -0
- package/dist/cli.js +86 -33
- package/dist/commands/add.js +7 -3
- package/dist/commands/check.js +10 -4
- package/dist/commands/dev.js +14 -5
- package/dist/commands/doctor.js +35 -10
- package/dist/commands/format.js +16 -11
- package/dist/commands/gameData.js +111 -25
- package/dist/commands/hash.js +12 -4
- package/dist/commands/lint.js +11 -11
- package/dist/commands/sync.js +41 -24
- package/dist/commands/update.js +114 -0
- package/dist/commands/validate.js +12 -6
- package/dist/pack/discover.js +124 -8
- package/dist/pack/imports.js +11 -6
- package/dist/pack/sourceGraph.js +3 -2
- package/dist/pack/transaction.js +110 -0
- package/dist/pack/usage.js +34 -3
- package/dist/types/configTypes.js +9 -5
- package/package.json +3 -3
- package/templates/default/DataForge/scripts/features/catalog.ts +7 -0
- package/templates/default/DataForge/scripts/lib/catalog-v1.ts +3 -0
- package/templates/default/DataForge/scripts/main.ts +8 -3
- package/templates/default/README.md +21 -1
- package/templates/default/DataForge/scripts/lib.ts +0 -3
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ npm run verify
|
|
|
24
24
|
| `kdf doctor [dir]` | Read-only health report for Node, project checks, manifest drift, installation and imported game data. `--json` emits machine-readable statuses: `pass`, `warn`, `fail`, `unknown`. |
|
|
25
25
|
| `kdf dev [dir]` | Watches authored files, debounces changes, then runs sync, check, lint and validate in order. After success, prints manual `KDF.Reload` instruction. |
|
|
26
26
|
| `kdf add <handler\|hook\|item\|recipe\|document> <name> [dir]` | Creates one scaffold and updates entry imports, handler call and literal capabilities. Existing destinations and computed metadata are refused. Documents default to `cdo`; `--type item` or `--type recipe` selects another minimal document form. |
|
|
27
|
+
| `kdf update [dir]` | Read-only, network-free report of declared and locally installed SDK/CLI versions and game-data status. `--apply` updates local dev dependencies, then runs the newly installed local CLI's `game-data` once. `--offline --apply` skips the package manager and refreshes from installed packages/cache/game only. |
|
|
27
28
|
|
|
28
29
|
Exit code `0` means all good, `1` means findings, `2` means the command was used wrong.
|
|
29
30
|
|
|
@@ -34,6 +35,47 @@ The generated project keeps `package.json` and `tsconfig.json` next to the `Data
|
|
|
34
35
|
itself has no `node_modules`. `npm run refresh` runs `kdf game-data`; `npm run fix` formats scripts and synchronizes
|
|
35
36
|
generated manifest fields. `format`, `lint`, `check`, `validate`, `hash`, `sync`, `test`, and `verify` are available too.
|
|
36
37
|
|
|
38
|
+
## Multiple packs in one workspace
|
|
39
|
+
|
|
40
|
+
Keep each pack in its own tooling project, for example `packs/Alpha/DataForge/pack.yml` and
|
|
41
|
+
`packs/Beta/DataForge/pack.yml`. At the repository root, declare npm `workspaces: ["packs/*"]`
|
|
42
|
+
or pnpm `packages: ["packs/*"]` in `pnpm-workspace.yaml`. Run `kdf init packs/Alpha --name Alpha`
|
|
43
|
+
for each pack; `package.json`, `tsconfig.json` and dependencies remain beside that pack's
|
|
44
|
+
`DataForge/`, never inside it. Install dependencies from the workspace root. Keep one root
|
|
45
|
+
`package-lock.json` or `pnpm-lock.yaml`; the CLI never installs packages during discovery,
|
|
46
|
+
checks, `doctor`, or `--offline` update.
|
|
47
|
+
|
|
48
|
+
From workspace root, `check`, `lint`, `validate`, `sync`, `hash`, `format`, `doctor`, and `dev`
|
|
49
|
+
cover all discovered packs. Add `--pack Alpha` to select one unique pack ref. `add` requires
|
|
50
|
+
`--pack` when several packs are present. Only literal workspace paths and one whole `*`
|
|
51
|
+
directory segment are supported; unsupported patterns, escaping symlinks, and duplicate refs
|
|
52
|
+
fail explicitly. `check` uses each pack project's own tsconfig, keeping config/reflection types
|
|
53
|
+
isolated. Packs still cannot import code outside their own `scripts/` or carry `node_modules`.
|
|
54
|
+
|
|
55
|
+
`kdf game-data` from workspace root exports the installed game once, uses one root cache/archive,
|
|
56
|
+
and installs generated reflection declarations plus `tsconfig.kdf.json` into every pack project.
|
|
57
|
+
The export describes installed game/mod content; authored workspace packs appear only after they
|
|
58
|
+
are installed into the game. `--pack` is intentionally unavailable for `game-data` and `update`.
|
|
59
|
+
Manifests are synchronized after successful game-data import. The CLI stages generated files,
|
|
60
|
+
uses a workspace writer lock under `.kdataforge/`, and restores old files on ordinary install
|
|
61
|
+
failure. A crash during a multi-file swap can leave mixed files; rerun `kdf game-data` and
|
|
62
|
+
`kdf sync`. Check for a live writer before removing a stale `writer.lock`.
|
|
63
|
+
|
|
64
|
+
## Update SDK and game data
|
|
65
|
+
|
|
66
|
+
`kdf update` reports versions from each project's manifest and installed `node_modules`; it
|
|
67
|
+
does not query a registry or modify files. It compares the installed archive with a validated
|
|
68
|
+
cache for the current game/save when possible. `unknown` freshness is never reported as current.
|
|
69
|
+
Run `kdf update --apply` to invoke detected npm/pnpm with fixed
|
|
70
|
+
`@sf-kmods/kdataforgejs@latest` and `@sf-kmods/kdataforgejs-cli@latest` dev dependencies,
|
|
71
|
+
`--ignore-scripts`, and no global install. It then runs the newly installed local CLI's
|
|
72
|
+
`game-data` once. Pass `--game-path`, `--timeout`, `--content-types`, or `--force` through to
|
|
73
|
+
that refresh. Package-manager network and lockfile operations are not atomic across packs:
|
|
74
|
+
if one install fails, inspect root lockfile and package manifests before retrying. Generated
|
|
75
|
+
reflection files remain untouched until game-data succeeds. `kdf update --offline --apply`
|
|
76
|
+
requires both packages already installed at matching versions, skips package-manager registry
|
|
77
|
+
access, and only refreshes game data. Offline mode never alters lockfiles.
|
|
78
|
+
|
|
37
79
|
Literal `ctx.import(kind, path)` calls and reflected paths used by `ctx.getClass`, `ctx.getObject` and
|
|
38
80
|
`ctx.getDataAsset` are source of truth. YAML imports are scanned for `target` paths. Run `kdf sync`; do not maintain
|
|
39
81
|
manifest import digests or reflection class lists by hand. Dynamic import paths are rejected because CLI cannot grant
|
package/dist/cli.js
CHANGED
|
@@ -8,23 +8,27 @@ import { importGameData } from "./commands/gameData.js";
|
|
|
8
8
|
import { hashProject } from "./commands/hash.js";
|
|
9
9
|
import { initProject } from "./commands/init.js";
|
|
10
10
|
import { lintProject } from "./commands/lint.js";
|
|
11
|
-
import { syncProject } from "./commands/sync.js";
|
|
11
|
+
import { prepareSync, syncProject } from "./commands/sync.js";
|
|
12
12
|
import { validateProject } from "./commands/validate.js";
|
|
13
|
+
import { updateProject } from "./commands/update.js";
|
|
13
14
|
import { formatDiagnostic, hasErrors } from "./diagnostics.js";
|
|
15
|
+
import { discoverPacks } from "./pack/discover.js";
|
|
16
|
+
import { withProjectLock } from "./pack/transaction.js";
|
|
14
17
|
const USAGE = `kdf - KDataForgeJS project tooling
|
|
15
18
|
|
|
16
19
|
Usage:
|
|
17
20
|
kdf init [dir] [--name <PackRef>] [--force] Create a new KDataForge project with a TypeScript script
|
|
18
|
-
kdf check [dir]
|
|
21
|
+
kdf check [dir] [--pack <ref>] Type-check selected pack projects (no emit)
|
|
19
22
|
kdf format [dir] Format DataForge scripts with bundled Biome
|
|
20
23
|
kdf lint [dir] Lint DataForge scripts with bundled Biome rules
|
|
21
24
|
kdf validate [dir] Check pack.yml, entry, static imports and import digests
|
|
22
25
|
kdf sync [dir] Generate imports, hashes and reflection classes from source
|
|
23
26
|
kdf hash [dir] Update sha256 of declared script imports in pack.yml
|
|
24
|
-
kdf game-data [dir] [--game-path <path>] [--content-types] [--force] Export
|
|
27
|
+
kdf game-data [dir] [--game-path <path>] [--content-types] [--force] Export once and refresh every pack
|
|
28
|
+
kdf update [dir] [--apply] [--offline] Inspect SDK/CLI and game data; apply local update explicitly
|
|
25
29
|
kdf doctor [dir] [--game-path <path>] [--json] Read-only environment and project health
|
|
26
30
|
kdf dev [dir] Watch authored files; sync, check, lint, validate
|
|
27
|
-
kdf add <handler|hook|item|recipe|document> <name> [dir] [--type <document-type>]
|
|
31
|
+
kdf add <handler|hook|item|recipe|document> <name> [dir] [--pack <ref>] [--type <document-type>]
|
|
28
32
|
kdf --help | --version
|
|
29
33
|
`;
|
|
30
34
|
const DEFAULT_DEPENDENCIES = { importGameData };
|
|
@@ -35,27 +39,40 @@ export function createCli(dependencies) {
|
|
|
35
39
|
}
|
|
36
40
|
async function runCli(request, dependencies) {
|
|
37
41
|
const { argv, io, version } = request;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
json: { type: "boolean", default: false },
|
|
48
|
-
force: { type: "boolean", default: false },
|
|
49
|
-
help: { type: "boolean", short: "h", default: false },
|
|
50
|
-
version: { type: "boolean", short: "v", default: false },
|
|
51
|
-
},
|
|
52
|
-
});
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = parseCliArgs(argv);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
io.err(error instanceof Error ? error.message : String(error));
|
|
48
|
+
return 2;
|
|
49
|
+
}
|
|
50
|
+
const { values, positionals } = parsed;
|
|
53
51
|
const [command, directory = "."] = positionals;
|
|
54
52
|
if (values.version)
|
|
55
53
|
return print(io.out, version);
|
|
56
54
|
if (values.help || command === undefined)
|
|
57
55
|
return print(io.out, USAGE);
|
|
58
56
|
try {
|
|
57
|
+
if ((values.apply || values.offline) && command !== "update" ||
|
|
58
|
+
(command === "add" ? positionals.length > 4 : positionals.length > 2)) {
|
|
59
|
+
io.err(`Invalid options or arguments for kdf ${command}.`);
|
|
60
|
+
return 2;
|
|
61
|
+
}
|
|
62
|
+
if (values.pack && ["init", "game-data", "update"].includes(command)) {
|
|
63
|
+
io.err(`--pack is not supported by kdf ${command}.`);
|
|
64
|
+
return 2;
|
|
65
|
+
}
|
|
66
|
+
if (values.pack) {
|
|
67
|
+
const target = command === "add" ? positionals[3] ?? "." : directory;
|
|
68
|
+
try {
|
|
69
|
+
discoverPacks(target, values.pack);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
io.err(error instanceof Error ? error.message : String(error));
|
|
73
|
+
return 2;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
59
76
|
switch (command) {
|
|
60
77
|
case "init": {
|
|
61
78
|
const result = initProject({ directory, force: values.force, ...(values.name ? { name: values.name } : {}) });
|
|
@@ -64,35 +81,39 @@ async function runCli(request, dependencies) {
|
|
|
64
81
|
return 0;
|
|
65
82
|
}
|
|
66
83
|
case "check":
|
|
67
|
-
return report(io, checkProject(directory), "Type check passed.");
|
|
84
|
+
return report(io, checkProject(directory, undefined, values.pack), "Type check passed.");
|
|
68
85
|
case "format": {
|
|
69
|
-
const result = formatProject(directory);
|
|
86
|
+
const result = formatProject(directory, values.pack);
|
|
70
87
|
io.out(result.changedFiles.length === 0
|
|
71
88
|
? "Files are already formatted."
|
|
72
89
|
: `Formatted files:\n${result.changedFiles.join("\n")}`);
|
|
73
90
|
return 0;
|
|
74
91
|
}
|
|
75
92
|
case "lint":
|
|
76
|
-
return report(io, lintProject(directory), "Lint passed.");
|
|
93
|
+
return report(io, lintProject(directory, values.pack), "Lint passed.");
|
|
77
94
|
case "validate":
|
|
78
|
-
return report(io, validateProject(directory), "Pack is valid.");
|
|
95
|
+
return report(io, validateProject(directory, values.pack), "Pack is valid.");
|
|
79
96
|
case "sync": {
|
|
80
|
-
const result = syncProject(directory);
|
|
81
|
-
io.out(result.changedPacks.length === 0
|
|
82
|
-
? "Manifest
|
|
83
|
-
: `Synchronized manifests:\n${result.changedPacks.join("\n")}`);
|
|
97
|
+
const result = syncProject(directory, values.pack);
|
|
98
|
+
io.out(result.changedPacks.length === 0 && result.changedTypes.length === 0
|
|
99
|
+
? "Manifest and config types are already synchronized."
|
|
100
|
+
: `Synchronized manifests and config types:\n${[...result.changedPacks, ...result.changedTypes].join("\n")}`);
|
|
84
101
|
return 0;
|
|
85
102
|
}
|
|
86
103
|
case "hash": {
|
|
87
|
-
const changed = hashProject(directory);
|
|
104
|
+
const changed = hashProject(directory, values.pack);
|
|
88
105
|
io.out(changed.length === 0 ? "All import digests are up to date." : `Updated digests:\n${changed.join("\n")}`);
|
|
89
106
|
return 0;
|
|
90
107
|
}
|
|
91
108
|
case "game-data": {
|
|
92
|
-
|
|
109
|
+
const selection = discoverPacks(directory);
|
|
110
|
+
const projects = [...new Set(selection.packs.map((pack) => pack.projectRoot))];
|
|
111
|
+
const prepared = prepareSync(directory);
|
|
93
112
|
const timeoutMilliseconds = parseTimeout(values.timeout);
|
|
94
113
|
const result = await dependencies.importGameData({
|
|
95
|
-
destination:
|
|
114
|
+
destination: selection.root,
|
|
115
|
+
projectRoots: projects,
|
|
116
|
+
synchronizedFiles: prepared.files,
|
|
96
117
|
...(values["game-path"] ? { gamePath: values["game-path"] } : {}),
|
|
97
118
|
...(timeoutMilliseconds === undefined ? {} : { timeoutMilliseconds }),
|
|
98
119
|
...(values["content-types"] ? { contentTypes: true } : {}),
|
|
@@ -103,8 +124,15 @@ async function runCli(request, dependencies) {
|
|
|
103
124
|
io.out(`Types: ${result.declarationPath}`);
|
|
104
125
|
return 0;
|
|
105
126
|
}
|
|
127
|
+
case "update": {
|
|
128
|
+
const result = updateProject({ directory, apply: values.apply, offline: values.offline,
|
|
129
|
+
gamePath: values["game-path"], timeout: values.timeout, contentTypes: values["content-types"], force: values.force });
|
|
130
|
+
for (const line of result.lines)
|
|
131
|
+
io.out(line);
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
106
134
|
case "doctor": {
|
|
107
|
-
const checks = doctorProject(directory, values["game-path"]);
|
|
135
|
+
const checks = doctorProject(directory, values["game-path"], values.pack);
|
|
108
136
|
if (values.json)
|
|
109
137
|
io.out(JSON.stringify({ checks }, null, 2));
|
|
110
138
|
else
|
|
@@ -113,7 +141,7 @@ async function runCli(request, dependencies) {
|
|
|
113
141
|
return checks.some((check) => check.status === "fail") ? 1 : 0;
|
|
114
142
|
}
|
|
115
143
|
case "dev":
|
|
116
|
-
startDev(directory, io);
|
|
144
|
+
startDev(directory, io, values.pack);
|
|
117
145
|
return 0;
|
|
118
146
|
case "add": {
|
|
119
147
|
const [kind, name, root = "."] = positionals.slice(1);
|
|
@@ -121,7 +149,12 @@ async function runCli(request, dependencies) {
|
|
|
121
149
|
io.err(USAGE);
|
|
122
150
|
return 2;
|
|
123
151
|
}
|
|
124
|
-
const
|
|
152
|
+
const selection = discoverPacks(root, values.pack);
|
|
153
|
+
if (selection.packs.length !== 1) {
|
|
154
|
+
io.err("Multiple packs found; pass --pack <ref> for kdf add.");
|
|
155
|
+
return 2;
|
|
156
|
+
}
|
|
157
|
+
const path = withProjectLock(selection.root, () => addScaffold(selection.packs[0]?.projectRoot ?? root, kind, name, values.type, selection.packs[0]?.root));
|
|
125
158
|
io.out(`Created ${path}`);
|
|
126
159
|
return 0;
|
|
127
160
|
}
|
|
@@ -135,6 +168,26 @@ async function runCli(request, dependencies) {
|
|
|
135
168
|
return 1;
|
|
136
169
|
}
|
|
137
170
|
}
|
|
171
|
+
function parseCliArgs(argv) {
|
|
172
|
+
return parseArgs({
|
|
173
|
+
args: [...argv],
|
|
174
|
+
allowPositionals: true,
|
|
175
|
+
options: {
|
|
176
|
+
name: { type: "string" },
|
|
177
|
+
pack: { type: "string" },
|
|
178
|
+
"game-path": { type: "string" },
|
|
179
|
+
timeout: { type: "string" },
|
|
180
|
+
"content-types": { type: "boolean", default: false },
|
|
181
|
+
type: { type: "string" },
|
|
182
|
+
json: { type: "boolean", default: false },
|
|
183
|
+
force: { type: "boolean", default: false },
|
|
184
|
+
apply: { type: "boolean", default: false },
|
|
185
|
+
offline: { type: "boolean", default: false },
|
|
186
|
+
help: { type: "boolean", short: "h", default: false },
|
|
187
|
+
version: { type: "boolean", short: "v", default: false },
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
138
191
|
function parseTimeout(value) {
|
|
139
192
|
if (value === undefined)
|
|
140
193
|
return undefined;
|
package/dist/commands/add.js
CHANGED
|
@@ -4,11 +4,12 @@ import { dirname, join, resolve } from "node:path";
|
|
|
4
4
|
import ts from "typescript";
|
|
5
5
|
import { parseDocument } from "yaml";
|
|
6
6
|
import { RUNTIME_MODULE } from "../conventions.js";
|
|
7
|
+
import { assertSafeWrite } from "../pack/transaction.js";
|
|
7
8
|
const CAPABILITY = {
|
|
8
9
|
hook: "kdf.native.hook", item: "kdf.items.define", recipe: "kdf.recipes.define", document: "kdf.documents.apply",
|
|
9
10
|
};
|
|
10
11
|
const NAME = /^[A-Za-z][A-Za-z0-9_-]*$/u;
|
|
11
|
-
export function addScaffold(directory, kind, name, documentType = "cdo") {
|
|
12
|
+
export function addScaffold(directory, kind, name, documentType = "cdo", selectedPackRoot) {
|
|
12
13
|
if (!NAME.test(name))
|
|
13
14
|
throw new Error("Name must start with a letter and contain only letters, digits, '-' or '_'.");
|
|
14
15
|
if (!["handler", "hook", "item", "recipe", "document"].includes(kind))
|
|
@@ -16,10 +17,13 @@ export function addScaffold(directory, kind, name, documentType = "cdo") {
|
|
|
16
17
|
if (kind === "document" && !NAME.test(documentType))
|
|
17
18
|
throw new Error("Document type must be a safe identifier.");
|
|
18
19
|
const root = resolve(directory);
|
|
19
|
-
const
|
|
20
|
+
const packRoot = selectedPackRoot ?? join(root, "DataForge");
|
|
21
|
+
const entryPath = join(packRoot, "scripts/main.ts");
|
|
22
|
+
assertSafeWrite(packRoot, entryPath);
|
|
20
23
|
if (!existsSync(entryPath))
|
|
21
24
|
throw new Error(`Entry file does not exist: ${entryPath}`);
|
|
22
|
-
const destination = kind === "document" ? join(
|
|
25
|
+
const destination = kind === "document" ? join(packRoot, `${name}.yml`) : join(packRoot, "scripts", `${name}.ts`);
|
|
26
|
+
assertSafeWrite(packRoot, destination);
|
|
23
27
|
if (existsSync(destination))
|
|
24
28
|
throw new Error(`Refusing to overwrite ${destination}`);
|
|
25
29
|
const before = readFileSync(entryPath, "utf8");
|
package/dist/commands/check.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { dirname, join, relative, resolve } from "node:path";
|
|
3
3
|
import ts from "typescript";
|
|
4
|
+
import { discoverPacks } from "../pack/discover.js";
|
|
4
5
|
/** Type-checks the project's tsconfig.json (no emit) with the TypeScript compiler bundled with the CLI. */
|
|
5
|
-
export function checkProject(projectRoot, configName) {
|
|
6
|
+
export function checkProject(projectRoot, configName, packRef) {
|
|
7
|
+
const selection = discoverPacks(projectRoot, packRef);
|
|
8
|
+
const projects = [...new Set(selection.packs.map((pack) => pack.projectRoot))];
|
|
9
|
+
return projects.flatMap((root) => checkSingleProject(root, selection.root, configName));
|
|
10
|
+
}
|
|
11
|
+
function checkSingleProject(projectRoot, displayRoot, configName) {
|
|
6
12
|
const absoluteProjectRoot = resolve(projectRoot);
|
|
7
13
|
const selectedConfig = configName ?? (existsSync(join(absoluteProjectRoot, "tsconfig.kdf.json")) ? "tsconfig.kdf.json" : "tsconfig.json");
|
|
8
14
|
const configPath = join(absoluteProjectRoot, selectedConfig);
|
|
@@ -11,17 +17,17 @@ export function checkProject(projectRoot, configName) {
|
|
|
11
17
|
{
|
|
12
18
|
severity: "error",
|
|
13
19
|
code: "check.no-tsconfig",
|
|
14
|
-
file:
|
|
20
|
+
file: relative(displayRoot, configPath).split("\\").join("/"),
|
|
15
21
|
message: "tsconfig.json not found. Run 'kdf init' or extend @sf-kmods/kdataforgejs/tsconfig.base.json.",
|
|
16
22
|
},
|
|
17
23
|
];
|
|
18
24
|
}
|
|
19
25
|
const read = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
20
26
|
if (read.error !== undefined)
|
|
21
|
-
return [toDiagnostic(read.error,
|
|
27
|
+
return [toDiagnostic(read.error, displayRoot)];
|
|
22
28
|
const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, dirname(configPath), undefined, configPath);
|
|
23
29
|
const program = ts.createProgram({ rootNames: parsed.fileNames, options: { ...parsed.options, noEmit: true } });
|
|
24
|
-
return [...parsed.errors, ...ts.getPreEmitDiagnostics(program)].map((d) => toDiagnostic(d,
|
|
30
|
+
return [...parsed.errors, ...ts.getPreEmitDiagnostics(program)].map((d) => toDiagnostic(d, displayRoot));
|
|
25
31
|
}
|
|
26
32
|
function toDiagnostic(diagnostic, projectRoot) {
|
|
27
33
|
let file = "tsconfig.json";
|
package/dist/commands/dev.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { watch, readFileSync, readdirSync, existsSync } from "node:fs";
|
|
2
2
|
import { join, resolve, sep } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { discoverPacks } from "../pack/discover.js";
|
|
4
4
|
import { checkProject } from "./check.js";
|
|
5
5
|
import { lintProject } from "./lint.js";
|
|
6
6
|
import { syncProject } from "./sync.js";
|
|
@@ -9,7 +9,16 @@ import { formatDiagnostic, hasErrors } from "../diagnostics.js";
|
|
|
9
9
|
const IGNORED = new Set(["node_modules", "typescript", ".kdataforge", ".git"]);
|
|
10
10
|
const DEBOUNCE_MS = 200;
|
|
11
11
|
/** Watches authored files. Generated manifests and declarations cannot feed the watcher. */
|
|
12
|
-
export function startDev(directory, io) {
|
|
12
|
+
export function startDev(directory, io, packRef) {
|
|
13
|
+
const selection = discoverPacks(directory, packRef);
|
|
14
|
+
const projects = [...new Set(selection.packs.map((pack) => pack.projectRoot))];
|
|
15
|
+
const watchers = projects.map((project) => startProjectDev(project, projects.length === 1 ? io : {
|
|
16
|
+
out: (line) => io.out(`${project}: ${line}`), err: (line) => io.err(`${project}: ${line}`),
|
|
17
|
+
}, packRef));
|
|
18
|
+
return { close: () => { for (const watcher of watchers)
|
|
19
|
+
watcher.close(); } };
|
|
20
|
+
}
|
|
21
|
+
function startProjectDev(directory, io, packRef) {
|
|
13
22
|
const root = resolve(directory);
|
|
14
23
|
const dataForge = join(root, "DataForge");
|
|
15
24
|
if (!existsSync(dataForge))
|
|
@@ -64,12 +73,12 @@ export function startDev(directory, io) {
|
|
|
64
73
|
while (dirty && !closed) {
|
|
65
74
|
dirty = false;
|
|
66
75
|
try {
|
|
67
|
-
syncProject(root);
|
|
68
|
-
for (const pack of
|
|
76
|
+
syncProject(root, packRef);
|
|
77
|
+
for (const pack of discoverPacks(root, packRef).packs.map((item) => item.root)) {
|
|
69
78
|
const path = join(pack, "pack.yml");
|
|
70
79
|
generatedManifests.set(path, readFileSync(path, "utf8"));
|
|
71
80
|
}
|
|
72
|
-
const diagnostics = [...checkProject(root), ...lintProject(root), ...validateProject(root)];
|
|
81
|
+
const diagnostics = [...checkProject(root, undefined, packRef), ...lintProject(root, packRef), ...validateProject(root, packRef)];
|
|
73
82
|
for (const diagnostic of diagnostics)
|
|
74
83
|
io.err(formatDiagnostic(diagnostic));
|
|
75
84
|
if (hasErrors(diagnostics))
|
package/dist/commands/doctor.js
CHANGED
|
@@ -6,8 +6,10 @@ import { validateProject } from "./validate.js";
|
|
|
6
6
|
import { lintProject } from "./lint.js";
|
|
7
7
|
import { detectGameInstallations, resolveGameInstallation } from "../game/installations.js";
|
|
8
8
|
import { hasErrors } from "../diagnostics.js";
|
|
9
|
+
import { discoverPacks } from "../pack/discover.js";
|
|
10
|
+
import { inspectGameData } from "./gameData.js";
|
|
9
11
|
/** Read-only health report. Unknown means the check could not be run. */
|
|
10
|
-
export function doctorProject(directory, gamePath) {
|
|
12
|
+
export function doctorProject(directory, gamePath, packRef) {
|
|
11
13
|
const root = resolve(directory);
|
|
12
14
|
const checks = [];
|
|
13
15
|
checks.push({ name: "node", status: Number(process.versions.node.split(".")[0]) >= 20 ? "pass" : "fail",
|
|
@@ -17,9 +19,9 @@ export function doctorProject(directory, gamePath) {
|
|
|
17
19
|
return checks;
|
|
18
20
|
}
|
|
19
21
|
for (const [name, run] of [
|
|
20
|
-
["validate", () => validateProject(root)],
|
|
21
|
-
["check", () => checkProject(root)],
|
|
22
|
-
["lint", () => lintProject(root)],
|
|
22
|
+
["validate", () => validateProject(root, packRef)],
|
|
23
|
+
["check", () => checkProject(root, undefined, packRef)],
|
|
24
|
+
["lint", () => lintProject(root, packRef)],
|
|
23
25
|
]) {
|
|
24
26
|
try {
|
|
25
27
|
const diagnostics = run();
|
|
@@ -30,9 +32,10 @@ export function doctorProject(directory, gamePath) {
|
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
try {
|
|
33
|
-
const drift = inspectSyncDrift(root)
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
const drift = inspectSyncDrift(root, packRef);
|
|
36
|
+
const changed = [...drift.changedPacks, ...drift.changedTypes];
|
|
37
|
+
checks.push({ name: "manifest", status: changed.length === 0 ? "pass" : "warn",
|
|
38
|
+
message: changed.length === 0 ? "Manifest and config types synchronized" : `Run kdf sync: ${changed.map((path) => relative(root, path)).join(", ")}` });
|
|
36
39
|
}
|
|
37
40
|
catch (error) {
|
|
38
41
|
checks.push({ name: "manifest", status: "unknown", message: error instanceof Error ? error.message : String(error) });
|
|
@@ -45,9 +48,31 @@ export function doctorProject(directory, gamePath) {
|
|
|
45
48
|
catch (error) {
|
|
46
49
|
checks.push({ name: "installation", status: "unknown", message: error instanceof Error ? error.message : String(error) });
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
try {
|
|
52
|
+
const selection = discoverPacks(root, packRef);
|
|
53
|
+
const projects = [...new Set(selection.packs.map((pack) => pack.projectRoot))];
|
|
54
|
+
if (selection.workspace) {
|
|
55
|
+
const rootLocks = ["package-lock.json", "pnpm-lock.yaml"].filter((name) => existsSync(join(root, name)));
|
|
56
|
+
const nested = projects.filter((project) => project !== root &&
|
|
57
|
+
["package-lock.json", "pnpm-lock.yaml"].some((name) => existsSync(join(project, name))));
|
|
58
|
+
checks.push({ name: "lockfile", status: rootLocks.length > 1 ? "fail" : rootLocks.length === 0 || nested.length > 0 ? "warn" : "pass",
|
|
59
|
+
message: rootLocks.length > 1 ? "Both npm and pnpm root lockfiles exist" : nested.length > 0
|
|
60
|
+
? `Nested lockfiles: ${nested.map((path) => relative(root, path)).join(", ")}`
|
|
61
|
+
: rootLocks.length === 0 ? "No root lockfile found" : `Root lockfile: ${rootLocks[0]}` });
|
|
62
|
+
}
|
|
63
|
+
const health = inspectGameData(root, projects, gamePath);
|
|
64
|
+
checks.push({ name: "game-data", status: health.status === "current" ? "pass" : health.status === "stale" ? "warn" : "unknown",
|
|
65
|
+
message: health.message });
|
|
66
|
+
for (const project of projects) {
|
|
67
|
+
const types = join(project, "DataForge/typescript/kdataforgejs/index.d.ts");
|
|
68
|
+
checks.push({ name: `reflection-types:${relative(root, project) || "."}`, status: existsSync(types) ? "pass" : "warn",
|
|
69
|
+
message: existsSync(types) ? `Types available: ${types}` : `Generated types missing: ${types}` });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
checks.push({ name: "game-data", status: "unknown", message: error instanceof Error ? error.message : String(error) });
|
|
74
|
+
checks.push({ name: "reflection-types", status: "unknown", message: error instanceof Error ? error.message : String(error) });
|
|
75
|
+
}
|
|
51
76
|
return checks;
|
|
52
77
|
}
|
|
53
78
|
function fromDiagnostics(name, diagnostics) {
|
package/dist/commands/format.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
import { existsSync, readFileSync
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { discoverPacks } from "../pack/discover.js";
|
|
3
4
|
import { findScriptFiles } from "../pack/scriptFiles.js";
|
|
5
|
+
import { commitStaged, stageTexts, withProjectLock } from "../pack/transaction.js";
|
|
4
6
|
import { biome, biomeProjectKey } from "../types/biome.js";
|
|
5
7
|
/** Formats JavaScript and TypeScript files in DataForge/scripts through bundled Biome. */
|
|
6
|
-
export function formatProject(projectRoot) {
|
|
8
|
+
export function formatProject(projectRoot, packRef) {
|
|
7
9
|
const absoluteProjectRoot = resolve(projectRoot);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
discoverPacks(absoluteProjectRoot, packRef);
|
|
11
|
+
return withProjectLock(absoluteProjectRoot, () => {
|
|
12
|
+
const scriptsRoots = discoverPacks(absoluteProjectRoot, packRef).packs.map((pack) => join(pack.root, "scripts"));
|
|
13
|
+
for (const scriptsRoot of scriptsRoots)
|
|
14
|
+
if (!existsSync(scriptsRoot))
|
|
15
|
+
throw new Error(`Scripts directory not found: ${scriptsRoot}`);
|
|
16
|
+
const files = new Set(scriptsRoots.flatMap(findScriptFiles));
|
|
17
|
+
const formattedFiles = [...files].sort().map((filePath) => formatFile(filePath, absoluteProjectRoot))
|
|
18
|
+
.filter((file) => file !== undefined);
|
|
19
|
+
commitStaged(stageTexts(formattedFiles));
|
|
20
|
+
return { changedFiles: formattedFiles.map((file) => shownPath(file.path, absoluteProjectRoot)) };
|
|
21
|
+
});
|
|
17
22
|
}
|
|
18
23
|
function formatFile(filePath, projectRoot) {
|
|
19
24
|
const original = readFileSync(filePath, "utf8");
|