-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-proto.ts
31 lines (27 loc) · 922 Bytes
/
generate-proto.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { execSync } from 'child_process';
import { readdirSync, statSync } from 'fs';
import { join } from 'path';
function findProtoFiles(dir: string): string[] {
let files: string[] = [];
const entries = readdirSync(dir);
for (const entry of entries) {
const fullPath = join(dir, entry);
if (statSync(fullPath).isDirectory()) {
files = files.concat(findProtoFiles(fullPath));
} else if (entry.endsWith('.proto')) {
files.push(fullPath);
}
}
return files;
}
function compileProtos(): void {
const protoFiles = findProtoFiles('protos');
if (protoFiles.length === 0) {
console.log('No .proto files found.');
return;
}
const command = `protoc --ts_out src/generated --ts_opt long_type_string --ts_opt optimize_code_size --proto_path protos ${protoFiles.join(' ')}`;
console.log(`Running: ${command}`);
execSync(command, { stdio: 'inherit' });
}
compileProtos();