Skip to content

Instantly share code, notes, and snippets.

@kiishi
Created February 12, 2020 09:53
Show Gist options
  • Select an option

  • Save kiishi/60743ae81c0f3cea6706255befce4857 to your computer and use it in GitHub Desktop.

Select an option

Save kiishi/60743ae81c0f3cea6706255befce4857 to your computer and use it in GitHub Desktop.
GENERATE TYPESCRIPT TYPINGS FROM PROTOCOL BUFFERS ( GRPC )

npm install protobufjs

create a bash script with this content in it

SRC_DIR= #folder containing protofiles
DEST_DIR=#destition directory

if [ ! -d "${DEST_DIR}" ]; then
    mkdir ${DEST_DIR}
fi


# generate js files
node_modules/.bin/pbjs \
--target static-module \
--wrap commonjs \
--keep-case \
--path ${SRC_DIR} \
--out ${DEST_DIR}/out.js \
${SRC_DIR}/**/*.proto

# generate typings
node_modules/.bin/pbts \
--out ${DEST_DIR}/out.d.ts \
${DEST_DIR}/out.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment