@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
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { parse } from "yaml";
|
|
6
|
+
const DOCUMENTS = {
|
|
7
|
+
AssetDocument: "asset", CategoryReorderDocument: "category_reorder", CdoDocument: "cdo",
|
|
8
|
+
CurveDocument: "curve", DataAssetDocument: "dataasset", EventRuleDocument: "eventrule",
|
|
9
|
+
GameTagDocument: "gametag", ItemDocument: "item", ResourceDocument: "resource", BuildingDocument: "building",
|
|
10
|
+
UnlockDocument: "unlock", RecipeDocument: "recipe", SchematicDocument: "schematic", ResearchDocument: "research",
|
|
11
|
+
ResourceNodeDocument: "resourcenode", SinkPointsDocument: "sinkpoints", SoundDocument: "sound", SublevelDocument: "sublevel",
|
|
12
|
+
};
|
|
13
|
+
/** Uses the same bundled schemas as KDF validation; never resolves schema URLs over the network. */
|
|
14
|
+
export function strictContentDeclarations(source) {
|
|
15
|
+
const generator = new ContentTypes();
|
|
16
|
+
const file = ts.createSourceFile("runtime.d.ts", source, ts.ScriptTarget.Latest, true);
|
|
17
|
+
const replacements = [];
|
|
18
|
+
const visit = (node) => {
|
|
19
|
+
if (ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) {
|
|
20
|
+
const schema = DOCUMENTS[node.name.text];
|
|
21
|
+
if (schema !== undefined)
|
|
22
|
+
replacements.push({ start: node.getStart(file), end: node.end,
|
|
23
|
+
text: `export type ${node.name.text} = ${generator.reference(`${schema}.schema.yml`, "")};` });
|
|
24
|
+
}
|
|
25
|
+
ts.forEachChild(node, visit);
|
|
26
|
+
};
|
|
27
|
+
visit(file);
|
|
28
|
+
let result = source;
|
|
29
|
+
for (const replacement of replacements.sort((left, right) => right.start - left.start)) {
|
|
30
|
+
result = result.slice(0, replacement.start) + replacement.text + result.slice(replacement.end);
|
|
31
|
+
}
|
|
32
|
+
if (replacements.length === 0)
|
|
33
|
+
return source;
|
|
34
|
+
return `${result}\ndeclare module "@sf-kmods/kdataforgejs" {\n${generator.declarations()}\n}\n`;
|
|
35
|
+
}
|
|
36
|
+
class ContentTypes {
|
|
37
|
+
schemas = new Map();
|
|
38
|
+
aliases = new Map();
|
|
39
|
+
directory = schemaDirectory();
|
|
40
|
+
reference(file, pointer) {
|
|
41
|
+
if (!/^[a-z_\-]+\.schema\.yml$/u.test(file) || (pointer !== "" && !pointer.startsWith("/"))) {
|
|
42
|
+
throw new Error(`Unsupported local schema reference: ${file}#${pointer}`);
|
|
43
|
+
}
|
|
44
|
+
const key = `${file}#${pointer}`;
|
|
45
|
+
const name = aliasName(key);
|
|
46
|
+
if (!this.aliases.has(key)) {
|
|
47
|
+
let node = this.load(file);
|
|
48
|
+
for (const part of pointer.split("/").slice(1)) {
|
|
49
|
+
node = record(node)?.[part.replaceAll("~1", "/").replaceAll("~0", "~")];
|
|
50
|
+
}
|
|
51
|
+
const schema = record(node);
|
|
52
|
+
if (schema === undefined)
|
|
53
|
+
throw new Error(`Missing bundled schema definition: ${key}`);
|
|
54
|
+
this.aliases.set(key, { file, pointer, schema });
|
|
55
|
+
}
|
|
56
|
+
return name;
|
|
57
|
+
}
|
|
58
|
+
declarations() {
|
|
59
|
+
const declarations = [];
|
|
60
|
+
for (const [key, located] of this.aliases) {
|
|
61
|
+
declarations.push(`type ${aliasName(key)} = ${this.render(located.schema, located.file)};`);
|
|
62
|
+
}
|
|
63
|
+
return declarations.join("\n");
|
|
64
|
+
}
|
|
65
|
+
load(file) {
|
|
66
|
+
const cached = this.schemas.get(file);
|
|
67
|
+
if (cached !== undefined)
|
|
68
|
+
return cached;
|
|
69
|
+
const schema = record(parse(readFileSync(join(this.directory, file), "utf8")));
|
|
70
|
+
if (schema === undefined)
|
|
71
|
+
throw new Error(`Invalid bundled schema: ${file}`);
|
|
72
|
+
this.schemas.set(file, schema);
|
|
73
|
+
return schema;
|
|
74
|
+
}
|
|
75
|
+
render(schema, file) {
|
|
76
|
+
const parts = [];
|
|
77
|
+
if (typeof schema.$ref === "string") {
|
|
78
|
+
const [path = "", pointer = ""] = schema.$ref.split("#");
|
|
79
|
+
parts.push(this.reference(path === "" ? file : basename(path), pointer));
|
|
80
|
+
}
|
|
81
|
+
if ("const" in schema)
|
|
82
|
+
parts.push(literal(schema.const));
|
|
83
|
+
else if (Array.isArray(schema.enum))
|
|
84
|
+
parts.push(schema.enum.map(literal).join(" | "));
|
|
85
|
+
else {
|
|
86
|
+
const type = this.valueType(schema, file);
|
|
87
|
+
if (type !== undefined)
|
|
88
|
+
parts.push(type);
|
|
89
|
+
}
|
|
90
|
+
for (const key of ["allOf", "anyOf", "oneOf"]) {
|
|
91
|
+
const entries = schema[key];
|
|
92
|
+
if (!Array.isArray(entries))
|
|
93
|
+
continue;
|
|
94
|
+
const types = entries.map((entry) => this.render(record(entry) ?? {}, file));
|
|
95
|
+
if (types.length > 0)
|
|
96
|
+
parts.push(`(${types.join(key === "allOf" ? " & " : " | ")})`);
|
|
97
|
+
}
|
|
98
|
+
return parts.length === 0 ? "unknown" : parts.map((part) => `(${part})`).join(" & ");
|
|
99
|
+
}
|
|
100
|
+
valueType(schema, file) {
|
|
101
|
+
if (Array.isArray(schema.type)) {
|
|
102
|
+
return schema.type.map((type) => this.valueType({ ...schema, type }, file) ?? "unknown").join(" | ");
|
|
103
|
+
}
|
|
104
|
+
if (schema.type === "string")
|
|
105
|
+
return "string";
|
|
106
|
+
if (schema.type === "number" || schema.type === "integer")
|
|
107
|
+
return "number";
|
|
108
|
+
if (schema.type === "boolean")
|
|
109
|
+
return "boolean";
|
|
110
|
+
if (schema.type === "null")
|
|
111
|
+
return "null";
|
|
112
|
+
if (schema.type === "array")
|
|
113
|
+
return `ReadonlyArray<${this.render(record(schema.items) ?? {}, file)}>`;
|
|
114
|
+
if (schema.type === "object" || schema.properties !== undefined || schema.required !== undefined)
|
|
115
|
+
return this.objectType(schema, file);
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
objectType(schema, file) {
|
|
119
|
+
const properties = record(schema.properties) ?? {};
|
|
120
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required.filter((value) => typeof value === "string") : []);
|
|
121
|
+
const names = [...new Set([...Object.keys(properties), ...required])].sort();
|
|
122
|
+
const fields = names.map((name) => `readonly ${JSON.stringify(name)}${required.has(name) ? "" : "?"}: ${this.render(record(properties[name]) ?? {}, file)};`);
|
|
123
|
+
const excluded = record(schema.not)?.required;
|
|
124
|
+
if (Array.isArray(excluded) && excluded.length === 1 && typeof excluded[0] === "string") {
|
|
125
|
+
fields.push(`readonly ${JSON.stringify(excluded[0])}?: never;`);
|
|
126
|
+
}
|
|
127
|
+
const additional = record(schema.additionalProperties);
|
|
128
|
+
if (additional !== undefined)
|
|
129
|
+
fields.push(`readonly [key: string]: ${this.render(additional, file)};`);
|
|
130
|
+
if (fields.length === 0 && schema.additionalProperties !== false)
|
|
131
|
+
return "Readonly<Record<string, unknown>>";
|
|
132
|
+
return `{ ${fields.join(" ")} }`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function record(value) {
|
|
136
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
137
|
+
}
|
|
138
|
+
function literal(value) {
|
|
139
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean")
|
|
140
|
+
return JSON.stringify(value);
|
|
141
|
+
throw new Error("Content schema contains a non-scalar enum or const.");
|
|
142
|
+
}
|
|
143
|
+
function aliasName(key) {
|
|
144
|
+
return `KDFSchema_${key.replace(/\.schema\.yml/gu, "").replace(/[^a-zA-Z0-9]/gu, "_")}`;
|
|
145
|
+
}
|
|
146
|
+
function schemaDirectory() {
|
|
147
|
+
const directories = [new URL("../../schemas/", import.meta.url), new URL("../../../schemas/", import.meta.url)];
|
|
148
|
+
const directory = directories.find((candidate) => existsSync(new URL("common.schema.yml", candidate)));
|
|
149
|
+
if (directory === undefined)
|
|
150
|
+
throw new Error("Bundled content schemas missing; rebuild the CLI package.");
|
|
151
|
+
return fileURLToPath(directory);
|
|
152
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { biome, biomeProjectKey } from "./biome.js";
|
|
2
|
+
/** Formats generated TypeScript and JSON through Biome's in-process JavaScript API. */
|
|
3
|
+
export function formatGeneratedContent(content, filePath) {
|
|
4
|
+
const formatted = biome.formatContent(biomeProjectKey, content, { filePath });
|
|
5
|
+
if (formatted.diagnostics.length > 0) {
|
|
6
|
+
throw new Error(`Biome could not format generated file '${filePath}'.`);
|
|
7
|
+
}
|
|
8
|
+
return formatted.content;
|
|
9
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, sep } from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { formatGeneratedContent } from "./format.js";
|
|
5
|
+
import { strictContentDeclarations } from "./contentTypes.js";
|
|
6
|
+
const RUNTIME_MODULE = "@sf-kmods/kdataforgejs";
|
|
7
|
+
const SATISFACTORY_MODULE = "satisfactory";
|
|
8
|
+
const GENERATED_FILE = "kdataforge.generated.d.ts";
|
|
9
|
+
/** Splits exported ambient declarations into deterministic, navigable files and returns the entry declaration. */
|
|
10
|
+
export function organizeGeneratedDeclarations(typesDirectory, options = {}) {
|
|
11
|
+
const generatedPath = join(typesDirectory, GENERATED_FILE);
|
|
12
|
+
const original = readFileSync(generatedPath, "utf8");
|
|
13
|
+
const source = ts.createSourceFile(generatedPath, options.contentTypes ? strictContentDeclarations(original) : original, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS);
|
|
14
|
+
removePreviousOrganization(typesDirectory);
|
|
15
|
+
const references = [];
|
|
16
|
+
const runtimeDeclarations = [];
|
|
17
|
+
const globalStatements = [];
|
|
18
|
+
for (const statement of source.statements) {
|
|
19
|
+
if (!ts.isModuleDeclaration(statement)) {
|
|
20
|
+
globalStatements.push(statement);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const moduleName = stringModuleName(statement);
|
|
24
|
+
if (moduleName === SATISFACTORY_MODULE) {
|
|
25
|
+
references.push(...writeSatisfactoryGroups(typesDirectory, statement, source));
|
|
26
|
+
}
|
|
27
|
+
else if (moduleName === RUNTIME_MODULE && containsNativeClassPathMap(statement)) {
|
|
28
|
+
references.push(...writeClassPathGroups(typesDirectory, statement, source));
|
|
29
|
+
const remainingStatements = moduleStatements(statement)
|
|
30
|
+
.filter((node) => !isNativeClassPathMap(node))
|
|
31
|
+
.map((node) => node.getText(source));
|
|
32
|
+
if (remainingStatements.length > 0) {
|
|
33
|
+
runtimeDeclarations.push(ambientModule(RUNTIME_MODULE, remainingStatements));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
runtimeDeclarations.push(statement.getText(source));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (runtimeDeclarations.length > 0) {
|
|
41
|
+
writeDeclaration(typesDirectory, "runtime.d.ts", runtimeDeclarations.join("\n\n"));
|
|
42
|
+
references.push("runtime.d.ts");
|
|
43
|
+
}
|
|
44
|
+
if (globalStatements.length > 0) {
|
|
45
|
+
writeDeclaration(typesDirectory, "globals.d.ts", globalStatements.map((node) => node.getText(source)).join("\n"));
|
|
46
|
+
references.push("globals.d.ts");
|
|
47
|
+
}
|
|
48
|
+
references.sort();
|
|
49
|
+
const moduleAnchors = `declare module "${RUNTIME_MODULE}" {}\ndeclare module "${SATISFACTORY_MODULE}" {}`;
|
|
50
|
+
writeDeclaration(typesDirectory, "index.d.ts", `${references.map((path) => `/// <reference path="./${path}" />`).join("\n")}\n\n${moduleAnchors}`);
|
|
51
|
+
updateGeneratedConfigs(typesDirectory);
|
|
52
|
+
rmSync(generatedPath);
|
|
53
|
+
return join(typesDirectory, "index.d.ts");
|
|
54
|
+
}
|
|
55
|
+
function removePreviousOrganization(typesDirectory) {
|
|
56
|
+
for (const path of ["globals.d.ts", "index.d.ts", "runtime.d.ts", "paths", "satisfactory"]) {
|
|
57
|
+
rmSync(join(typesDirectory, path), { force: true, recursive: true });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function writeSatisfactoryGroups(typesDirectory, declaration, source) {
|
|
61
|
+
const statements = moduleStatements(declaration);
|
|
62
|
+
const imports = statements.filter(ts.isImportDeclaration).map((node) => node.getText(source));
|
|
63
|
+
const groups = new Map();
|
|
64
|
+
for (const statement of statements) {
|
|
65
|
+
if (ts.isImportDeclaration(statement))
|
|
66
|
+
continue;
|
|
67
|
+
const key = satisfactoryGroup(statementName(statement));
|
|
68
|
+
const entries = groups.get(key) ?? [];
|
|
69
|
+
entries.push(statement.getText(source));
|
|
70
|
+
groups.set(key, entries);
|
|
71
|
+
}
|
|
72
|
+
return [...groups.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([key, entries]) => {
|
|
73
|
+
const path = `satisfactory/${key}.d.ts`;
|
|
74
|
+
writeDeclaration(typesDirectory, path, ambientModule(SATISFACTORY_MODULE, [...imports, ...entries]));
|
|
75
|
+
return path;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function writeClassPathGroups(typesDirectory, declaration, source) {
|
|
79
|
+
const pathMap = moduleStatements(declaration).find((statement) => ts.isInterfaceDeclaration(statement) && statement.name.text === "NativeClassPathMap");
|
|
80
|
+
if (pathMap === undefined)
|
|
81
|
+
return [];
|
|
82
|
+
const groups = new Map();
|
|
83
|
+
for (const member of pathMap.members) {
|
|
84
|
+
const key = classPathGroup(propertyPath(member));
|
|
85
|
+
const entries = groups.get(key) ?? [];
|
|
86
|
+
entries.push(member);
|
|
87
|
+
groups.set(key, entries);
|
|
88
|
+
}
|
|
89
|
+
return [...groups.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([key, members]) => {
|
|
90
|
+
const body = members.map((member) => qualifiedTypeReference(member.getText(source))).join("\n");
|
|
91
|
+
const path = `paths/${key}.d.ts`;
|
|
92
|
+
writeDeclaration(typesDirectory, path, `import type * as Satisfactory from "satisfactory";\n\ndeclare module "${RUNTIME_MODULE}" {\n interface NativeClassPathMap {\n${indent(body, 4)}\n }\n}`);
|
|
93
|
+
return path;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function updateGeneratedConfigs(typesDirectory) {
|
|
97
|
+
updateJson(join(typesDirectory, "tsconfig.json"), (value) => {
|
|
98
|
+
const compilerOptions = recordOrEmpty(value.compilerOptions);
|
|
99
|
+
value.compilerOptions = compilerOptions;
|
|
100
|
+
compilerOptions.paths = { [RUNTIME_MODULE]: ["index.d.ts"], [SATISFACTORY_MODULE]: ["index.d.ts"] };
|
|
101
|
+
});
|
|
102
|
+
updateJsonIfPresent(join(typesDirectory, "paths.json"), (value) => {
|
|
103
|
+
value.paths = { [RUNTIME_MODULE]: "index.d.ts", [SATISFACTORY_MODULE]: "index.d.ts" };
|
|
104
|
+
});
|
|
105
|
+
updateJsonIfPresent(join(typesDirectory, "editor.json"), (value) => {
|
|
106
|
+
const typescript = recordOrEmpty(value.typescript);
|
|
107
|
+
value.typescript = typescript;
|
|
108
|
+
typescript.declaration = "index.d.ts";
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function updateJsonIfPresent(path, update) {
|
|
112
|
+
if (existsSync(path))
|
|
113
|
+
updateJson(path, update);
|
|
114
|
+
}
|
|
115
|
+
function updateJson(path, update) {
|
|
116
|
+
const value = record(JSON.parse(readFileSync(path, "utf8")));
|
|
117
|
+
update(value);
|
|
118
|
+
writeFileSync(path, formatGeneratedContent(JSON.stringify(value), path));
|
|
119
|
+
}
|
|
120
|
+
function record(value) {
|
|
121
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
122
|
+
throw new Error("Generated config must be an object.");
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
function recordOrEmpty(value) {
|
|
126
|
+
return value === undefined ? {} : record(value);
|
|
127
|
+
}
|
|
128
|
+
function moduleStatements(declaration) {
|
|
129
|
+
return declaration.body !== undefined && ts.isModuleBlock(declaration.body) ? declaration.body.statements : [];
|
|
130
|
+
}
|
|
131
|
+
function stringModuleName(declaration) {
|
|
132
|
+
return ts.isStringLiteral(declaration.name) ? declaration.name.text : undefined;
|
|
133
|
+
}
|
|
134
|
+
function containsNativeClassPathMap(declaration) {
|
|
135
|
+
return moduleStatements(declaration).some(isNativeClassPathMap);
|
|
136
|
+
}
|
|
137
|
+
function isNativeClassPathMap(statement) {
|
|
138
|
+
return ts.isInterfaceDeclaration(statement) && statement.name.text === "NativeClassPathMap";
|
|
139
|
+
}
|
|
140
|
+
function statementName(statement) {
|
|
141
|
+
if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) ||
|
|
142
|
+
ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement))
|
|
143
|
+
return statement.name?.text ?? "misc";
|
|
144
|
+
if (ts.isVariableStatement(statement))
|
|
145
|
+
return statement.declarationList.declarations[0]?.name.getText() ?? "misc";
|
|
146
|
+
return "misc";
|
|
147
|
+
}
|
|
148
|
+
function satisfactoryGroup(name) {
|
|
149
|
+
if (name.startsWith("KdfEnumBrand"))
|
|
150
|
+
return "e";
|
|
151
|
+
const first = name[0]?.toLocaleLowerCase();
|
|
152
|
+
return first !== undefined && /^[a-z0-9]$/u.test(first) ? first : "misc";
|
|
153
|
+
}
|
|
154
|
+
function propertyPath(member) {
|
|
155
|
+
if (!ts.isPropertySignature(member) || member.name === undefined)
|
|
156
|
+
return "misc";
|
|
157
|
+
return ts.isStringLiteral(member.name) ? member.name.text : member.name.getText();
|
|
158
|
+
}
|
|
159
|
+
function classPathGroup(path) {
|
|
160
|
+
const segments = path.split("/").filter(Boolean);
|
|
161
|
+
if (segments[0]?.toLocaleLowerCase() === "script") {
|
|
162
|
+
return slug(["script", segments[1]?.split(".")[0] ?? "misc"]);
|
|
163
|
+
}
|
|
164
|
+
const count = Math.max(1, Math.min(3, segments.length - 1));
|
|
165
|
+
return slug(segments.slice(0, count));
|
|
166
|
+
}
|
|
167
|
+
function slug(parts) {
|
|
168
|
+
const value = parts.join("-").toLocaleLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-|-$/gu, "");
|
|
169
|
+
return value === "" ? "misc" : value;
|
|
170
|
+
}
|
|
171
|
+
function qualifiedTypeReference(text) {
|
|
172
|
+
return text.replace(/import\(["']satisfactory["']\)\.([A-Za-z_$][\w$]*)/gu, "Satisfactory.$1");
|
|
173
|
+
}
|
|
174
|
+
function ambientModule(name, statements) {
|
|
175
|
+
return `declare module "${name}" {\n${indent(statements.join("\n"), 2)}\n}`;
|
|
176
|
+
}
|
|
177
|
+
function indent(value, spaces) {
|
|
178
|
+
const prefix = " ".repeat(spaces);
|
|
179
|
+
return value.split("\n").map((line) => line.length === 0 ? line : `${prefix}${line}`).join("\n");
|
|
180
|
+
}
|
|
181
|
+
function writeDeclaration(root, path, body) {
|
|
182
|
+
const target = join(root, path.split("/").join(sep));
|
|
183
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
184
|
+
const content = `// Generated by KDataForgeJS. Do not edit.\n${body.trim()}\n`;
|
|
185
|
+
writeFileSync(target, formatGeneratedContent(content, target));
|
|
186
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sf-kmods/kdataforgejs-cli",
|
|
3
|
-
"version": "2026.4.
|
|
3
|
+
"version": "2026.4.20",
|
|
4
4
|
"description": "kdf - create, type-check and validate KDataForge projects with KDataForgeJS (TypeScript) scripts.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Kyri123/Kyrium",
|
|
@@ -28,20 +28,24 @@
|
|
|
28
28
|
"files": [
|
|
29
29
|
"dist",
|
|
30
30
|
"templates",
|
|
31
|
+
"schemas",
|
|
31
32
|
"README.md"
|
|
32
33
|
],
|
|
33
34
|
"engines": {
|
|
34
35
|
"node": ">=20"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
38
|
+
"@biomejs/js-api": "6.1.0",
|
|
39
|
+
"@biomejs/wasm-nodejs": "2.6.3",
|
|
37
40
|
"typescript": ">=5.7.3 <6",
|
|
38
41
|
"yaml": "^2.6.1",
|
|
39
|
-
"@sf-kmods/kdataforgejs": "^2026.4.
|
|
42
|
+
"@sf-kmods/kdataforgejs": "^2026.4.20"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"@types/node": "^22.10.0"
|
|
43
46
|
},
|
|
44
47
|
"scripts": {
|
|
48
|
+
"sync:schemas": "node scripts/sync-content-schemas.mjs",
|
|
45
49
|
"build": "tsc -p tsconfig.build.json",
|
|
46
50
|
"test": "tsc -p tsconfig.test.json && node --test \"dist-test/test/*.test.js\""
|
|
47
51
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
$schema: https://json-schema.org/draft/2020-12/schema
|
|
2
|
+
$id: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/actor-selector.schema.yml
|
|
3
|
+
title: KDataForge actor instance selector
|
|
4
|
+
type: object
|
|
5
|
+
additionalProperties: false
|
|
6
|
+
minProperties: 1
|
|
7
|
+
properties:
|
|
8
|
+
tags:
|
|
9
|
+
oneOf:
|
|
10
|
+
- { type: string, minLength: 1, pattern: '\S' }
|
|
11
|
+
- type: array
|
|
12
|
+
minItems: 1
|
|
13
|
+
items: { type: string, minLength: 1, pattern: '\S' }
|
|
14
|
+
sphere:
|
|
15
|
+
type: object
|
|
16
|
+
additionalProperties: false
|
|
17
|
+
required: [center, radius]
|
|
18
|
+
properties:
|
|
19
|
+
center: { $ref: '#/$defs/vector' }
|
|
20
|
+
radius: { type: number, exclusiveMinimum: 0 }
|
|
21
|
+
box:
|
|
22
|
+
type: object
|
|
23
|
+
additionalProperties: false
|
|
24
|
+
required: [min, max]
|
|
25
|
+
properties:
|
|
26
|
+
min: { $ref: '#/$defs/vector' }
|
|
27
|
+
max: { $ref: '#/$defs/vector' }
|
|
28
|
+
currentRecipe:
|
|
29
|
+
oneOf:
|
|
30
|
+
- { type: string, minLength: 1, pattern: '\S' }
|
|
31
|
+
- type: array
|
|
32
|
+
minItems: 1
|
|
33
|
+
items: { type: string, minLength: 1, pattern: '\S' }
|
|
34
|
+
$defs:
|
|
35
|
+
vector:
|
|
36
|
+
type: array
|
|
37
|
+
minItems: 3
|
|
38
|
+
maxItems: 3
|
|
39
|
+
items: { type: number }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
$schema: https://json-schema.org/draft/2020-12/schema
|
|
2
|
+
$id: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/asset.schema.yml
|
|
3
|
+
x-kdf-type: asset
|
|
4
|
+
title: KDataForge image assets
|
|
5
|
+
allOf:
|
|
6
|
+
- $ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/documentBase
|
|
7
|
+
- type: object
|
|
8
|
+
required: [assets]
|
|
9
|
+
properties:
|
|
10
|
+
type: { const: asset }
|
|
11
|
+
assets:
|
|
12
|
+
type: array
|
|
13
|
+
minItems: 1
|
|
14
|
+
items:
|
|
15
|
+
type: object
|
|
16
|
+
additionalProperties: false
|
|
17
|
+
required: [id, file]
|
|
18
|
+
properties:
|
|
19
|
+
id:
|
|
20
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/token
|
|
21
|
+
file:
|
|
22
|
+
type: string
|
|
23
|
+
minLength: 1
|
|
24
|
+
pattern: '\.(?:[Pp][Nn][Gg]|[Jj][Pp][Ee]?[Gg]|[Tt][Gg][Aa]|[Bb][Mm][Pp])$'
|
|
25
|
+
properties:
|
|
26
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/properties
|
|
27
|
+
unevaluatedProperties: false
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
$schema: https://json-schema.org/draft/2020-12/schema
|
|
2
|
+
$id: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/building.schema.yml
|
|
3
|
+
x-kdf-type: building
|
|
4
|
+
title: KDataForge buildings
|
|
5
|
+
allOf:
|
|
6
|
+
- $ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/documentBase
|
|
7
|
+
- type: object
|
|
8
|
+
required: [buildings]
|
|
9
|
+
properties:
|
|
10
|
+
type: { const: building }
|
|
11
|
+
buildings:
|
|
12
|
+
type: array
|
|
13
|
+
minItems: 1
|
|
14
|
+
items:
|
|
15
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/generatedEntry
|
|
16
|
+
unevaluatedProperties: false
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
$schema: https://json-schema.org/draft/2020-12/schema
|
|
2
|
+
$id: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/category_reorder.schema.yml
|
|
3
|
+
x-kdf-type: category_reorder
|
|
4
|
+
title: KDataForge category ordering
|
|
5
|
+
allOf:
|
|
6
|
+
- $ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/documentBase
|
|
7
|
+
- type: object
|
|
8
|
+
required: [subType, category, order]
|
|
9
|
+
properties:
|
|
10
|
+
type: { const: category_reorder }
|
|
11
|
+
subType:
|
|
12
|
+
type: string
|
|
13
|
+
enum: [items, recipe, schematic, settings]
|
|
14
|
+
category:
|
|
15
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/nonEmptyString
|
|
16
|
+
subCategory:
|
|
17
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/nonEmptyString
|
|
18
|
+
categoryPriority: { type: number }
|
|
19
|
+
subCategoryPriority: { type: number }
|
|
20
|
+
order:
|
|
21
|
+
type: array
|
|
22
|
+
minItems: 1
|
|
23
|
+
uniqueItems: true
|
|
24
|
+
items:
|
|
25
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/nonEmptyString
|
|
26
|
+
allOf:
|
|
27
|
+
- if:
|
|
28
|
+
required: [subCategoryPriority]
|
|
29
|
+
then:
|
|
30
|
+
required: [subCategory]
|
|
31
|
+
- if:
|
|
32
|
+
properties:
|
|
33
|
+
subType: { const: recipe }
|
|
34
|
+
required: [subType]
|
|
35
|
+
then:
|
|
36
|
+
not:
|
|
37
|
+
anyOf:
|
|
38
|
+
- required: [subCategory]
|
|
39
|
+
- required: [subCategoryPriority]
|
|
40
|
+
unevaluatedProperties: false
|
|
41
|
+
unevaluatedProperties: false
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
$schema: https://json-schema.org/draft/2020-12/schema
|
|
2
|
+
$id: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/cdo.schema.yml
|
|
3
|
+
x-kdf-type: cdo
|
|
4
|
+
title: KDataForge CDO patches
|
|
5
|
+
allOf:
|
|
6
|
+
- $ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/documentBase
|
|
7
|
+
- type: object
|
|
8
|
+
required: [patches]
|
|
9
|
+
properties:
|
|
10
|
+
type: { const: cdo }
|
|
11
|
+
patches:
|
|
12
|
+
type: array
|
|
13
|
+
minItems: 1
|
|
14
|
+
items:
|
|
15
|
+
type: object
|
|
16
|
+
oneOf:
|
|
17
|
+
- required: [properties]
|
|
18
|
+
not:
|
|
19
|
+
anyOf:
|
|
20
|
+
- required: [actorAction]
|
|
21
|
+
- required: [inventoryRemap]
|
|
22
|
+
- required: [actorAction]
|
|
23
|
+
not:
|
|
24
|
+
anyOf:
|
|
25
|
+
- required: [properties]
|
|
26
|
+
- required: [inventoryRemap]
|
|
27
|
+
- required: [inventoryRemap]
|
|
28
|
+
not:
|
|
29
|
+
anyOf:
|
|
30
|
+
- required: [properties]
|
|
31
|
+
- required: [actorAction]
|
|
32
|
+
allOf:
|
|
33
|
+
- $ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/scopeFilters
|
|
34
|
+
- $ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/scopeNeedsOfClass
|
|
35
|
+
properties:
|
|
36
|
+
target:
|
|
37
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/stringOrList
|
|
38
|
+
allAssetsOfClass:
|
|
39
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/nonEmptyString
|
|
40
|
+
applyToSubclasses: { type: boolean, default: false }
|
|
41
|
+
applyToSpawnedActors: { type: boolean, default: false }
|
|
42
|
+
actorAction:
|
|
43
|
+
type: string
|
|
44
|
+
enum: [destroy, dismantle]
|
|
45
|
+
inventoryRemap:
|
|
46
|
+
type: array
|
|
47
|
+
minItems: 1
|
|
48
|
+
maxItems: 256
|
|
49
|
+
items:
|
|
50
|
+
type: object
|
|
51
|
+
required: [from, to]
|
|
52
|
+
properties:
|
|
53
|
+
from:
|
|
54
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/nonEmptyString
|
|
55
|
+
to:
|
|
56
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/nonEmptyString
|
|
57
|
+
multiplier: { type: integer, minimum: 1, maximum: 2147483647, default: 1 }
|
|
58
|
+
additionalProperties: false
|
|
59
|
+
actorSelector:
|
|
60
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/actor-selector.schema.yml
|
|
61
|
+
deferOneGameTick: { type: boolean, default: false }
|
|
62
|
+
properties:
|
|
63
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/properties
|
|
64
|
+
if:
|
|
65
|
+
anyOf:
|
|
66
|
+
- required: [actorSelector]
|
|
67
|
+
- required: [actorAction]
|
|
68
|
+
- required: [inventoryRemap]
|
|
69
|
+
then:
|
|
70
|
+
required: [target, applyToSpawnedActors]
|
|
71
|
+
properties:
|
|
72
|
+
applyToSpawnedActors: { const: true }
|
|
73
|
+
not:
|
|
74
|
+
anyOf:
|
|
75
|
+
- required: [allAssetsOfClass]
|
|
76
|
+
- required: [ofClass]
|
|
77
|
+
- required: [matchTag]
|
|
78
|
+
- required: [matchName]
|
|
79
|
+
- required: [classType]
|
|
80
|
+
- required: [excludeClasses]
|
|
81
|
+
- required: [where]
|
|
82
|
+
- required: [producedIn]
|
|
83
|
+
- required: [ingredient]
|
|
84
|
+
- required: [product]
|
|
85
|
+
- required: [tagProperty]
|
|
86
|
+
- required: [matchAssets]
|
|
87
|
+
anyOf:
|
|
88
|
+
- required: [target]
|
|
89
|
+
- required: [allAssetsOfClass]
|
|
90
|
+
- $ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/hasScopeFilter
|
|
91
|
+
unevaluatedProperties: false
|
|
92
|
+
unevaluatedProperties: false
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
$schema: https://json-schema.org/draft/2020-12/schema
|
|
2
|
+
$id: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/class.schema.yml
|
|
3
|
+
x-kdf-type: class
|
|
4
|
+
title: KDataForge generic classes
|
|
5
|
+
allOf:
|
|
6
|
+
- $ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/documentBase
|
|
7
|
+
- type: object
|
|
8
|
+
required: [classes]
|
|
9
|
+
properties:
|
|
10
|
+
type: { const: class }
|
|
11
|
+
classes:
|
|
12
|
+
type: array
|
|
13
|
+
minItems: 1
|
|
14
|
+
items:
|
|
15
|
+
type: object
|
|
16
|
+
additionalProperties: false
|
|
17
|
+
required: [id, parent]
|
|
18
|
+
properties:
|
|
19
|
+
id:
|
|
20
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/token
|
|
21
|
+
parent:
|
|
22
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/nonEmptyString
|
|
23
|
+
registerAs:
|
|
24
|
+
enum: [recipe, schematic, research]
|
|
25
|
+
properties:
|
|
26
|
+
$ref: https://raw.githubusercontent.com/Satisfactory-KMods/KDataForge-Linter/main/src/kdataforge_linter/schemas/common.schema.yml#/$defs/properties
|
|
27
|
+
unevaluatedProperties: false
|