Skip to content

Commit

Permalink
web: add generators for typescript defs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Miller authored and nicks committed Oct 24, 2019
1 parent 0a02b14 commit 4f5b3ac
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 58 deletions.
28 changes: 24 additions & 4 deletions Dockerfile.toast
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
FROM golang:1.12-alpine
RUN apk update
RUN apk add protobuf protobuf-dev git wget make
RUN go get -u github.com/golang/protobuf/protoc-gen-go github.com/golang/protobuf/jsonpb github.com/golang/protobuf/proto github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway google.golang.org/grpc

RUN apk add \
protobuf \
protobuf-dev \
git \
wget \
make \
nodejs \
npm

RUN go get -u \
github.com/golang/protobuf/protoc-gen-go \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
google.golang.org/grpc \
github.com/google/wire/cmd/wire

RUN go get golang.org/x/tools/cmd/goimports
RUN cd /tmp && wget https://github.com/grpc/grpc-web/releases/download/1.0.6/protoc-gen-grpc-web-1.0.6-linux-x86_64 && mv protoc-gen-grpc-web-1.0.6-linux-x86_64 /usr/local/bin/protoc-gen-grpc-web && chmod +x /usr/local/bin/protoc-gen-grpc-web
RUN go get -u github.com/google/wire/cmd/wire

RUN cd /tmp && \
wget https://github.com/grpc/grpc-web/releases/download/1.0.6/protoc-gen-grpc-web-1.0.6-linux-x86_64 && \
mv protoc-gen-grpc-web-1.0.6-linux-x86_64 /usr/local/bin/protoc-gen-grpc-web && \
chmod +x /usr/local/bin/protoc-gen-grpc-web

RUN npm install -g @manifoldco/swagger-to-ts
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all proto install lint test test-go check-js test-js integration wire-check wire ensure check-go goimports
.PHONY: all proto install lint test test-go check-js test-js integration wire-check wire ensure check-go goimports proto-webview proto-webview-ts

check-go: lint errcheck verify_goimports wire-check test-go
all: check-go check-js test-js
Expand All @@ -23,11 +23,14 @@ scripts/protocc/protocc.py: scripts/protocc
git submodule init
git submodule update

toast.yaml:
proto: scripts/protocc/protocc.py
python3 scripts/protocc/protocc.py --out go

proto-webview:
toast proto

proto: scripts/protocc/protocc.py toast.yaml
python3 scripts/protocc/protocc.py --out go
proto-webview-ts:
toast proto-ts

# Build a binary that uses synclet:latest
install:
Expand Down
5 changes: 2 additions & 3 deletions internal/cli/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
"golang.org/x/sync/errgroup"
"k8s.io/klog"

"github.com/windmilleng/tilt/internal/engine"
"github.com/windmilleng/tilt/web"

"github.com/windmilleng/tilt/internal/analytics"
"github.com/windmilleng/tilt/internal/engine"
"github.com/windmilleng/tilt/internal/hud"
"github.com/windmilleng/tilt/internal/k8s"
"github.com/windmilleng/tilt/internal/output"
Expand All @@ -26,6 +24,7 @@ import (
"github.com/windmilleng/tilt/pkg/assets"
"github.com/windmilleng/tilt/pkg/logger"
"github.com/windmilleng/tilt/pkg/model"
"github.com/windmilleng/tilt/web"
)

const DefaultWebPort = 10350
Expand Down
82 changes: 41 additions & 41 deletions pkg/webview/view.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/webview/view.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/webview/view.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ message Resource {}

message TiltBuild {
string version = 1;
string commit_SHA = 2;
string commitSHA = 2;
string date = 3;
bool dev = 4;
}
Expand All @@ -28,7 +28,7 @@ message View {

string tilt_cloud_username = 8;
string tilt_cloud_schemeHost = 9;
string tilt_cloud_team_ID = 10;
string tilt_cloud_teamID = 10;

string fatal_error = 11;
}
Expand All @@ -38,7 +38,7 @@ message GetViewRequest {}
service ViewService {
rpc GetView(GetViewRequest) returns (View) {
option (google.api.http) = {
get: "/api/proto/view"
get: "/api/proto/webview.ViewService/GetView"
};
}
}
106 changes: 106 additions & 0 deletions pkg/webview/view.swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"swagger": "2.0",
"info": {
"title": "pkg/webview/view.proto",
"version": "version not set"
},
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/api/proto/webview.ViewService/GetView": {
"get": {
"operationId": "GetView",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/webviewView"
}
}
},
"tags": [
"ViewService"
]
}
}
},
"definitions": {
"webviewResource": {
"type": "object",
"title": "TODO(dmiller) fill this in"
},
"webviewTiltBuild": {
"type": "object",
"properties": {
"version": {
"type": "string"
},
"commitSHA": {
"type": "string"
},
"date": {
"type": "string"
},
"dev": {
"type": "boolean",
"format": "boolean"
}
}
},
"webviewView": {
"type": "object",
"properties": {
"log": {
"type": "string"
},
"resources": {
"type": "array",
"items": {
"$ref": "#/definitions/webviewResource"
}
},
"log_timestamps": {
"type": "boolean",
"format": "boolean"
},
"feature_flags": {
"type": "object",
"additionalProperties": {
"type": "boolean",
"format": "boolean"
}
},
"need_analytics_nudge": {
"type": "boolean",
"format": "boolean"
},
"running_tilt_build": {
"$ref": "#/definitions/webviewTiltBuild"
},
"latest_tilt_build": {
"$ref": "#/definitions/webviewTiltBuild"
},
"tilt_cloud_username": {
"type": "string"
},
"tilt_cloud_schemeHost": {
"type": "string"
},
"tilt_cloud_teamID": {
"type": "string"
},
"fatal_error": {
"type": "string"
}
}
}
}
}
27 changes: 25 additions & 2 deletions toast.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
image: gcr.io/windmill-public-containers/tilt-toast@sha256:232b4f5b187da1bedc3bd6fcc0d07a8d33c169fa9430ac0105da7efb5a65ca9f
image: gcr.io/windmill-public-containers/tilt-toast@sha256:f3dc747f3861ae274b72943ea511a46e9e760928507191fb8179480ae804933d
tasks:
proto:
input_paths:
- pkg/webview/view.proto
output_paths:
- pkg/webview/view.pb.go
- pkg/webview/view.pb.gw.go
command: protoc -I. -I/usr/include -I"$(go env GOPATH)"/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. --go_out=plugins=grpc,paths=source_relative:. pkg/webview/view.proto && goimports -local github.com/windmilleng/tft -w pkg/webview/view.pb.go
- pkg/webview/view.swagger.json
command: |
set -euo pipefail
mkdir -p web/src
protoc \
-I. \
-I/usr/include \
-I"$(go env GOPATH)"/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--grpc-gateway_out=logtostderr=true:. \
--swagger_out=logtostderr=true:. \
--go_out=plugins=grpc,paths=source_relative:. \
pkg/webview/view.proto
goimports -local github.com/windmilleng/tilt -w pkg/webview/view.pb.go
proto-ts:
dependencies:
- proto
input_paths:
- pkg/webview/view.swagger.json
output_paths:
- web/src/view.d.ts
command: |
npx @manifoldco/swagger-to-ts pkg/webview/view.swagger.json --camelcase --output web/src/view.d.ts
wire:
location: /go/src/github.com/windmilleng/tilt
input_paths:
Expand Down
22 changes: 22 additions & 0 deletions web/src/view.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
declare namespace OpenAPI2 {
export interface webviewView {
log?: string;
resources?: webviewResource[];
logTimestamps?: boolean;
featureFlags?: object;
needAnalyticsNudge?: boolean;
runningTiltBuild?: webviewTiltBuild;
latestTiltBuild?: webviewTiltBuild;
tiltCloudUsername?: string;
tiltCloudSchemeHost?: string;
tiltCloudTeamID?: string;
fatalError?: string;
}
export interface webviewTiltBuild {
version?: string;
commitSHA?: string;
date?: string;
dev?: boolean;
}
export interface webviewResource {}
}

0 comments on commit 4f5b3ac

Please sign in to comment.