-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.sh
89 lines (77 loc) · 2.34 KB
/
gen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s nullglob
cd "$(dirname "$0")"
root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
vendor=${root}/vendor
# generators
protoc=$(which protoc)
$protoc --version
#grpc_tools_node_protoc=$(which ./node_modules/.bin/grpc_tools_node_protoc)
#$grpc_tools_node_protoc --version
# plugins
PROTOC_GEN_TS_PATH="./node_modules/.bin/protoc-gen-ts"
JS_PLUGIN_PATH="./node_modules/.bin/grpc_tools_node_protoc_plugin"
# directories to compile
imports=(
"${vendor}/envoy/api/v2"
"${vendor}/envoy/config/filter/accesslog/v2"
"${vendor}/envoy/config/filter/http/ext_authz/v2"
"${vendor}/envoy/config/filter/http/lua/v2"
"${vendor}/envoy/config/filter/network/ext_authz/v2"
"${vendor}/envoy/config/filter/network/http_connection_manager/v2"
"${vendor}/envoy/config/filter/network/mysql_proxy"
"${vendor}/envoy/config/filter/network/tcp_proxy/v2"
"${vendor}/envoy/config/listener/v2"
"${vendor}/envoy/service/discovery/v2"
"${vendor}/envoy/type"
"${vendor}/opencensus/proto/resource"
"${vendor}/opencensus/proto/trace"
"${vendor}/udpa/annotations"
"${vendor}/validate"
)
# individual files to compile
importsi=(
"${vendor}/google/api/expr/v1alpha1/syntax.proto"
"${vendor}/google/api/annotations.proto"
"${vendor}/google/api/http.proto"
"${vendor}/google/rpc/status.proto"
"${vendor}/metrics.proto"
)
# Directory to write generated code to (.js and .d.ts files)
OUT_DIR="./lib"
for i in "${imports[@]}"
do
for path in $(find ${i} -type d)
do
path_protos=(${path}/*.proto)
if [[ ${#path_protos[@]} > 0 ]]
then
echo "${path} ..."
$protoc --proto_path=${vendor} \
--js_out="import_style=commonjs,binary:${OUT_DIR}" \
--grpc_out=$OUT_DIR \
--plugin="protoc-gen-grpc=$JS_PLUGIN_PATH" \
${path}/*.proto
$protoc --proto_path=${vendor} \
--plugin="protoc-gen-ts=${PROTOC_GEN_TS_PATH}" \
--ts_out="${OUT_DIR}" \
${path}/*.proto
fi
done
done
for i in "${importsi[@]}"
do
echo "${i} ..."
$protoc --proto_path=${vendor} \
--js_out="import_style=commonjs,binary:${OUT_DIR}" \
--grpc_out=$OUT_DIR \
--plugin="protoc-gen-grpc=$JS_PLUGIN_PATH" \
${i}
$protoc --proto_path=${vendor} \
--plugin="protoc-gen-ts=${PROTOC_GEN_TS_PATH}" \
--ts_out="${OUT_DIR}" \
${i}
done