feat: update closed

This commit is contained in:
TrèsAbhi committed 2025-09-12 13:29:10 -05:00
1 parent ebdd7629ff
commit c6eae9ad51
2 files changed
+59 -36

No files matched your search

+58 -35
View File
@@ -1,47 +1,70 @@
import { exec as execSync } from 'child_process'; import { exec as execSync } from "child_process";
import { existsSync } from 'fs'; import { existsSync } from "fs";
import { readdir, rm, writeFile } from 'fs/promises'; import { readdir, rm, writeFile } from "fs/promises";
import { promisify } from 'util'; import { promisify } from "util";
const ROOT = 'packages/core/src/protos'; const MAX_COMMAND_LENGTH = 2 ** 11;
const roots = [
// "packages/core/src/protos",
"submodules/blitzkit-closed/protos",
];
const exec = promisify(execSync); const exec = promisify(execSync);
let executableFileExtension: string; let executableFileExtension: string;
if (existsSync('node_modules/.bin/protoc-gen-ts_proto.exe')) { if (existsSync("node_modules/.bin/protoc-gen-ts_proto.exe")) {
executableFileExtension = '.exe'; executableFileExtension = ".exe";
} else { } else {
executableFileExtension = ''; executableFileExtension = "";
} }
const filesRaw = await readdir(`${ROOT}`); for (const root of roots) {
await Promise.all( const filesRaw = await readdir(`${root}`);
filesRaw.map(async (file) => { const files: string[] = [];
if (!file.endsWith('.proto')) {
await rm(`${ROOT}/${file}`); for (const file of filesRaw) {
if (file.endsWith(".proto")) files.push(file);
if (file.endsWith(".ts")) await rm(`${root}/${file}`);
}
while (files.length > 0) {
let command = [
"protoc",
`--plugin=./node_modules/.bin/protoc-gen-ts_proto${executableFileExtension}`,
"--ts_proto_opt=esModuleInterop=true",
"--ts_proto_opt=oneof=unions-value",
// "--ts_proto_opt=removeEnumPrefix=true",
"--ts_proto_opt=unrecognizedEnum=false",
"--ts_proto_opt=snakeToCamel=false",
`--ts_proto_out=${root}`,
`-I=${root}`,
].join(" ");
while (true) {
if (files.length === 0) break;
const file = files.at(-1);
const newLine = ` ${root}/${file}`;
if (command.length + newLine.length < MAX_COMMAND_LENGTH) {
command += newLine;
files.pop();
} else {
break;
}
} }
}),
);
const files = filesRaw.filter((file) => file.endsWith('.proto')); await exec(command);
const args = [ }
`--plugin=./node_modules/.bin/protoc-gen-ts_proto${executableFileExtension}`,
'--ts_proto_opt=esModuleInterop=true',
'--ts_proto_opt=oneof=unions-value',
'--ts_proto_opt=removeEnumPrefix=true',
'--ts_proto_opt=unrecognizedEnum=false',
'--ts_proto_opt=snakeToCamel=false',
'--ts_proto_out=.',
...files.map((file) => `${ROOT}/${file}`),
];
await exec(`protoc ${args.join(' ')}`); await writeFile(
await writeFile( `${root}/index.ts`,
`${ROOT}/index.ts`, "// @ts-nocheck\n" +
'// @ts-nocheck\n' + files
files .map((file) => file.replace(".proto", ""))
.map((file) => file.replace('.proto', '')) .map((file) => `export * from './${file}.ts';`)
.map((file) => `export * from './${file}.ts';`) .join("\n")
.join('\n'), );
); }