Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: add generators for typescript defs #2422

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions Dockerfile.toast
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
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 \
yarn

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 yarn global add \
@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.

4 changes: 2 additions & 2 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 Down
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/view": {
"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"
}
}
}
}
}
30 changes: 28 additions & 2 deletions toast.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
image: gcr.io/windmill-public-containers/tilt-toast@sha256:232b4f5b187da1bedc3bd6fcc0d07a8d33c169fa9430ac0105da7efb5a65ca9f
image: gcr.io/windmill-public-containers/tilt-toast@sha256:481cd7eb12dc5b82ea5f6832b2895f914a6b21621dbb122ea5290ae73bb0d1b3
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: |
set -euo pipefail
swagger-to-ts pkg/webview/view.swagger.json --camelcase --output web/src/view.d.ts
cd web && prettier --write src/view.d.ts


wire:
location: /go/src/github.com/windmilleng/tilt
input_paths:
Expand Down
1 change: 1 addition & 0 deletions web/.prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/__snapshots__/**/*
src/view.d.ts
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the main thing to look at

separately, we should strategize on how to substitute these generated types for the handwritten types in types.ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aww, it makes all of these optional fields? Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in proto3, fields can only be optional. there's some good discussion here:
protocolbuffers/protobuf#2497
https://capnproto.org/faq.html#how-do-i-make-a-field-required-like-in-protocol-buffers

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 {}
}