-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
710 additions
and
976 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
bin | ||
dist | ||
node_modules | ||
test/test.js | ||
test/generated | ||
bin/ | ||
node_modules/ | ||
test/generated/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
bin | ||
src | ||
test | ||
.editorconfig | ||
.gitignore | ||
tsconfig.json | ||
bin/ | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2022 Elias Skogevall | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,29 @@ | ||
# Protoc Tools gRPC Web Plugin | ||
**Protoc gRPC web generator plugin for @accility/protoc-tools ([NPM](https://npmjs.com/package/accility/protoc-tools) | [GitHub](https://github.com/accility/protoc-tools))** | ||
**This [accility/protoc-tools](https://github.com/accility/protoc-tools) plugin uses [protoc-gen-grpc-web](https://github.com/grpc/grpc-web/releases) to generate the gRPC Web files.** The protoc-gen-grpc-web binary can be downloaded and used as-is, however this have some implications, that mainly being: adding the binary to path and installation. This plugin solves both of theese issues. | ||
|
||
This package downloads and utilizes the [gRPC Web](https://github.com/grpc/grpc-web) ([protoc-gen-grpc-web](https://github.com/grpc/grpc-web/releases)) plugin from the [gRPC](https://github.com/grpc) project on post-install. | ||
For a more in-depth documentation, visit https://github.com/grpc/grpc-web. | ||
|
||
[protoc-gen-grpc-web](https://github.com/grpc/grpc-web/releases) is a plugin and can be used with [@accility/protoc-tools](https://github.com/accility/protoc-tools) directly. But protoc-gen-grpc-web is a binary and needs to be installed for respectively operating system, which this plugin does on post-install **and** needs to be executed in PATH, which this plugin adds the binary directory to the process enviroment PATH variable. | ||
|
||
## Usage | ||
``` | ||
npm install --save-dev @accility/protoc-tools protoc-tools-grpc-web-plugin | ||
``` | ||
|
||
```javascript | ||
import * as tools from '@accility/protoc-tools' | ||
import * as gRPCWeb from '../dist/plugin' | ||
|
||
// OR | ||
|
||
const tools = require('@accility/protoc-tools') | ||
const gRPCWeb = require('../dist/plugin') | ||
import * as grpcweb from 'protoc-tools-grpc-web-plugin' | ||
|
||
tools.protoc({ | ||
... | ||
outOptions: [ | ||
tools.generators.js({ | ||
outOptions: 'import_style=commonjs' | ||
}), | ||
gRPCWeb({ | ||
module: 'commonjs', // 'closure' | 'commonjs' | 'commonjs+dts' | 'typescript' | ||
// mode: 'grpcwebtext' | 'grpcweb' | ||
grpcweb({ | ||
// required: 'closure' | 'commonjs' | 'commonjs+dts' | 'typescript' | ||
module: 'commonjs', | ||
|
||
// optional: 'grpcwebtext' | 'grpcweb' | ||
mode: 'grpcwebtext' | ||
}) | ||
] | ||
}) | ||
``` | ||
|
||
### Module | ||
Import style (https://github.com/grpc/grpc-web#import-style) | ||
|
||
- `closure` - the default generated code has Closure `goog.require()` import style. | ||
- `commonjs` - the CommonJS style `require()` is also supported. | ||
- `commonjs+dts` - (experimental) in addition to above, a .d.ts typings file will also be generated for the protobufssages and service stub. | ||
- `typescript` - (experimental) the service stub will be generat | ||
|
||
### Mode | ||
Wire format mode (https://github.com/grpc/grpc-web#wire-format-mode) | ||
|
||
`grpcwebtext`: The default generated code sends the payload in the grpc-web-text format. | ||
- `Content-type: application/grpc-web-text` | ||
- Payload are base64-encoded. | ||
- Both unary and server streaming calls are supported. | ||
|
||
`grpcweb`: A binary protobuf format is also supported. | ||
- `Content-type: application/grpc-web+proto` | ||
- Payload are in the binary protobuf format. | ||
- Only unary calls are supported for now. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { OutputOptions } from '@accility/protoc-tools' | ||
|
||
export interface Options { | ||
/** | ||
* Import style (https://github.com/grpc/grpc-web#import-style) | ||
* | ||
* - `closure` - the default generated code has Closure `goog.require()` import style. | ||
* - `commonjs` - the CommonJS style `require()` is also supported. | ||
* - `commonjs+dts` - (experimental) in addition to above, a .d.ts typings file will also be generated for the protobuf messages and service stub. | ||
* - `typescript` - (experimental) the service stub will be generated in TypeScript. See TypeScript Support below for information on how to generate TypeScript files. | ||
*/ | ||
module: 'closure' | 'commonjs' | 'commonjs+dts' | 'typescript' | ||
|
||
/** | ||
* Wire format mode (https://github.com/grpc/grpc-web#wire-format-mode) | ||
* | ||
* `mode=grpcwebtext`: The default generated code sends the payload in the grpc-web-text format. | ||
* - `Content-type: application/grpc-web-text` | ||
* - Payload are base64-encoded. | ||
* - Both unary and server streaming calls are supported. | ||
* | ||
* `mode=grpcweb`: A binary protobuf format is also supported. | ||
* - `Content-type: application/grpc-web+proto` | ||
* - Payload are in the binary protobuf format. | ||
* - Only unary calls are supported for now. | ||
* | ||
* @default 'grpcwebtext' | ||
*/ | ||
mode?: 'grpcwebtext' | 'grpcweb' | ||
} | ||
|
||
export default function plugin(options: Options): OutputOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const path = require('path') | ||
|
||
function appendPathEnv(path) { | ||
const name = process.platform === 'win32' ? 'Path' : 'PATH' | ||
const sep = process.platform === 'win32' ? ';' : ':' | ||
const paths = process.env[name].split(sep).filter(v => !!v) | ||
|
||
if (!paths.includes(path)) | ||
process.env[name] = paths.concat(path).join(sep) | ||
} | ||
|
||
function plugin(options) { | ||
appendPathEnv(path.join(__dirname, 'bin')) | ||
|
||
return { | ||
name: 'grpc-web', | ||
outOptions: `import_style=${options.module},mode=${options.mode || 'grpcwebtext'}`, | ||
} | ||
} | ||
|
||
module.exports = plugin | ||
module.exports.default = plugin |
Oops, something went wrong.