-
Notifications
You must be signed in to change notification settings - Fork 436
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
protoc-gen-improbable-eng-grpc-web Hello World #368
base: master
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't comment on the TS stuff as I'm mostly incapable, but I'm confused by some of the structure.
@@ -0,0 +1,3 @@ | |||
#!/usr/bin/env node | |||
|
|||
require('../lib/index'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
GENERATION_DIR=${GENERATION_DIR-${SCRIPT_DIR}/${PROTOGEN_DIR}} | ||
|
||
mkdir -p ${GENERATION_DIR} 2> /dev/null | ||
PROTO_SOURCES=$(npx glob-cli2 './proto/**/*.proto') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
There was a problem hiding this comment.
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.
--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} |
There was a problem hiding this comment.
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?
Hello World 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
This package uses protoc-plugin which provides the ability to extract comments from the source proto and in-line them into the generated code; this was a much requested feature on ts-protoc-gen
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: