from pathlib import Path from invoke import task ROOT = Path(__file__).parent PB_ROOT = ROOT / "pb" # @task # def clean(c, docs=False, bytecode=False, extra=""): # patterns = ["build"] # if docs: # patterns.append("docs/_build") # if bytecode: # patterns.append("**/*.pyc") # if extra: # patterns.append(extra) # for pattern in patterns: # c.run("rm -rf {}".format(pattern)) @task( help={ "target": "Target gRPC licent code to generate.", } ) 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) )