mirror of
https://github.com/LuanRT/googlevideo.git
synced 2026-06-02 12:13:19 +00:00
Noticed YouTube returning very large int64 values, causing the protobuf library to throw.
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
import { exec } from 'child_process';
|
|
import { existsSync, mkdirSync, readdirSync, statSync } from 'fs';
|
|
import { join } from 'path';
|
|
import path from 'path';
|
|
import url from 'url';
|
|
import os from 'os';
|
|
|
|
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
|
|
const protoDir = './protos';
|
|
const outDir = './protos/generated';
|
|
|
|
if (!existsSync(outDir)) {
|
|
mkdirSync(outDir, { recursive: true });
|
|
}
|
|
|
|
const protocGenTs = path.join(
|
|
__dirname,
|
|
'../node_modules',
|
|
'.bin',
|
|
os.platform() === 'win32' ? 'protoc-gen-ts_proto.cmd' : 'protoc-gen-ts_proto'
|
|
);
|
|
|
|
function listProtoFiles(dir) {
|
|
let protoFiles = [];
|
|
const items = readdirSync(dir);
|
|
|
|
for (const item of items) {
|
|
const fullPath = join(dir, item);
|
|
if (statSync(fullPath).isDirectory()) {
|
|
protoFiles = protoFiles.concat(listProtoFiles(fullPath));
|
|
} else if (item.endsWith('.proto')) {
|
|
protoFiles.push(fullPath);
|
|
}
|
|
}
|
|
|
|
return protoFiles;
|
|
}
|
|
|
|
const protoFiles = listProtoFiles(protoDir);
|
|
|
|
if (!protoFiles.length) {
|
|
console.log('No .proto files found.');
|
|
process.exit(0);
|
|
}
|
|
|
|
protoFiles.forEach((file) => {
|
|
const command = `protoc --proto_path=${protoDir} --plugin=protoc-gen-ts=${protocGenTs} --ts_opt=env=browser --ts_opt=forceLong=string --ts_opt=importSuffix=.js --ts_out=${outDir} --ts_opt=outputJsonMethods=false --ts_opt=outputPartialMethods=false --ts_opt=removeEnumPrefix=true ${file}`;
|
|
exec(command, (error, _stdout, stderr) => {
|
|
if (error) {
|
|
console.error(`Error compiling ${file}:`, stderr);
|
|
}
|
|
});
|
|
}); |