Skip to content
Open
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
Hello World!
Proof of concept protoc-plugin for generating service clients for use with @improbable-eng/grpc-web.

## Why?
See conversation in improbable-eng/ts-protoc-gen#145

## Design Choices
1. This package uses [protoc-plugin](https://github.com/konsumer/node-protoc-plugin) which provides the ability to [extract comments from the source proto](https://github.com/konsumer/node-protoc-plugin#findcommentbypath) and in-line them into the generated code; this was a much requested feature on ts-protoc-gen

2. [ts-morph](https://dsherret.github.io/ts-morph/) is used to build TypeScript source code in-line; this is then compiled into TypeScript definition files (`.d.ts`) and JavaScript source files. This is great as it reduces the number of code-paths required.

## What's left to do?
Loads, off the top of my head:

1. Generate service clients, at present we are only generating classes required to use directly against grpc-web ("Raw!")
2. Add unit/integration test coverage!
3. Add support for in-lined documentation from source protos.
  • Loading branch information
jonny-improbable committed Mar 8, 2019
commit d82a2f192486d85c4d0bbaae37ded488f34bc2d9
16 changes: 16 additions & 0 deletions client/protoc-gen-improbable-grpc-web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @improbable-eng/protoc-gen-improbable-grpc-web
protoc-plugin for generating @improbable-eng/grpc-web service clients.

## Usage
This plugin should be used in conjunction with the [protoc-js plugin](https://developers.google.com/protocol-buffers/docs/reference/javascript-generated) with the following caveats:
1. The output directory must be consistent between both plugins (ie: `js_out` and `improbable-grpc-web_out`).
2. You must use `import_style=commonjs,binary` in your protoc-js plugin configuration.

```bash
OUT_DIR="generated"
protoc \
--plugin=protoc-gen-improbable-grpc-web=./bin/protoc-gen-improbable-grpc-web \
--js_out=import_style=commonjs,binary:${OUT_DIR} \
--improbable-grpc-web_out=${OUT_DIR} \
./proto/some.proto
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../lib/index');
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's how node/npm manages binaries. This file will be automagically chmod +x'd when you npm install allowing the end user to invoke it like a binary. You can also invoke these bins via npm scripts (defined inside the package.json) or via the npx command.

15 changes: 15 additions & 0 deletions client/protoc-gen-improbable-grpc-web/generate-protos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
PROTOBUF_DIR=${PROTOBUF_DIR-${SCRIPT_DIR}/proto}
PROTOGEN_DIR=generated/_proto
GENERATION_DIR=${GENERATION_DIR-${SCRIPT_DIR}/${PROTOGEN_DIR}}

mkdir -p ${GENERATION_DIR} 2> /dev/null
PROTO_SOURCES=$(npx glob-cli2 './proto/**/*.proto')
Copy link
Contributor

Choose a reason for hiding this comment

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

😱

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, fair, this script was hacky AF! Your suggestion of prototool is a good one.


protoc \
--plugin=protoc-gen-improbable-grpc-web=./bin/protoc-gen-improbable-grpc-web \
--js_out=import_style=commonjs,binary:${GENERATION_DIR} \
--improbable-grpc-web_out=service=true:${GENERATION_DIR} \
${PROTO_SOURCES}
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered something like https://github.com/uber/prototool to simplify this?

Loading