Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Created May 10, 2020 13:46
Show Gist options
  • Save badsyntax/75fcf5e8da5c23d9fed43c6332f56ad1 to your computer and use it in GitHub Desktop.
Save badsyntax/75fcf5e8da5c23d9fed43c6332f56ad1 to your computer and use it in GitHub Desktop.
Generate grpc-js typescript files
#!/usr/bin/env bash
OUT_DIR="./out"
TS_OUT_DIR="./src"
IN_DIR="./proto"
PROTOC="$(npm bin)/grpc_tools_node_protoc"
PROTOC_GEN_TS="$(npm bin)/protoc-gen-ts"
mkdir -p "$OUT_DIR"
$PROTOC \
-I=./ \
--plugin=protoc-gen-ts=$PROTOC_GEN_TS \
--js_out=import_style=commonjs:$OUT_DIR \
--grpc_out=:$OUT_DIR \
--ts_out=service=grpc-node:$TS_OUT_DIR \
"$IN_DIR"/service.proto
sed -i "" -e \
"s/require('grpc')/require('@grpc\/grpc-js')/g" \
"$OUT_DIR/$IN_DIR/"*
sed -i "" -e \
"s/from \"grpc\"/from \"@grpc\/grpc-js\"/g" \
"$TS_OUT_DIR/$IN_DIR/"*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment