feat: add ts-proto for new TypeScript SDK
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user