2026-09-13 12:36:29 -05:00
|
|
|
import { execFile } from "child_process";
|
|
|
|
|
import { mkdir, readdir, rm, writeFile } from "fs/promises";
|
2024-09-28 21:07:00 -05:00
|
|
|
|
2026-09-13 12:36:29 -05:00
|
|
|
const TEMP = "../../temp";
|
2026-09-13 12:52:25 -05:00
|
|
|
const TS_PROTO_EXECUTABLE = "../../node_modules/.bin/protoc-gen-ts_proto";
|
2026-09-13 12:36:29 -05:00
|
|
|
const ROOTS = ["../protos/src/blitzkit"];
|
2025-09-12 13:29:10 -05:00
|
|
|
|
2026-09-13 12:36:29 -05:00
|
|
|
for (const root of ROOTS) {
|
|
|
|
|
await mkdir(TEMP, { recursive: true });
|
2024-09-29 20:56:52 -05:00
|
|
|
|
2026-09-13 12:36:29 -05:00
|
|
|
let args = "";
|
2024-09-29 20:56:52 -05:00
|
|
|
|
2026-09-13 12:36:29 -05:00
|
|
|
args += `--plugin=${TS_PROTO_EXECUTABLE}\n`;
|
|
|
|
|
args += "--ts_proto_opt=esModuleInterop=true\n";
|
|
|
|
|
args += "--ts_proto_opt=oneof=unions-value\n";
|
|
|
|
|
args += "--ts_proto_opt=unrecognizedEnum=false\n";
|
|
|
|
|
args += "--ts_proto_opt=snakeToCamel=false\n";
|
|
|
|
|
args += `--ts_proto_out=${root}\n`;
|
2024-09-29 20:56:52 -05:00
|
|
|
|
2026-09-13 12:52:25 -05:00
|
|
|
for (const dir of ROOTS) {
|
|
|
|
|
args += `-I=${dir}\n`;
|
2025-11-27 17:59:34 -06:00
|
|
|
}
|
|
|
|
|
|
2026-09-13 12:36:29 -05:00
|
|
|
const filesRaw = await readdir(`${root}`, { recursive: true });
|
2025-09-12 13:29:10 -05:00
|
|
|
const files: string[] = [];
|
|
|
|
|
|
2026-09-13 12:52:25 -05:00
|
|
|
let index = "";
|
|
|
|
|
index += "// @ts-nocheck\n";
|
|
|
|
|
|
2025-09-12 13:29:10 -05:00
|
|
|
for (const file of filesRaw) {
|
2026-09-13 12:36:29 -05:00
|
|
|
if (file.endsWith(".proto")) {
|
2026-09-23 16:42:30 -05:00
|
|
|
const name = file.slice(0, -6);
|
|
|
|
|
|
|
|
|
|
index += `export * from "./${name}";\n`;
|
2026-09-13 12:36:29 -05:00
|
|
|
args += `${root}/${file}\n`;
|
2026-09-23 16:42:30 -05:00
|
|
|
|
|
|
|
|
files.push(file);
|
2026-09-13 12:36:29 -05:00
|
|
|
}
|
|
|
|
|
|
2026-09-13 12:52:25 -05:00
|
|
|
if (file.endsWith(".ts")) {
|
|
|
|
|
await rm(`${root}/${file}`);
|
|
|
|
|
}
|
2025-09-12 13:29:10 -05:00
|
|
|
}
|
|
|
|
|
|
2026-09-13 12:36:29 -05:00
|
|
|
await writeFile(`${TEMP}/protoc.txt`, args);
|
2025-09-12 13:29:10 -05:00
|
|
|
|
2026-09-13 12:36:29 -05:00
|
|
|
execFile("protoc", [`@${TEMP}/protoc.txt`], (error, stdout, stderr) => {
|
|
|
|
|
if (error) throw new Error(error.message);
|
|
|
|
|
if (stderr) console.error(stderr);
|
|
|
|
|
if (stdout) console.log(stdout);
|
|
|
|
|
});
|
2026-09-13 12:52:25 -05:00
|
|
|
|
|
|
|
|
await writeFile(`${root}/index.ts`, index);
|
2025-09-12 13:29:10 -05:00
|
|
|
}
|