-
Notifications
You must be signed in to change notification settings - Fork 46
/
protos.js
53 lines (48 loc) · 1.54 KB
/
protos.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint-disable @typescript-eslint/no-require-imports */
const path = require('path');
const childProcess = require('child_process');
const protoDir = path.join(__dirname, 'proto');
const protoDirHold = path.join(__dirname, 'hold/protos');
const protoDirMpay = path.join(__dirname, 'tools/plugins/mpay/protos');
const protoDirSidecar = path.join(__dirname, 'boltzr/protos');
const libDir = path.join(__dirname, 'lib/proto');
const protocPath = path.join(
__dirname,
'node_modules/.bin/grpc_tools_node_protoc',
);
const protocGenTsPath = path.join(__dirname, 'node_modules/.bin/protoc-gen-ts');
const protoPaths = [
[`--proto_path ${protoDir} ${protoDir}/*.proto`, libDir],
[`--proto_path ${protoDir} ${protoDir}/**/*.proto`, libDir],
[
`--proto_path ${protoDirHold} ${protoDirHold}/*.proto`,
path.join(libDir, 'hold'),
],
[
`--proto_path ${protoDirMpay} ${protoDirMpay}/*.proto`,
path.join(libDir, 'mpay'),
],
[
`--proto_path ${protoDirSidecar} ${protoDirSidecar}/*.proto`,
path.join(libDir, 'sidecar'),
],
];
for (const [path, lib] of protoPaths) {
try {
childProcess.execSync(
`${protocPath} ${[
`--grpc_out="grpc_js:${lib}"`,
`--js_out="import_style=commonjs,binary:${lib}"`,
].join(' ')} ${path}`,
);
childProcess.execSync(
`${protocPath} ${[
`--plugin="protoc-gen-ts=${protocGenTsPath}"`,
`--ts_out="grpc_js:${lib}"`,
].join(' ')} ${path}`,
);
} catch (e) {
console.error(`Could not compile protobuf: ${path}`);
console.log(e);
}
}