Skip to content

Commit

Permalink
[supervisor] Provide TypeScript clients for gRPC, gRPC-web and REST
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Weichel committed Sep 24, 2020
1 parent 9cb4125 commit 282346e
Show file tree
Hide file tree
Showing 38 changed files with 330 additions and 7,698 deletions.
2 changes: 1 addition & 1 deletion components/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ packages:
- components/ws-proxy:docker
- components/ws-sync:docker
- components/gitpod-protocol:publish
- components/supervisor-api/typescript:publish
- components/supervisor-api/typescript-grpc:publish
- name: all-apps
type: generic
deps:
Expand Down
10 changes: 10 additions & 0 deletions components/supervisor-api/BUILD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
packages:
- name: proto
type: generic
srcs:
- "*.proto"
config:
commands:
- ["git", "clone", "https://github.com/grpc-ecosystem/grpc-gateway"]
- ["mv", "grpc-gateway/third_party", "third_party"]
- ["rm", "-r", "grpc-gateway"]
19 changes: 1 addition & 18 deletions components/supervisor-api/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ PROTOC_INCLUDE="-I. -I $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_

GO111MODULE=on go get github.com/golang/protobuf/[email protected]
GO111MODULE=off go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
GO111MODULE=off go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
protoc $PROTOC_INCLUDE --go_out=plugins=grpc:go *.proto
protoc $PROTOC_INCLUDE --grpc-gateway_out=allow_colon_final_segments=true,logtostderr=true,paths=source_relative:go *.proto

# GO111MODULE=on go get github.com/golang/mock/mockgen@latest
# cd go
# # source mode does not always work for gRPC: see https://github.com/golang/mock/pull/163
# mockgen -package mock github.com/gitpod-io/gitpod/ws-manager/api WorkspaceManagerClient,WorkspaceManager_SubscribeClient > mock/mock.go
# cd ..

# generate typescript client
cd typescript
export PATH=$PWD/../../../node_modules/.bin:$PATH
protoc $PROTOC_INCLUDE --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` --js_out=import_style=commonjs,binary:src --grpc_out=grpc_js:src -I.. ../*.proto
protoc $PROTOC_INCLUDE --plugin=protoc-gen-ts=`which protoc-gen-ts` --ts_out=grpc_js:src -I.. ../*.proto

## HACK: we don't care for the API annotations in the generated Javascript/Typescript code.
## Rather than trying to make the dependencies work, we just remove the respective code.
sed -i '/google_api_annotations_pb/d' src/*.js

cd ..
2 changes: 2 additions & 0 deletions components/supervisor-api/typescript-grpc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/
lib/
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ packages:
- name: lib
type: yarn
srcs:
- "src/*.ts"
- "src/*.js"
- package.json
deps:
- components/supervisor-api:proto
env:
- PROTOLOC=components-supervisor-api--proto
config:
packaging: library
dontTest: true
Expand All @@ -21,4 +23,4 @@ packages:
- version
config:
commands:
- ["node", "components-gitpod-protocol--scripts/publish.js", "${version}", "components-supervisor-api-typescript--lib/package"]
- ["node", "components-gitpod-protocol--scripts/publish.js", "${version}", "components-supervisor-api-typescript-grpc--lib/package"]
23 changes: 23 additions & 0 deletions components/supervisor-api/typescript-grpc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@gitpod/supervisor-api-grpc",
"version": "0.1.5",
"license": "UNLICENSED",
"scripts": {
"prepare": "mkdir -p src; protoc -I ${PROTOLOC:-$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway}/third_party/googleapis -I /usr/lib/protoc/include --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` --js_out=import_style=commonjs,binary:src --grpc_out=grpc_js:src -I${PROTOLOC:-..} ${PROTOLOC:-..}/*.proto && protoc -I ${PROTOLOC:-$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway}/third_party/googleapis -I /usr/lib/protoc/include --plugin=protoc-gen-ts=`which protoc-gen-ts` --ts_out=grpc_js:src -I${PROTOLOC:-..} ${PROTOLOC:-..}/*.proto && sed -i '/google_api_annotations_pb/d' src/*.js",
"build": "mkdir -p lib; tsc && cp -f src/*.js src/*d.ts lib"
},
"files": [
"lib",
"src"
],
"dependencies": {
"@grpc/grpc-js": "^1.1.5",
"google-protobuf": "^3.8.0-rc.1"
},
"devDependencies": {
"@types/google-protobuf": "^3.2.7",
"grpc-tools": "^1.7.2",
"grpc_tools_node_protoc_ts": "^2.5.0",
"typescript-formatter": "^7.2.2"
}
}
4 changes: 4 additions & 0 deletions components/supervisor-api/typescript-grpcweb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*_pb.*ts
*_pb.*js
*_pb_service.*js
*_pb_service.*ts
26 changes: 26 additions & 0 deletions components/supervisor-api/typescript-grpcweb/BUILD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
packages:
- name: lib
type: yarn
srcs:
- package.json
deps:
- components/supervisor-api:proto
env:
- PROTOLOC=components-supervisor-api--proto
config:
packaging: library
dontTest: true
commands:
build: ["yarn", "build"]
yarnLock: ${coreYarnLockBase}/../yarn.lock
tsconfig: tsconfig.json
- name: publish
type: generic
deps:
- :lib
- components/gitpod-protocol:scripts
argdeps:
- version
config:
commands:
- ["node", "components-gitpod-protocol--scripts/publish.js", "${version}", "components-supervisor-api-typescript-grpcweb--lib/package"]
18 changes: 18 additions & 0 deletions components/supervisor-api/typescript-grpcweb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@gitpod/supervisor-api-grpcweb",
"version": "0.1.5",
"license": "UNLICENSED",
"scripts": {
"prepare": "mkdir -p src; protoc -I ${PROTOLOC:-$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway}/third_party/googleapis -I /usr/lib/protoc/include --plugin=\"protoc-gen-ts=`which protoc-gen-ts`\" --js_out=\"import_style=commonjs,binary:src\" --ts_out=\"service=grpc-web:src\" -I${PROTOLOC:-..} ${PROTOLOC:-..}/*.proto",
"build": "mkdir -p lib; tsc && cp -f src/*.js src/*d.ts lib",
"full-build": "yarn prepare && yarn build"
},
"files": [
"lib",
"src"
],
"dependencies": {},
"devDependencies": {
"ts-protoc-gen": "^0.13.0"
}
}
28 changes: 28 additions & 0 deletions components/supervisor-api/typescript-grpcweb/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"rootDir": "src",
"experimentalDecorators": true,
"outDir": "lib",
"lib": [
"es6",
"esnext.asynciterable"
],
"strict": true,
"noEmitOnError": false,
"noUnusedLocals": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"downlevelIteration": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"jsx": "react",
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"skipLibCheck": true
},
"include": [
"src"
]
}
1 change: 1 addition & 0 deletions components/supervisor-api/typescript-rest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/
26 changes: 26 additions & 0 deletions components/supervisor-api/typescript-rest/BUILD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
packages:
- name: lib
type: yarn
srcs:
- package.json
deps:
- components/supervisor-api:proto
env:
- PROTOLOC=components-supervisor-api--proto
config:
packaging: library
dontTest: true
commands:
build: ["yarn", "build"]
yarnLock: ${coreYarnLockBase}/../yarn.lock
tsconfig: tsconfig.json
- name: publish
type: generic
deps:
- :lib
- components/gitpod-protocol:scripts
argdeps:
- version
config:
commands:
- ["node", "components-gitpod-protocol--scripts/publish.js", "${version}", "components-supervisor-api-typescript-rest--lib/package"]
15 changes: 15 additions & 0 deletions components/supervisor-api/typescript-rest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@gitpod/supervisor-api-rest",
"version": "0.1.5",
"license": "UNLICENSED",
"scripts": {
"build": "mkdir -p lib; protoc -I ${PROTOLOC:-$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway}/third_party/googleapis -I /usr/lib/protoc/include --swagger_out=logtostderr=true:. -I${PROTOLOC:-..} ${PROTOLOC:-..}/*.proto && mv *.swagger.json lib && for f in $(ls lib/*.swagger.json); do yarn dtsgen -o ${f%.swagger.json}.dt.ts $f; done"
},
"files": [
"lib"
],
"dependencies": {},
"devDependencies": {
"dtsgenerator": "^3.3.0"
}
}
28 changes: 28 additions & 0 deletions components/supervisor-api/typescript-rest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"rootDir": "src",
"experimentalDecorators": true,
"outDir": "lib",
"lib": [
"es6",
"esnext.asynciterable"
],
"strict": true,
"noEmitOnError": false,
"noUnusedLocals": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"downlevelIteration": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"jsx": "react",
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"skipLibCheck": true
},
"include": [
"src"
]
}
23 changes: 0 additions & 23 deletions components/supervisor-api/typescript/package.json

This file was deleted.

46 changes: 0 additions & 46 deletions components/supervisor-api/typescript/src/backup_grpc_pb.d.ts

This file was deleted.

54 changes: 0 additions & 54 deletions components/supervisor-api/typescript/src/backup_grpc_pb.js

This file was deleted.

Loading

0 comments on commit 282346e

Please sign in to comment.