mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: start of new protos
This commit is contained in:
1 parent
d707f1cc5d
commit
9bca5dccc7
1 file changed
+62
-40
@@ -1,22 +1,16 @@
|
|||||||
import { exec as execSync } from "child_process";
|
import { execFile } from "child_process";
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import { readdir, rm } from "fs/promises";
|
import { mkdir, readdir, rm, writeFile } from "fs/promises";
|
||||||
import { promisify } from "util";
|
|
||||||
|
|
||||||
const MAX_COMMAND_LENGTH = 2 ** 11;
|
|
||||||
const TS_PROTO_EXECUTABLE_LOCATIONS = [
|
const TS_PROTO_EXECUTABLE_LOCATIONS = [
|
||||||
"./node_modules/.bin/protoc-gen-ts_proto",
|
"./node_modules/.bin/protoc-gen-ts_proto",
|
||||||
"../../node_modules/.bin/protoc-gen-ts_proto",
|
"../../node_modules/.bin/protoc-gen-ts_proto",
|
||||||
];
|
];
|
||||||
|
const ROOTS = [
|
||||||
const roots = [
|
|
||||||
// "../../packages/core/src/protos",
|
|
||||||
"../../packages/closed/protos",
|
"../../packages/closed/protos",
|
||||||
"../../packages/website-ue/src/protos",
|
"../../packages/website-ue/src/protos",
|
||||||
];
|
];
|
||||||
|
|
||||||
const exec = promisify(execSync);
|
|
||||||
|
|
||||||
let tsProtoExecutableLocation: string | undefined = undefined;
|
let tsProtoExecutableLocation: string | undefined = undefined;
|
||||||
|
|
||||||
for (const location of TS_PROTO_EXECUTABLE_LOCATIONS) {
|
for (const location of TS_PROTO_EXECUTABLE_LOCATIONS) {
|
||||||
@@ -37,7 +31,63 @@ if (!tsProtoExecutableLocation) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const root of roots) {
|
// for (const root of ROOTS) {
|
||||||
|
// const filesRaw = await readdir(`${root}`);
|
||||||
|
// const files: string[] = [];
|
||||||
|
|
||||||
|
// 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=${tsProtoExecutableLocation}`,
|
||||||
|
// "--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}`,
|
||||||
|
// ...ROOTS.map((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) {
|
||||||
|
// const file = files.pop();
|
||||||
|
// command += newLine;
|
||||||
|
// // console.log(` ${file}`);
|
||||||
|
// } else {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await exec(command);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
await mkdir("temp", { recursive: true });
|
||||||
|
|
||||||
|
for (const root of ROOTS) {
|
||||||
|
let args = "";
|
||||||
|
|
||||||
|
for (const include of ROOTS) {
|
||||||
|
args += `-I=${include}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
args += `--plugin=${tsProtoExecutableLocation}\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`;
|
||||||
|
|
||||||
const filesRaw = await readdir(`${root}`);
|
const filesRaw = await readdir(`${root}`);
|
||||||
const files: string[] = [];
|
const files: string[] = [];
|
||||||
|
|
||||||
@@ -46,34 +96,6 @@ for (const root of roots) {
|
|||||||
if (file.endsWith(".ts")) await rm(`${root}/${file}`);
|
if (file.endsWith(".ts")) await rm(`${root}/${file}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (files.length > 0) {
|
await writeFile("temp/protoc.txt", args);
|
||||||
let command = [
|
execFile("protoc", ["@temp/protoc.txt"]);
|
||||||
"protoc",
|
|
||||||
`--plugin=${tsProtoExecutableLocation}`,
|
|
||||||
"--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}`,
|
|
||||||
...roots.map((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) {
|
|
||||||
const file = files.pop();
|
|
||||||
command += newLine;
|
|
||||||
// console.log(` ${file}`);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await exec(command);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user