bdledger-apis/grpc/scripts/gen.sh

105 lines
3.1 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2020-04-07 18:26:57 +00:00
# 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
2020-04-07 18:26:57 +00:00
# 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
2020-06-16 07:12:53 +00:00
vplugin=protoc-gen-govalidators
which $vplugin > /dev/null
if [ $? -ne 0 ];then
echo "missing plugin: $vplugin" && exit
fi
2020-04-07 18:26:57 +00:00
out="$gen_dir/go"
if [ ! -d $out ]; then
mkdir -p $out
fi
echo "Generating Go code"
2020-06-16 07:12:53 +00:00
$exec --go_out=plugins=grpc:$out --govalidators_out=$out $pb_files $async_tag
2020-04-07 18:26:57 +00:00
fi
2020-06-08 09:24:03 +00:00
if [ $aug == "gohttp" ]; then
plugin=protoc-gen-grpc-gateway
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 HTTP code"
$exec --grpc-gateway_out=grpc_api_configuration=bdware/bdledger/api/grpc-gateway.yml,logtostderr=true:$out $pb_files $async_tag
fi
2020-04-07 18:26:57 +00:00
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