forked from otrego/clamshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regenerate-proto.sh
executable file
·57 lines (47 loc) · 1.52 KB
/
regenerate-proto.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
#!/bin/bash
set -e
cd "$(dirname "$0")"
DIR=$PWD
function generate_proto() {
protoc --go_out=plugins=grpc,paths=source_relative:. \
-I . \
-I ./third_party/googleapis \
-I ./third_party/grpc-gateway \
./server/api/*.proto
}
function generate_grpcgateway() {
protoc --grpc-gateway_out=logtostderr=true,paths=source_relative:. \
-I . \
-I ./third_party/googleapis \
-I ./third_party/grpc-gateway \
./server/api/*.proto
}
function generate_swagger_json() {
protoc --swagger_out=logtostderr=true:. \
-I . \
-I ./third_party/googleapis \
-I ./third_party/grpc-gateway \
./server/api/*.proto
}
# Manually go-embed the swagger into a go file.
function generate_swagger_goembed() {
# This is quite hacky -- we should use go-bindata or even go generate. For now,
# it's mega simple. See https://github.com/otrego/clamshell/issues/40
SWAG_GO="./server/api/api.swagger.go"
SWAG_JSON="./server/api/api.swagger.json"
echo '// ---- Do not edit! This file was autogenerated by regenerate-proto.sh ----' > "${SWAG_GO}"
echo '' >> "${SWAG_GO}"
echo 'package api' >> "${SWAG_GO}"
echo '' >> "${SWAG_GO}"
echo '// Swagger contains embedded swagger data.' >> "${SWAG_GO}"
echo 'const Swagger = `' >> "${SWAG_GO}"
cat "${SWAG_JSON}" | sed 's/`/'"'"'/g' >> "${SWAG_GO}"
echo '`' >> "${SWAG_GO}"
# Remove the swagger.json file; we don't need it since it's embedded in a
# go-file.
rm "${SWAG_JSON}"
}
generate_proto
generate_grpcgateway
generate_swagger_json
generate_swagger_goembed