mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
handle nested messages correctly
This commit is contained in:
1 parent
0e637d772e
commit
f95a6e3495
3 files changed
+35
-47
No files matched your search
+2
-2
@@ -4,13 +4,13 @@
|
|||||||
"license": "BlitzKit License",
|
"license": "BlitzKit License",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"setup": "bun install && bun run build:protos && bun run build:proxyclient && bun run build:catalogitemaccesssor",
|
"setup": "bun install && bun run build:protos && bun run build:proxyclient && bun run build:catalogitemaccessor",
|
||||||
"dev": "bun run dev:website",
|
"dev": "bun run dev:website",
|
||||||
"dev:website": "cd packages/website-ue && bun run dev",
|
"dev:website": "cd packages/website-ue && bun run dev",
|
||||||
"build:game": "cd packages/game && bun run build",
|
"build:game": "cd packages/game && bun run build",
|
||||||
"build:website": "cd packages/website-ue && bun run build",
|
"build:website": "cd packages/website-ue && bun run build",
|
||||||
"build:proxyclient": "cd packages/scripts && bun run build:proxyclient",
|
"build:proxyclient": "cd packages/scripts && bun run build:proxyclient",
|
||||||
"build:catalogitemaccesssor": "cd packages/scripts && bun run build:catalogitemaccesssor",
|
"build:catalogitemaccessor": "cd packages/scripts && bun run build:catalogitemaccessor",
|
||||||
"build:protos": "cd packages/scripts && bun run build:protos",
|
"build:protos": "cd packages/scripts && bun run build:protos",
|
||||||
"lint": "tsc",
|
"lint": "tsc",
|
||||||
"lint:website": "cd packages/website-ue && bun run lint"
|
"lint:website": "cd packages/website-ue && bun run lint"
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
"build:bot": "bun src/buildBot.ts",
|
"build:bot": "bun src/buildBot.ts",
|
||||||
"build:ratingleaderboard": "bun src/buildRatingLeaderboard.ts",
|
"build:ratingleaderboard": "bun src/buildRatingLeaderboard.ts",
|
||||||
"build:proxyclient": "bun src/buildProxyClient.ts",
|
"build:proxyclient": "bun src/buildProxyClient.ts",
|
||||||
"build:catalogitemaccesssor": "bun src/buildCatalogItemAccessor.ts",
|
"build:catalogitemaccessor": "bun src/buildCatalogItemAccessor.ts",
|
||||||
"build:protos": "bun src/protos.ts",
|
"build:protos": "bun src/protos.ts",
|
||||||
"patchnotes": "bun src/patchNotes.ts"
|
"patchnotes": "bun src/patchNotes.ts"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,62 +1,50 @@
|
|||||||
import { readdir, readFile, writeFile } from "fs/promises";
|
import { readdir, readFile, writeFile } from "fs/promises";
|
||||||
|
import { lowerFirst } from "lodash-es";
|
||||||
|
|
||||||
const SOURCES = "../../packages/closed/protos/blitz";
|
const SOURCES = "../../packages/closed/protos";
|
||||||
const TARGET = "../../packages/closed/src/unreal/catalogItemAccessor.ts";
|
const TARGET = "../../packages/closed/src/unreal/catalogItemAccessor.ts";
|
||||||
|
|
||||||
const componentPattern = /^message (\w+)Component {/gm;
|
const componentPattern = /^export interface (\w+Component) {/gm;
|
||||||
|
const componentSuffixPattern = /Component$/;
|
||||||
|
const tsSuffixPattern = /\.ts$/;
|
||||||
|
|
||||||
const files = await readdir(SOURCES).then((files) =>
|
let imports = "";
|
||||||
files.filter(
|
let methods = "";
|
||||||
(file) =>
|
|
||||||
file.startsWith("blitz_static_") && file.endsWith("_component.proto"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
const imports: { name: string; file: string }[] = [];
|
const files = await readdir(SOURCES);
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const content = await readFile(`${SOURCES}/${file}`).then((buffer) =>
|
if (!file.endsWith("_component.ts")) continue;
|
||||||
buffer.toString(),
|
|
||||||
);
|
|
||||||
const components = content.matchAll(componentPattern);
|
|
||||||
|
|
||||||
for (const match of components) {
|
const buffer = await readFile(`${SOURCES}/${file}`);
|
||||||
const name = match[1];
|
const content = buffer.toString();
|
||||||
const duplicate = imports.find((_import) => _import.name === name);
|
const matches = content.matchAll(componentPattern);
|
||||||
|
|
||||||
if (duplicate) {
|
for (const match of matches) {
|
||||||
console.warn(
|
const interfaceName = match[1];
|
||||||
`Duplicate component ${name} across ${duplicate.file}.proto and ${file}`,
|
const componentName = interfaceName.split("_").at(-1)!;
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const importFile = file.replace(".proto", "");
|
if (componentName.startsWith("BlitzStatic")) continue;
|
||||||
|
|
||||||
imports.push({ name, file: importFile });
|
const fieldName = lowerFirst(componentName);
|
||||||
|
const methodName = componentName.replace(componentSuffixPattern, "");
|
||||||
|
const importName = file.replace(tsSuffixPattern, "");
|
||||||
|
|
||||||
|
imports += `import { ${interfaceName} } from "@protos/${importName}";\n`;
|
||||||
|
|
||||||
|
methods += ` ${methodName}(name = "${fieldName}") {\n`;
|
||||||
|
methods += ` return this.component(name, ${interfaceName});`;
|
||||||
|
methods += "\n }\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = "";
|
let body = "";
|
||||||
|
|
||||||
for (const _import of imports) {
|
body += imports;
|
||||||
content += `import { ${_import.name}Component } from "@protos/${_import.file}";\n`;
|
body +=
|
||||||
}
|
|
||||||
|
|
||||||
content +=
|
|
||||||
'import { BaseCatalogItemAccessor } from "./baseCatalogItemAccessor";\n\n';
|
'import { BaseCatalogItemAccessor } from "./baseCatalogItemAccessor";\n\n';
|
||||||
content +=
|
body += `export class CatalogItemAccessor extends BaseCatalogItemAccessor {\n`;
|
||||||
"export class CatalogItemAccessor extends BaseCatalogItemAccessor {\n";
|
body += methods;
|
||||||
|
body += `}\n`;
|
||||||
|
|
||||||
for (const _import of imports) {
|
await writeFile(TARGET, body);
|
||||||
const strippedName = _import.name.replace("BlitzStatic", "");
|
|
||||||
const defaultName = strippedName[0].toLowerCase() + strippedName.slice(1);
|
|
||||||
|
|
||||||
content += ` ${strippedName}(name = "${defaultName}Component") {\n`;
|
|
||||||
content += ` return this.component(name, ${_import.name}Component);\n`;
|
|
||||||
content += " }\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
content += "}\n";
|
|
||||||
|
|
||||||
await writeFile(TARGET, content);
|
|
||||||
Reference in new issue
Block a user