2021-05-25 14:33:44 +00:00
|
|
|
#!/bin/bash
|
2019-03-06 20:13:50 +00:00
|
|
|
|
2019-03-12 22:34:45 +00:00
|
|
|
set -e
|
|
|
|
|
2021-05-25 14:33:44 +00:00
|
|
|
# generate compiles the *.pb.go stubs from the *.proto files.
|
|
|
|
function generate() {
|
|
|
|
# Generate the gRPC bindings for all proto files.
|
|
|
|
for file in ./*.proto
|
|
|
|
do
|
2021-12-13 11:56:40 +00:00
|
|
|
protoc -I/usr/local/include -I. -I.. \
|
2021-07-29 11:32:53 +00:00
|
|
|
--go_out . --go_opt paths=source_relative \
|
|
|
|
--go-grpc_out . --go-grpc_opt paths=source_relative \
|
2021-05-25 14:33:44 +00:00
|
|
|
"${file}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Generate the REST reverse proxy for the client only.
|
2021-12-13 11:56:40 +00:00
|
|
|
protoc -I/usr/local/include -I. -I.. \
|
2021-07-29 11:32:53 +00:00
|
|
|
--grpc-gateway_out . \
|
|
|
|
--grpc-gateway_opt logtostderr=true \
|
|
|
|
--grpc-gateway_opt paths=source_relative \
|
|
|
|
--grpc-gateway_opt grpc_api_configuration=client.yaml \
|
|
|
|
client.proto
|
2019-03-12 22:34:45 +00:00
|
|
|
|
2021-05-25 14:33:44 +00:00
|
|
|
# Finally, generate the swagger file which describes the REST API in detail.
|
2021-12-13 11:56:40 +00:00
|
|
|
protoc -I/usr/local/include -I. -I.. \
|
2021-07-29 11:32:53 +00:00
|
|
|
--openapiv2_out . \
|
|
|
|
--openapiv2_opt logtostderr=true \
|
|
|
|
--openapiv2_opt grpc_api_configuration=client.yaml \
|
|
|
|
--openapiv2_opt json_names_for_fields=false \
|
|
|
|
client.proto
|
2021-07-26 16:44:31 +00:00
|
|
|
|
|
|
|
# Generate the JSON/WASM client stubs.
|
|
|
|
falafel=$(which falafel)
|
|
|
|
pkg="looprpc"
|
2022-09-08 14:31:04 +00:00
|
|
|
opts="package_name=$pkg,js_stubs=1"
|
2021-07-26 16:44:31 +00:00
|
|
|
protoc -I/usr/local/include -I. -I.. \
|
|
|
|
--plugin=protoc-gen-custom=$falafel\
|
|
|
|
--custom_out=. \
|
|
|
|
--custom_opt="$opts" \
|
|
|
|
client.proto
|
2021-05-25 14:33:44 +00:00
|
|
|
}
|
2019-03-06 23:38:36 +00:00
|
|
|
|
2021-05-25 14:33:44 +00:00
|
|
|
# format formats the *.proto files with the clang-format utility.
|
|
|
|
function format() {
|
|
|
|
find . -name "*.proto" -print0 | xargs -0 clang-format --style=file -i
|
|
|
|
}
|
|
|
|
|
|
|
|
# Compile and format the looprpc package.
|
|
|
|
pushd looprpc
|
|
|
|
format
|
|
|
|
generate
|
|
|
|
popd
|