Skip to content

Instantly share code, notes, and snippets.

@navono
Last active June 13, 2019 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navono/8dbc8962585825d5321f995dd2f99564 to your computer and use it in GitHub Desktop.
Save navono/8dbc8962585825d5321f995dd2f99564 to your computer and use it in GitHub Desktop.
proto shell 编译脚本
#! /bin/bash
# test.sh
PROTOC_GEN_TS_PATH=$(pwd)/node_modules/.bin/protoc-gen-ts.cmd
# Directory to write generated code to
OUT_DIR="./generated"
JS_DIR=$OUT_DIR/js
GO_DIR=$OUT_DIR/go
SWAGGER_DIR=$OUT_DIR/swagger
mkdir -p $JS_DIR
mkdir -p $GO_DIR
mkdir -p $SWAGGER_DIR
function compile {
for file in $1/*
do
if [ -d "$file" ]; then
compile $file
else
##check for the file
ext="${file##*.}"
if [[ -f "$file" ]] && [[ "$ext" = "proto" ]] ; then
protoc -I. -Ithird_party \
--js_out=import_style=commonjs,binary:$JS_DIR \
--ts_out=service=true:$JS_DIR \
--go_out=plugins=grpc:$GO_DIR \
--grpc-gateway_out=logtostderr=true:$GO_DIR \
--swagger_out=logtostderr=true:$SWAGGER_DIR \
--lint_out=. $file
fi
fi
done
}
echo "proto files compiling..."
# 运行需要编译的 proto 目录
compile ./are
@navono
Copy link
Author

navono commented Jun 13, 2019

Windows 运行 Docker:

docker run --rm -v %cd%:/data -w /data navono007/proto-compiler /bin/bash ./protoc.sh

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