refactor: support invoke tasks.py from other dir

This commit is contained in:
Nex Zhu 2021-07-16 18:13:11 +08:00
parent 6839c4f573
commit 9d77f65495
No known key found for this signature in database
GPG Key ID: 15C6254AD19362B4

View File

@ -1,6 +1,7 @@
from invoke import task
from pathlib import Path
from invoke import task
ROOT = Path(__file__).parent
PB_ROOT = ROOT / "pb"
@ -27,13 +28,14 @@ def gen(c, target="types"):
"""
Generate gRPC client code.
"""
outDir = "gen/types"
outDir = "gen/" + target
paths = Path(PB_ROOT).glob('**/*.proto')
for path in paths:
# because path is object not string
pathStr = str(path)
print("Generating f or", pathStr)
print("Generating for", pathStr)
cmd = Path(c.run("npm bin").stdout.rstrip()).joinpath("proto-loader-gen-types")
c.run(
"npx proto-loader-gen-types --includeComments --grpcLib @grpc/grpc-js -I pb -O {} {}"
.format(outDir, pathStr)
"{} --includeComments --grpcLib @grpc/grpc-js -I pb -O {} {}"
.format(cmd, outDir, pathStr)
)