-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproto.sh
More file actions
executable file
·66 lines (53 loc) · 1.56 KB
/
proto.sh
File metadata and controls
executable file
·66 lines (53 loc) · 1.56 KB
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
#!/bin/bash
set -eou pipefail
shopt -s globstar
clean_generated_files() {
find "$1" -type f \( \
-name '*_pb2.py' -o \
-name '*_pb2.pyi' -o \
-name '*_pb2_grpc.py' -o \
-name '*_grpc.py' -o \
-name '*.pyc' \
\) -delete
find "$1" -type d -name '__pycache__' -exec rm -rf {} +
}
PROTO_DIR="${1:-proto}"
OUT_DIR="${2:-src}"
GATEWAY_DIR="${3:-gateway/pkg/pb}"
APIDOCS_DIR="${4:-gateway/apidocs}"
# Ensure output directory exists.
mkdir -p "${OUT_DIR}"
# Clean previously generated files.
clean_generated_files "${OUT_DIR}"
# Generate protobuf files.
python -m grpc_tools.protoc \
-I"${PROTO_DIR}" \
--python_out="${OUT_DIR}" \
--pyi_out="${OUT_DIR}" \
--grpc_python_out="${OUT_DIR}" \
"${PROTO_DIR}"/**/*.proto
# Clean previously generated files.
rm -rf "${GATEWAY_DIR}"/* && \
mkdir -p "${GATEWAY_DIR}"
# Generate gateway code.
protoc \
-I"${PROTO_DIR}" \
--go_out="${GATEWAY_DIR}" \
--go_opt=paths=source_relative \
--go-grpc_out=require_unimplemented_servers=false:"${GATEWAY_DIR}" \
--go-grpc_opt=paths=source_relative \
--grpc-gateway_out=logtostderr=true:"${GATEWAY_DIR}" \
--grpc-gateway_opt paths=source_relative \
"${PROTO_DIR}"/*.proto
# Clean previously generated files.
rm -rf "${APIDOCS_DIR}"/* && \
mkdir -p "${APIDOCS_DIR}"
# Generate swagger.json file.
protoc \
-I"${PROTO_DIR}" \
--openapiv2_out "${APIDOCS_DIR}" \
--openapiv2_opt logtostderr=true \
--openapiv2_opt use_go_templates=true \
"${PROTO_DIR}"/*.proto
# Remove google directory since the protobuf package already includes it.
rm -rf src/google