From 9d77f6549509b21ca605c8019a2f6a7fa91d1227 Mon Sep 17 00:00:00 2001 From: Nex Zhu <4370605+NexZhu@users.noreply.github.com> Date: Fri, 16 Jul 2021 18:13:11 +0800 Subject: [PATCH] refactor: support invoke tasks.py from other dir --- grpc/tasks.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/grpc/tasks.py b/grpc/tasks.py index a6496fd..4e8fccc 100644 --- a/grpc/tasks.py +++ b/grpc/tasks.py @@ -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) )