@sf-kmods/kdataforgejs-cli 2026.4.16 → 2026.4.20
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 +28 -3
- package/dist/cli.js +26 -1
- package/dist/commands/format.js +29 -0
- package/dist/commands/gameData.js +11 -4
- package/dist/commands/lint.js +43 -0
- package/dist/commands/sync.js +99 -0
- package/dist/pack/scriptFiles.js +14 -0
- package/dist/pack/usage.js +102 -0
- package/dist/types/biome.js +25 -0
- package/dist/types/configTypes.js +74 -0
- package/dist/types/contentTypes.js +152 -0
- package/dist/types/format.js +9 -0
- package/dist/types/organize.js +186 -0
- package/package.json +6 -2
- package/schemas/actor-selector.schema.yml +39 -0
- package/schemas/asset.schema.yml +27 -0
- package/schemas/building.schema.yml +16 -0
- package/schemas/category_reorder.schema.yml +41 -0
- package/schemas/cdo.schema.yml +92 -0
- package/schemas/class.schema.yml +27 -0
- package/schemas/common.schema.yml +543 -0
- package/schemas/config.schema.yml +208 -0
- package/schemas/curve.schema.yml +59 -0
- package/schemas/dataasset.schema.yml +33 -0
- package/schemas/eventrule.schema.yml +47 -0
- package/schemas/gametag.schema.yml +24 -0
- package/schemas/item.schema.yml +16 -0
- package/schemas/localization.schema.yml +27 -0
- package/schemas/mam.schema.yml +5 -0
- package/schemas/pack.schema.yml +60 -0
- package/schemas/recipe.schema.yml +26 -0
- package/schemas/research.schema.yml +76 -0
- package/schemas/resource.schema.yml +16 -0
- package/schemas/resourcenode.schema.yml +117 -0
- package/schemas/schematic.schema.yml +75 -0
- package/schemas/sinkpoints.schema.yml +29 -0
- package/schemas/sound.schema.yml +45 -0
- package/schemas/sublevel.schema.yml +16 -0
- package/schemas/unlock.schema.yml +21 -0
- package/templates/default/DataForge/scripts/lib.ts +1 -1
- package/templates/default/DataForge/scripts/main.ts +2 -2
- package/templates/default/README.md +8 -2
- package/templates/default/_gitignore +1 -0
- package/templates/default/package.json +7 -1
package/README.md
CHANGED
|
@@ -15,9 +15,12 @@ npm run verify
|
|
|
15
15
|
| --- | --- |
|
|
16
16
|
| `kdf init [dir]` | Creates a project: `package.json`, `tsconfig.json` and a `DataForge/` pack with `pack.yml` and `scripts/main.ts`. `--name` sets the pack ref, `--force` writes into a non-empty folder. |
|
|
17
17
|
| `kdf check [dir]` | Type-checks the project against `@sf-kmods/kdataforgejs` with the bundled TypeScript. Nothing is emitted. |
|
|
18
|
+
| `kdf format [dir]` | Formats JavaScript and TypeScript files below `DataForge/scripts/` with bundled Biome. |
|
|
19
|
+
| `kdf lint [dir]` | Lints JavaScript and TypeScript files below `DataForge/scripts/` with bundled Biome recommended rules. |
|
|
18
20
|
| `kdf validate [dir]` | Checks `pack.yml`, the entry file, the static import graph and the digests of declared imports. |
|
|
21
|
+
| `kdf sync [dir]` | Generates sorted `imports`, SHA-256 digests, `reflectionClasses`, and pack-local config key/value types. |
|
|
19
22
|
| `kdf hash [dir]` | Rewrites stale `sha256` values of declared imports and leaves your comments alone. |
|
|
20
|
-
| `kdf game-data [dir]` |
|
|
23
|
+
| `kdf game-data [dir]` | Runs manifest sync, finds a modded Satisfactory installation, starts a full reflection export, closes the game and imports the archive plus generated TypeScript declarations. Use `--game-path <root-or-executable>` to select an installation explicitly; add `--content-types` for schema-derived content document types. |
|
|
21
24
|
|
|
22
25
|
Exit code `0` means all good, `1` means findings, `2` means the command was used wrong.
|
|
23
26
|
|
|
@@ -25,7 +28,13 @@ Exit code `0` means all good, `1` means findings, `2` means the command was used
|
|
|
25
28
|
It does not replace the runtime: catalog, authority and limits are still decided in game.
|
|
26
29
|
|
|
27
30
|
The generated project keeps `package.json` and `tsconfig.json` next to the `DataForge` folder, never inside it. The pack
|
|
28
|
-
itself has no `node_modules`.
|
|
31
|
+
itself has no `node_modules`. `npm run refresh` runs `kdf game-data`; `npm run fix` formats scripts and synchronizes
|
|
32
|
+
generated manifest fields. `format`, `lint`, `check`, `validate`, `hash`, `sync`, `test`, and `verify` are available too.
|
|
33
|
+
|
|
34
|
+
Literal `ctx.import(kind, path)` calls and reflected paths used by `ctx.getClass`, `ctx.getObject` and
|
|
35
|
+
`ctx.getDataAsset` are source of truth. YAML imports are scanned for `target` paths. Run `kdf sync`; do not maintain
|
|
36
|
+
manifest import digests or reflection class lists by hand. Dynamic import paths are rejected because CLI cannot grant
|
|
37
|
+
their authority safely.
|
|
29
38
|
|
|
30
39
|
## Import game data
|
|
31
40
|
|
|
@@ -47,4 +56,20 @@ The CLI loads the newest local save automatically, starts a full reflection expo
|
|
|
47
56
|
minutes by default; override this with `--timeout <seconds>`. It writes `.kdataforge/satisfactory.kdfdata`, imports
|
|
48
57
|
generated declarations below `DataForge/typescript/kdataforgejs/`, creates `tsconfig.kdf.json`, and makes later
|
|
49
58
|
`kdf check` calls use those installed-game types automatically. `.kdataforge/` is added to `.gitignore` because the
|
|
50
|
-
archive can be large.
|
|
59
|
+
archive can be large. Declarations are split into `runtime.d.ts`, `globals.d.ts`, alphabetical `satisfactory/` groups,
|
|
60
|
+
and Unreal-path `paths/` groups behind `index.d.ts`. Biome formats generated TypeScript and JSON through its JavaScript
|
|
61
|
+
API. Projects created by `kdf init` also ignore `DataForge/typescript/kdataforgejs/`; regenerate it for the local game
|
|
62
|
+
and mod set. Temporary export and staging directories are removed after the game exits.
|
|
63
|
+
|
|
64
|
+
`kdf game-data --content-types` opts into schema-derived document entries for `applyDocument`, including schematics,
|
|
65
|
+
research, unlocks, buildings and DataAssets. Field names and structural types are checked locally; runtime validation
|
|
66
|
+
still enforces ranges, conditional rules, reflection, capabilities and lifecycle. Export without the flag to restore
|
|
67
|
+
generic content types. The schemas ship in the CLI package; generation does not fetch schema URLs.
|
|
68
|
+
|
|
69
|
+
`kdf sync` writes `DataForge/typescript/kdataforgejs-config.d.ts` from authored `*.config.yml`/`*.config.yaml` fields.
|
|
70
|
+
These keys type `ctx.config.get` and `onChange`; runtime access still requires `kdf.config.read`. Regenerate the file
|
|
71
|
+
after changing config definitions. Keep generated files outside your source edits.
|
|
72
|
+
|
|
73
|
+
For CLI maintenance, `pnpm run sync:schemas` refreshes the checked-in `schemas/` snapshot from the workspace's
|
|
74
|
+
`kdataforge-editor/crates/kdf-validation/schemas/`. Normal builds and installed packages use the bundled snapshot and
|
|
75
|
+
do not require a separate editor checkout.
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { checkProject } from "./commands/check.js";
|
|
3
|
+
import { formatProject } from "./commands/format.js";
|
|
3
4
|
import { importGameData } from "./commands/gameData.js";
|
|
4
5
|
import { hashProject } from "./commands/hash.js";
|
|
5
6
|
import { initProject } from "./commands/init.js";
|
|
7
|
+
import { lintProject } from "./commands/lint.js";
|
|
8
|
+
import { syncProject } from "./commands/sync.js";
|
|
6
9
|
import { validateProject } from "./commands/validate.js";
|
|
7
10
|
import { formatDiagnostic, hasErrors } from "./diagnostics.js";
|
|
8
11
|
const USAGE = `kdf - KDataForgeJS project tooling
|
|
@@ -10,9 +13,12 @@ const USAGE = `kdf - KDataForgeJS project tooling
|
|
|
10
13
|
Usage:
|
|
11
14
|
kdf init [dir] [--name <PackRef>] [--force] Create a new KDataForge project with a TypeScript script
|
|
12
15
|
kdf check [dir] Type-check the project (tsconfig.json, no emit)
|
|
16
|
+
kdf format [dir] Format DataForge scripts with bundled Biome
|
|
17
|
+
kdf lint [dir] Lint DataForge scripts with bundled Biome rules
|
|
13
18
|
kdf validate [dir] Check pack.yml, entry, static imports and import digests
|
|
19
|
+
kdf sync [dir] Generate imports, hashes and reflection classes from source
|
|
14
20
|
kdf hash [dir] Update sha256 of declared script imports in pack.yml
|
|
15
|
-
kdf game-data [dir] [--game-path <path>]
|
|
21
|
+
kdf game-data [dir] [--game-path <path>] [--content-types] Export game data; optionally generate schema-derived content types
|
|
16
22
|
kdf --help | --version
|
|
17
23
|
`;
|
|
18
24
|
const DEFAULT_DEPENDENCIES = { importGameData };
|
|
@@ -30,6 +36,7 @@ async function runCli(request, dependencies) {
|
|
|
30
36
|
name: { type: "string" },
|
|
31
37
|
"game-path": { type: "string" },
|
|
32
38
|
timeout: { type: "string" },
|
|
39
|
+
"content-types": { type: "boolean", default: false },
|
|
33
40
|
force: { type: "boolean", default: false },
|
|
34
41
|
help: { type: "boolean", short: "h", default: false },
|
|
35
42
|
version: { type: "boolean", short: "v", default: false },
|
|
@@ -50,19 +57,37 @@ async function runCli(request, dependencies) {
|
|
|
50
57
|
}
|
|
51
58
|
case "check":
|
|
52
59
|
return report(io, checkProject(directory), "Type check passed.");
|
|
60
|
+
case "format": {
|
|
61
|
+
const result = formatProject(directory);
|
|
62
|
+
io.out(result.changedFiles.length === 0
|
|
63
|
+
? "Files are already formatted."
|
|
64
|
+
: `Formatted files:\n${result.changedFiles.join("\n")}`);
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
case "lint":
|
|
68
|
+
return report(io, lintProject(directory), "Lint passed.");
|
|
53
69
|
case "validate":
|
|
54
70
|
return report(io, validateProject(directory), "Pack is valid.");
|
|
71
|
+
case "sync": {
|
|
72
|
+
const result = syncProject(directory);
|
|
73
|
+
io.out(result.changedPacks.length === 0
|
|
74
|
+
? "Manifest is already synchronized."
|
|
75
|
+
: `Synchronized manifests:\n${result.changedPacks.join("\n")}`);
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
55
78
|
case "hash": {
|
|
56
79
|
const changed = hashProject(directory);
|
|
57
80
|
io.out(changed.length === 0 ? "All import digests are up to date." : `Updated digests:\n${changed.join("\n")}`);
|
|
58
81
|
return 0;
|
|
59
82
|
}
|
|
60
83
|
case "game-data": {
|
|
84
|
+
syncProject(directory);
|
|
61
85
|
const timeoutMilliseconds = parseTimeout(values.timeout);
|
|
62
86
|
const result = await dependencies.importGameData({
|
|
63
87
|
destination: directory,
|
|
64
88
|
...(values["game-path"] ? { gamePath: values["game-path"] } : {}),
|
|
65
89
|
...(timeoutMilliseconds === undefined ? {} : { timeoutMilliseconds }),
|
|
90
|
+
...(values["content-types"] ? { contentTypes: true } : {}),
|
|
66
91
|
});
|
|
67
92
|
io.out(`Imported game data from ${result.installation.root}`);
|
|
68
93
|
io.out(`Archive: ${result.archivePath}`);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { findScriptFiles } from "../pack/scriptFiles.js";
|
|
4
|
+
import { biome, biomeProjectKey } from "../types/biome.js";
|
|
5
|
+
/** Formats JavaScript and TypeScript files in DataForge/scripts through bundled Biome. */
|
|
6
|
+
export function formatProject(projectRoot) {
|
|
7
|
+
const absoluteProjectRoot = resolve(projectRoot);
|
|
8
|
+
const scriptsRoot = join(absoluteProjectRoot, "DataForge/scripts");
|
|
9
|
+
if (!existsSync(scriptsRoot))
|
|
10
|
+
throw new Error("DataForge/scripts not found. Run 'kdf init' or pass project root.");
|
|
11
|
+
const formattedFiles = findScriptFiles(scriptsRoot)
|
|
12
|
+
.map((filePath) => formatFile(filePath, absoluteProjectRoot))
|
|
13
|
+
.filter((file) => file !== undefined);
|
|
14
|
+
for (const file of formattedFiles)
|
|
15
|
+
writeFileSync(file.path, file.content);
|
|
16
|
+
return { changedFiles: formattedFiles.map((file) => shownPath(file.path, absoluteProjectRoot)) };
|
|
17
|
+
}
|
|
18
|
+
function formatFile(filePath, projectRoot) {
|
|
19
|
+
const original = readFileSync(filePath, "utf8");
|
|
20
|
+
const result = biome.formatContent(biomeProjectKey, original, { filePath });
|
|
21
|
+
if (result.diagnostics.length > 0) {
|
|
22
|
+
const messages = result.diagnostics.map((diagnostic) => diagnostic.description).join("; ");
|
|
23
|
+
throw new Error(`${shownPath(filePath, projectRoot)}: Biome format failed: ${messages}`);
|
|
24
|
+
}
|
|
25
|
+
return result.content === original ? undefined : { path: filePath, content: result.content };
|
|
26
|
+
}
|
|
27
|
+
function shownPath(filePath, projectRoot) {
|
|
28
|
+
return relative(projectRoot, filePath).split(sep).join("/");
|
|
29
|
+
}
|
|
@@ -3,6 +3,8 @@ import { appendFileSync, copyFileSync, cpSync, existsSync, mkdirSync, mkdtempSyn
|
|
|
3
3
|
import { homedir, tmpdir } from "node:os";
|
|
4
4
|
import { basename, extname, join, resolve } from "node:path";
|
|
5
5
|
import { detectGameInstallations, resolveGameInstallation, supportedPlatform } from "../game/installations.js";
|
|
6
|
+
import { formatGeneratedContent } from "../types/format.js";
|
|
7
|
+
import { organizeGeneratedDeclarations } from "../types/organize.js";
|
|
6
8
|
const DEFAULT_TIMEOUT_MILLISECONDS = 15 * 60 * 1_000;
|
|
7
9
|
const POLL_INTERVAL_MILLISECONDS = 500;
|
|
8
10
|
export async function importGameData(options, dependencies = {}) {
|
|
@@ -17,7 +19,7 @@ export async function importGameData(options, dependencies = {}) {
|
|
|
17
19
|
const plan = createLaunchPlan(installation, platform, exportDirectory, savePath);
|
|
18
20
|
const launchedGame = await (dependencies.launch ?? launchGame)(plan);
|
|
19
21
|
const artifacts = await waitForExport(exportDirectory, timeoutMilliseconds, dependencies.sleep ?? delay, launchedGame?.exited);
|
|
20
|
-
const result = installExport(destination, installation, artifacts);
|
|
22
|
+
const result = installExport({ ...options, destination }, installation, artifacts);
|
|
21
23
|
if (launchedGame !== undefined)
|
|
22
24
|
await waitForCleanGameExit(launchedGame.exited);
|
|
23
25
|
return result;
|
|
@@ -178,7 +180,8 @@ function findCompletedExport(exportDirectory) {
|
|
|
178
180
|
}
|
|
179
181
|
return { archive, typesDirectory };
|
|
180
182
|
}
|
|
181
|
-
function installExport(
|
|
183
|
+
function installExport(options, installation, artifacts) {
|
|
184
|
+
const destination = options.destination;
|
|
182
185
|
mkdirSync(destination, { recursive: true });
|
|
183
186
|
const archiveDirectory = join(destination, ".kdataforge");
|
|
184
187
|
mkdirSync(archiveDirectory, { recursive: true });
|
|
@@ -188,8 +191,12 @@ function installExport(destination, installation, artifacts) {
|
|
|
188
191
|
rmSync(typesDirectory, { recursive: true, force: true });
|
|
189
192
|
mkdirSync(typesDirectory, { recursive: true });
|
|
190
193
|
cpSync(artifacts.typesDirectory, typesDirectory, { recursive: true });
|
|
191
|
-
const declarationPath =
|
|
192
|
-
|
|
194
|
+
const declarationPath = organizeGeneratedDeclarations(typesDirectory, { contentTypes: options.contentTypes });
|
|
195
|
+
const tsconfigPath = join(destination, "tsconfig.kdf.json");
|
|
196
|
+
writeFileSync(tsconfigPath, formatGeneratedContent(JSON.stringify({
|
|
197
|
+
extends: "./DataForge/typescript/kdataforgejs/tsconfig.json",
|
|
198
|
+
include: ["DataForge/**/*.ts"],
|
|
199
|
+
}), tsconfigPath));
|
|
193
200
|
ensureGitIgnoreEntry(destination, ".kdataforge/");
|
|
194
201
|
return { installation, archivePath, declarationPath };
|
|
195
202
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { spanInBytesToSpanInCodeUnits } from "@biomejs/js-api/nodejs";
|
|
4
|
+
import { findScriptFiles } from "../pack/scriptFiles.js";
|
|
5
|
+
import { biome, biomeProjectKey } from "../types/biome.js";
|
|
6
|
+
/** Lints every JavaScript and TypeScript source file in DataForge/scripts with bundled Biome rules. */
|
|
7
|
+
export function lintProject(projectRoot) {
|
|
8
|
+
const absoluteProjectRoot = resolve(projectRoot);
|
|
9
|
+
const scriptsRoot = join(absoluteProjectRoot, "DataForge/scripts");
|
|
10
|
+
if (!existsSync(scriptsRoot)) {
|
|
11
|
+
return [{
|
|
12
|
+
severity: "error",
|
|
13
|
+
code: "lint.no-scripts",
|
|
14
|
+
file: "DataForge/scripts",
|
|
15
|
+
message: "Scripts directory not found. Run 'kdf init' or pass project root.",
|
|
16
|
+
}];
|
|
17
|
+
}
|
|
18
|
+
return findScriptFiles(scriptsRoot).flatMap((filePath) => lintFile(filePath, absoluteProjectRoot));
|
|
19
|
+
}
|
|
20
|
+
function lintFile(filePath, projectRoot) {
|
|
21
|
+
const content = readFileSync(filePath, "utf8");
|
|
22
|
+
return biome.lintContent(biomeProjectKey, content, { filePath }).diagnostics
|
|
23
|
+
.filter((diagnostic) => !diagnostic.category?.startsWith("assist/"))
|
|
24
|
+
.map((diagnostic) => toDiagnostic(diagnostic, content, filePath, projectRoot));
|
|
25
|
+
}
|
|
26
|
+
function toDiagnostic(diagnostic, content, filePath, projectRoot) {
|
|
27
|
+
const location = diagnostic.location.span === undefined ? "" : diagnosticLocation(diagnostic.location.span, content);
|
|
28
|
+
const shownPath = relative(projectRoot, filePath).split(sep).join("/");
|
|
29
|
+
return {
|
|
30
|
+
severity: diagnostic.severity === "error" || diagnostic.severity === "fatal" ? "error" : "warning",
|
|
31
|
+
code: diagnostic.category ?? "biome",
|
|
32
|
+
file: `${shownPath}${location}`,
|
|
33
|
+
message: diagnostic.description,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function diagnosticLocation(span, content) {
|
|
37
|
+
const [start] = spanInBytesToSpanInCodeUnits(span, content);
|
|
38
|
+
const before = content.slice(0, start);
|
|
39
|
+
const line = before.split("\n").length;
|
|
40
|
+
const lastNewline = before.lastIndexOf("\n");
|
|
41
|
+
const column = start - lastNewline;
|
|
42
|
+
return `:${line}:${column}`;
|
|
43
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { isMap, isSeq, parseDocument, YAMLMap, YAMLSeq } from "yaml";
|
|
4
|
+
import { findPackRoots } from "../pack/discover.js";
|
|
5
|
+
import { sha256Of } from "../pack/imports.js";
|
|
6
|
+
import { discoverPackUsage } from "../pack/usage.js";
|
|
7
|
+
import { syncConfigTypes } from "../types/configTypes.js";
|
|
8
|
+
/** Generates manifest imports, digests, and reflection class authority from source usage. */
|
|
9
|
+
export function syncProject(projectRoot) {
|
|
10
|
+
if (!existsSync(projectRoot))
|
|
11
|
+
return { changedPacks: [] };
|
|
12
|
+
const changedPacks = findPackRoots(projectRoot).filter(syncPack);
|
|
13
|
+
return { changedPacks };
|
|
14
|
+
}
|
|
15
|
+
function syncPack(packRoot) {
|
|
16
|
+
const manifestFile = join(packRoot, "pack.yml");
|
|
17
|
+
const before = readFileSync(manifestFile, "utf8");
|
|
18
|
+
const document = parseDocument(before);
|
|
19
|
+
const scripts = document.get("scripts", true);
|
|
20
|
+
if (!isSeq(scripts))
|
|
21
|
+
return false;
|
|
22
|
+
syncConfigTypes(packRoot);
|
|
23
|
+
for (const script of scripts.items) {
|
|
24
|
+
if (!isMap(script))
|
|
25
|
+
continue;
|
|
26
|
+
const entry = String(script.get("entry") ?? "");
|
|
27
|
+
if (entry === "")
|
|
28
|
+
continue;
|
|
29
|
+
const usage = discoverPackUsage(packRoot, entry);
|
|
30
|
+
setSequence(script, "reflectionClasses", usage.reflectionClasses);
|
|
31
|
+
setImports(script, packRoot, usage.imports);
|
|
32
|
+
}
|
|
33
|
+
const after = document.toString();
|
|
34
|
+
if (after === before)
|
|
35
|
+
return false;
|
|
36
|
+
writeFileSync(manifestFile, after);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
function setSequence(map, key, values) {
|
|
40
|
+
if (values.length === 0) {
|
|
41
|
+
map.delete(key);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const sequence = new YAMLSeq();
|
|
45
|
+
sequence.items = [...values];
|
|
46
|
+
map.set(key, sequence);
|
|
47
|
+
}
|
|
48
|
+
function setImports(script, packRoot, imports) {
|
|
49
|
+
if (imports.length === 0) {
|
|
50
|
+
script.delete("imports");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const oldKeys = existingKeys(script);
|
|
54
|
+
const usedKeys = new Set();
|
|
55
|
+
const sequence = new YAMLSeq();
|
|
56
|
+
sequence.items = imports.map((item) => {
|
|
57
|
+
const target = join(packRoot, item.path);
|
|
58
|
+
if (!existsSync(target))
|
|
59
|
+
throw new Error(`Imported file '${item.path}' does not exist in ${packRoot}.`);
|
|
60
|
+
const preferred = oldKeys.get(`${item.kind}\n${item.path}`) ?? keyFrom(item);
|
|
61
|
+
const key = uniqueKey(preferred, usedKeys);
|
|
62
|
+
usedKeys.add(key);
|
|
63
|
+
const map = new YAMLMap();
|
|
64
|
+
map.set("key", key);
|
|
65
|
+
map.set("kind", item.kind);
|
|
66
|
+
map.set("path", item.path);
|
|
67
|
+
map.set("sha256", sha256Of(target));
|
|
68
|
+
return map;
|
|
69
|
+
});
|
|
70
|
+
script.set("imports", sequence);
|
|
71
|
+
}
|
|
72
|
+
function existingKeys(script) {
|
|
73
|
+
const result = new Map();
|
|
74
|
+
const imports = script.get("imports", true);
|
|
75
|
+
if (!isSeq(imports))
|
|
76
|
+
return result;
|
|
77
|
+
for (const item of imports.items) {
|
|
78
|
+
if (!isMap(item))
|
|
79
|
+
continue;
|
|
80
|
+
const kind = String(item.get("kind") ?? "");
|
|
81
|
+
const path = String(item.get("path") ?? "");
|
|
82
|
+
const key = String(item.get("key") ?? "");
|
|
83
|
+
if (kind !== "" && path !== "" && key !== "")
|
|
84
|
+
result.set(`${kind}\n${path}`, key);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
function keyFrom(item) {
|
|
89
|
+
const normalized = item.path.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
90
|
+
return normalized === "" ? item.kind : normalized;
|
|
91
|
+
}
|
|
92
|
+
function uniqueKey(preferred, used) {
|
|
93
|
+
if (!used.has(preferred))
|
|
94
|
+
return preferred;
|
|
95
|
+
let suffix = 2;
|
|
96
|
+
while (used.has(`${preferred}-${suffix}`))
|
|
97
|
+
suffix += 1;
|
|
98
|
+
return `${preferred}-${suffix}`;
|
|
99
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
2
|
+
import { extname, join } from "node:path";
|
|
3
|
+
const SCRIPT_EXTENSIONS = new Set([".js", ".ts"]);
|
|
4
|
+
export function findScriptFiles(directory) {
|
|
5
|
+
const files = [];
|
|
6
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
7
|
+
const path = join(directory, entry.name);
|
|
8
|
+
if (entry.isDirectory())
|
|
9
|
+
files.push(...findScriptFiles(path));
|
|
10
|
+
else if (entry.isFile() && SCRIPT_EXTENSIONS.has(extname(entry.name).toLocaleLowerCase()))
|
|
11
|
+
files.push(path);
|
|
12
|
+
}
|
|
13
|
+
return files.sort((left, right) => left.localeCompare(right));
|
|
14
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, extname, relative, resolve, sep } from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { parse } from "yaml";
|
|
5
|
+
import { RUNTIME_MODULE, SATISFACTORY_MODULE } from "../conventions.js";
|
|
6
|
+
const REFLECTION_METHODS = new Set(["getClass", "getObject", "getDataAsset"]);
|
|
7
|
+
/** Discovers manifest authority inputs from reachable TypeScript and imported YAML without executing pack code. */
|
|
8
|
+
export function discoverPackUsage(packRoot, entry) {
|
|
9
|
+
const entryFile = resolve(packRoot, entry);
|
|
10
|
+
const scriptsRoot = dirname(entryFile);
|
|
11
|
+
const queue = [entryFile];
|
|
12
|
+
const visited = new Set();
|
|
13
|
+
const imports = new Map();
|
|
14
|
+
const reflectionClasses = new Set();
|
|
15
|
+
while (queue.length > 0) {
|
|
16
|
+
const file = queue.pop();
|
|
17
|
+
if (visited.has(file))
|
|
18
|
+
continue;
|
|
19
|
+
visited.add(file);
|
|
20
|
+
if (!existsSync(file))
|
|
21
|
+
continue;
|
|
22
|
+
const source = ts.createSourceFile(file, readFileSync(file, "utf8"), ts.ScriptTarget.ES2020, true);
|
|
23
|
+
visit(source, (node) => {
|
|
24
|
+
const specifier = staticSpecifier(node);
|
|
25
|
+
if (specifier !== undefined) {
|
|
26
|
+
const target = resolveModule(scriptsRoot, file, specifier);
|
|
27
|
+
if (target !== undefined)
|
|
28
|
+
queue.push(target);
|
|
29
|
+
}
|
|
30
|
+
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression))
|
|
31
|
+
return;
|
|
32
|
+
const method = node.expression.name.text;
|
|
33
|
+
if (method === "import") {
|
|
34
|
+
const kind = stringLiteral(node.arguments[0]);
|
|
35
|
+
const path = stringLiteral(node.arguments[1]);
|
|
36
|
+
if (kind === undefined || path === undefined) {
|
|
37
|
+
throw new Error(`${shownPath(packRoot, file)}: ctx.import requires literal kind and path so CLI can secure manifest imports.`);
|
|
38
|
+
}
|
|
39
|
+
imports.set(`${kind}\n${path}`, { kind, path });
|
|
40
|
+
}
|
|
41
|
+
else if (REFLECTION_METHODS.has(method)) {
|
|
42
|
+
const path = stringLiteral(node.arguments[1]);
|
|
43
|
+
if (path !== undefined)
|
|
44
|
+
reflectionClasses.add(path);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
for (const item of imports.values()) {
|
|
49
|
+
if (item.kind !== "yaml")
|
|
50
|
+
continue;
|
|
51
|
+
const target = resolveInside(packRoot, item.path);
|
|
52
|
+
if (target === undefined || !existsSync(target))
|
|
53
|
+
continue;
|
|
54
|
+
collectYamlTargets(parse(readFileSync(target, "utf8")), reflectionClasses);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
imports: [...imports.values()].sort((left, right) => left.path.localeCompare(right.path) || left.kind.localeCompare(right.kind)),
|
|
58
|
+
reflectionClasses: [...reflectionClasses].sort((left, right) => left.localeCompare(right)),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function visit(node, callback) {
|
|
62
|
+
callback(node);
|
|
63
|
+
ts.forEachChild(node, (child) => visit(child, callback));
|
|
64
|
+
}
|
|
65
|
+
function staticSpecifier(node) {
|
|
66
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier !== undefined &&
|
|
67
|
+
ts.isStringLiteral(node.moduleSpecifier))
|
|
68
|
+
return node.moduleSpecifier.text;
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
function resolveModule(scriptsRoot, importer, specifier) {
|
|
72
|
+
if (specifier === RUNTIME_MODULE || specifier === SATISFACTORY_MODULE ||
|
|
73
|
+
(!specifier.startsWith("./") && !specifier.startsWith("../")))
|
|
74
|
+
return undefined;
|
|
75
|
+
const extension = extname(specifier);
|
|
76
|
+
const target = resolve(dirname(importer), extension === "" ? `${specifier}.ts` : specifier);
|
|
77
|
+
return relative(scriptsRoot, target).startsWith("..") ? undefined : target;
|
|
78
|
+
}
|
|
79
|
+
function stringLiteral(node) {
|
|
80
|
+
return node !== undefined && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : undefined;
|
|
81
|
+
}
|
|
82
|
+
function resolveInside(packRoot, path) {
|
|
83
|
+
const target = resolve(packRoot, path);
|
|
84
|
+
return relative(packRoot, target).startsWith("..") ? undefined : target;
|
|
85
|
+
}
|
|
86
|
+
function collectYamlTargets(value, targets) {
|
|
87
|
+
if (Array.isArray(value)) {
|
|
88
|
+
for (const item of value)
|
|
89
|
+
collectYamlTargets(item, targets);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (typeof value !== "object" || value === null)
|
|
93
|
+
return;
|
|
94
|
+
for (const [key, child] of Object.entries(value)) {
|
|
95
|
+
if (key === "target" && typeof child === "string" && child.startsWith("/"))
|
|
96
|
+
targets.add(child);
|
|
97
|
+
collectYamlTargets(child, targets);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function shownPath(packRoot, file) {
|
|
101
|
+
return relative(packRoot, file).split(sep).join("/");
|
|
102
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Biome } from "@biomejs/js-api/nodejs";
|
|
2
|
+
export const biome = new Biome();
|
|
3
|
+
export const { projectKey: biomeProjectKey } = biome.openProject();
|
|
4
|
+
biome.applyConfiguration(biomeProjectKey, {
|
|
5
|
+
assist: {
|
|
6
|
+
enabled: false,
|
|
7
|
+
},
|
|
8
|
+
formatter: {
|
|
9
|
+
indentStyle: "tab",
|
|
10
|
+
lineEnding: "lf",
|
|
11
|
+
lineWidth: 120,
|
|
12
|
+
trailingNewline: true,
|
|
13
|
+
},
|
|
14
|
+
linter: {
|
|
15
|
+
enabled: true,
|
|
16
|
+
rules: {
|
|
17
|
+
recommended: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
json: {
|
|
21
|
+
formatter: {
|
|
22
|
+
expand: "always",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { parse } from "yaml";
|
|
4
|
+
import { formatGeneratedContent } from "./format.js";
|
|
5
|
+
const CONFIG_ID = /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$/u;
|
|
6
|
+
const MAX_CONFIG_FILES = 256;
|
|
7
|
+
const MAX_FIELDS = 1024;
|
|
8
|
+
const MAX_DIRECTORY_DEPTH = 16;
|
|
9
|
+
/** Emits pack-local keys only; a generated map never grants config access to a script. */
|
|
10
|
+
export function syncConfigTypes(packRoot) {
|
|
11
|
+
const fields = new Map();
|
|
12
|
+
for (const path of configFiles(packRoot)) {
|
|
13
|
+
const document = parse(readFileSync(path, "utf8"));
|
|
14
|
+
const entries = asRecord(document)?.fields;
|
|
15
|
+
if (!Array.isArray(entries))
|
|
16
|
+
continue;
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const field = asRecord(entry);
|
|
19
|
+
if (field === undefined || typeof field.id !== "string" || !CONFIG_ID.test(field.id))
|
|
20
|
+
throw new Error(`Invalid config id in ${path}.`);
|
|
21
|
+
if (fields.has(field.id))
|
|
22
|
+
throw new Error(`Duplicate config id '${field.id}'.`);
|
|
23
|
+
if (fields.size >= MAX_FIELDS)
|
|
24
|
+
throw new Error("Config type generation exceeds field limit.");
|
|
25
|
+
fields.set(field.id, fieldType(field));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const path = join(packRoot, "typescript/kdataforgejs-config.d.ts");
|
|
29
|
+
const entries = [...fields].sort(([left], [right]) => left.localeCompare(right))
|
|
30
|
+
.map(([id, type]) => `readonly ${JSON.stringify(id)}: ${type};`).join("\n");
|
|
31
|
+
const content = formatGeneratedContent(`// Generated by kdf sync. Do not edit.\ndeclare module "@sf-kmods/kdataforgejs" { export interface ConfigValueMap {\n${entries}\n} }\n`, path);
|
|
32
|
+
if (!existsSync(path) || readFileSync(path, "utf8") !== content) {
|
|
33
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
34
|
+
writeFileSync(path, content);
|
|
35
|
+
}
|
|
36
|
+
return path;
|
|
37
|
+
}
|
|
38
|
+
function configFiles(root) {
|
|
39
|
+
const result = [];
|
|
40
|
+
const visit = (directory, depth) => {
|
|
41
|
+
if (depth > MAX_DIRECTORY_DEPTH)
|
|
42
|
+
throw new Error("Config type generation exceeds directory depth limit.");
|
|
43
|
+
for (const entry of readdirSync(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
|
|
44
|
+
if (entry.isSymbolicLink() || entry.name === "typescript" || entry.name.startsWith("."))
|
|
45
|
+
continue;
|
|
46
|
+
const path = join(directory, entry.name);
|
|
47
|
+
if (entry.isDirectory())
|
|
48
|
+
visit(path, depth + 1);
|
|
49
|
+
else if (entry.isFile() && /\.config\.ya?ml$/iu.test(entry.name)) {
|
|
50
|
+
if (result.length >= MAX_CONFIG_FILES)
|
|
51
|
+
throw new Error("Config type generation exceeds file limit.");
|
|
52
|
+
result.push(path);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
visit(root, 0);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
function fieldType(field) {
|
|
60
|
+
let scalar;
|
|
61
|
+
const valueType = String(field.valueType ?? "").trim().toLowerCase();
|
|
62
|
+
if (field.type === "boolean" || valueType === "bool")
|
|
63
|
+
scalar = "boolean";
|
|
64
|
+
else if (field.type === "number" || ["int8", "int16", "int32", "int64", "uint8", "float", "double"].includes(valueType))
|
|
65
|
+
scalar = valueType === "int64" ? "number | bigint" : "number";
|
|
66
|
+
else if (field.type === "text" || field.type === "select")
|
|
67
|
+
scalar = "string";
|
|
68
|
+
else
|
|
69
|
+
throw new Error(`Unsupported config field type '${String(field.type)}'.`);
|
|
70
|
+
return field.multiple === true ? `readonly (${scalar})[]` : scalar;
|
|
71
|
+
}
|
|
72
|
+
function asRecord(value) {
|
|
73
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
74
|
+
}
|