Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/scripts/protoc-generator.sh
2486 views
1
#!/bin/bash
2
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
# Licensed under the GNU Affero General Public License (AGPL).
4
# See License.AGPL.txt in the project root for license information.
5
6
7
install_dependencies() {
8
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1
9
10
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0
11
12
go install github.com/golang/mock/mockgen@v1.6.0
13
14
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.11.3
15
16
# To use buf as a codegeneration utility for protobuf plugins and linting
17
go install github.com/bufbuild/buf/cmd/buf@v1.8.0
18
19
# To generate connect-go (https://github.com/bufbuild/connect-go) interfaces
20
go install github.com/bufbuild/connect-go/cmd/protoc-gen-connect-go@v1.0.0
21
22
curl -sSo /tmp/protoc-gen-grpc-java https://repo1.maven.org/maven2/io/grpc/protoc-gen-grpc-java/1.49.0/protoc-gen-grpc-java-1.49.0-linux-x86_64.exe
23
chmod +x /tmp/protoc-gen-grpc-java
24
}
25
26
lint() {
27
buf lint || exit 1
28
}
29
30
protoc_buf_generate() {
31
buf generate || exit 1
32
}
33
34
go_protoc() {
35
local ROOT_DIR=$1
36
local PROTO_DIR=${2:-.}
37
# shellcheck disable=2035
38
protoc \
39
-I /usr/lib/protoc/include -I"$ROOT_DIR" -I. \
40
--go_out=go \
41
--go_opt=paths=source_relative \
42
--go-grpc_out=go \
43
--go-grpc_opt=paths=source_relative \
44
"${PROTO_DIR}"/*.proto
45
}
46
47
typescript_ts_protoc() {
48
local ROOT_DIR=$1
49
local PROTO_DIR=${2:-.}
50
local MODULE_DIR
51
# Assigning external program output directly
52
# after the `local` keyword masks the return value (Could be an error).
53
# Should be done in a separate line.
54
MODULE_DIR=$(pwd)
55
TARGET_DIR="$MODULE_DIR"/typescript/src
56
57
pushd typescript > /dev/null || exit
58
59
yarn install
60
61
rm -rf "$TARGET_DIR"
62
mkdir -p "$TARGET_DIR"
63
64
echo "[protoc] Generating TypeScript files"
65
protoc --plugin="$MODULE_DIR"/typescript/node_modules/.bin/protoc-gen-ts_proto \
66
--ts_proto_opt=context=true \
67
--ts_proto_opt=lowerCaseServiceMethods=true \
68
--ts_proto_opt=stringEnums=true \
69
--ts_proto_out="$TARGET_DIR" \
70
--ts_proto_opt=fileSuffix=.pb \
71
--ts_proto_opt=outputServices=nice-grpc,outputServices=generic-definitions,useExactTypes=false \
72
-I /usr/lib/protoc/include -I"$ROOT_DIR" -I.. -I"../$PROTO_DIR" \
73
"../$PROTO_DIR"/*.proto
74
75
popd > /dev/null || exit
76
}
77
78
typescript_protoc() {
79
local ROOT_DIR=$1
80
local PROTO_DIR=${2:-.}
81
local MODULE_DIR
82
# Assigning external program output directly
83
# after the `local` keyword masks the return value (Could be an error).
84
# Should be done in a separate line.
85
MODULE_DIR=$(pwd)
86
87
pushd typescript > /dev/null || exit
88
89
yarn install
90
91
rm -rf "$MODULE_DIR"/typescript/src/*pb*.*
92
93
echo "[protoc] Generating TypeScript files"
94
protoc \
95
--plugin=protoc-gen-grpc="$MODULE_DIR"/typescript/node_modules/.bin/grpc_tools_node_protoc_plugin \
96
--js_out=import_style=commonjs,binary:src \
97
--grpc_out=grpc_js:src \
98
-I /usr/lib/protoc/include -I"$ROOT_DIR" -I.. -I"../$PROTO_DIR" \
99
"../$PROTO_DIR"/*.proto
100
101
protoc \
102
--plugin=protoc-gen-ts="$MODULE_DIR"/typescript/node_modules/.bin/protoc-gen-ts \
103
--ts_out=grpc_js:src \
104
-I /usr/lib/protoc/include -I"$ROOT_DIR" -I.. -I"../$PROTO_DIR" \
105
"../$PROTO_DIR"/*.proto
106
107
# remove trailing spaces
108
find "$MODULE_DIR"/typescript/src -maxdepth 1 -name "*_pb.d.ts" -exec sed -i -e "s/[[:space:]]*$//" {} \;
109
110
popd > /dev/null || exit
111
}
112
113
update_license() {
114
leeway run components:update-license-header
115
}
116
117