feat: add ts-proto for new TypeScript SDK

This commit is contained in:
Nex Zhu
2021-07-22 16:21:15 +08:00
parent 345adce56e
commit dc6ca140e7
4 changed files with 196 additions and 19 deletions

View File

@@ -1,3 +1,5 @@
import os
import platform
from pathlib import Path
from invoke import task
@@ -28,14 +30,25 @@ def gen(c, target="types"):
"""
Generate gRPC client code.
"""
outDir = "gen/" + target
paths = Path(PB_ROOT).glob('**/*.proto')
for path in paths:
# because path is object not string
pathStr = str(path)
print("Generating for", pathStr)
cmd = Path(c.run("npm bin").stdout.rstrip()).joinpath("proto-loader-gen-types")
c.run(
"{} --includeComments --grpcLib @grpc/grpc-js -I pb -O {} {}"
.format(cmd, outDir, pathStr)
)
out_dir = "gen/" + target
if not os.path.exists(out_dir):
os.mkdir(out_dir)
npmbin_path = Path(c.run("npm bin").stdout.rstrip())
if target == "ts":
plugin_path = npmbin_path / ("protoc-gen-ts_proto" + (".cmd" if platform.system() == "Windows" else ""))
cmd = "protoc --plugin=protoc-gen-ts_proto={} --ts_proto_opt=outputServices=grpc-js --ts_proto_out={} -I pb {}".format(
plugin_path, out_dir, "./pb/bdware/bdledger/api/*.proto")
print(cmd)
c.run(cmd)
elif target == "types":
paths = Path(PB_ROOT).glob('**/*.proto')
for path in paths:
# because path is object not string
path_str = str(path)
print("Generating for", path_str)
cmd = "npx proto-loader-gen-types --includeComments --grpcLib @grpc/grpc-js -I pb -O {} {}".format(
out_dir, path_str)
print(cmd)
c.run(cmd)