From 60aed81a2ae79870702595979c3158d19fdbb1c7 Mon Sep 17 00:00:00 2001 From: Hu Yingcong Date: Wed, 8 Apr 2020 02:26:57 +0800 Subject: [PATCH] update gen.sh --- grpc/scripts/gen.sh | 88 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 4 deletions(-) mode change 100644 => 100755 grpc/scripts/gen.sh diff --git a/grpc/scripts/gen.sh b/grpc/scripts/gen.sh old mode 100644 new mode 100755 index a184788..3535b38 --- a/grpc/scripts/gen.sh +++ b/grpc/scripts/gen.sh @@ -1,7 +1,87 @@ #!/usr/bin/env bash -cd "${0%/*}/.." || exit -gen=..\gen -pbs='bdware/bdledger/api/*.proto' +# check pb dir +pb_dir="$(cd "$(dirname $0)";pwd)/../pb" +if [ ! -d $pb_dir ]; then + echo "pb dir $pb_dir does not exist in grpc folder" + exit +fi +cd $pb_dir -# TODO +# check protoc +which protoc > /dev/null +if [ $? -ne 0 ];then + echo "missing protoc" && exit +fi + +gen_dir="$pb_dir/../gen" +pb_files="bdware/bdledger/api/*.proto" +empty_file="google/protobuf/empty.proto" + +exec=protoc +async_tag="" + +# check all arguments +for aug in $@ +do + if [ $aug == "-a" ]; then + async_tag="&" + fi + if [ $aug == "--async" ]; then + async_tag="&" + fi + if [ $aug == "go" ]; then + plugin=protoc-gen-go + which $plugin > /dev/null + if [ $? -ne 0 ];then + echo "missing plugin: $plugin" && exit + fi + out="$gen_dir/go" + if [ ! -d $out ]; then + mkdir -p $out + fi + echo "Generating Go code" + $exec --go_out=plugins=grpc:$out $pb_files $async_tag + fi + if [ $aug == "nodejs" ]; then + plugin=grpc_tools_node_protoc_plugin + plugin_path=$(which $plugin) + if [ $? -ne 0 ];then + echo "missing plugin: $plugin" && exit + fi + out="$gen_dir/nodejs" + if [ ! -d $out ]; then + mkdir -p $out + fi + echo "Generating Node.js code" + $exec --js_out=import_style=commonjs,binary:$out --grpc_out=$out --plugin=protoc-gen-grpc=$plugin_path $pb_files $empty_file $async_tag + fi + if [ $aug == "ts" ]; then + plugin=protoc-gen-ts + plugin_path=$(which $plugin) + if [ $? -ne 0 ];then + echo "missing plugin: $plugin" && exit + fi + out="$gen_dir/nodejs" + if [ ! -d $out ]; then + mkdir -p $out + fi + echo "Generating TypeScript code" + $exec --ts_out=$out -plugin=protoc-gen-ts=$plugin_path $pb_files $empty_file $async_tag + fi + if [ $aug == "docs" ]; then + plugin=protoc-gen-ts + plugin_path=$(which $plugin) + if [ $? -ne 0 ];then + echo "missing plugin: $plugin" && exit + fi + out="$pb_dir/../../docs" + if [ ! -d $out ]; then + mkdir -p $out + fi + echo "Generating documentations" + $exec --doc_out=$out --doc_opt=html,apis.html $pb_files $empty_file $async_tag + $exec --doc_out=$out --doc_opt=markdown,apis.md $pb_files $empty_file $async_tag + $exec --doc_out=$out --doc_opt=json,apis.json $pb_files $empty_file $async_tag + fi +done \ No newline at end of file