Add node.js gen scripts

This commit is contained in:
Nex 2020-03-14 21:48:59 +08:00
parent cfe8dd42e3
commit 45081f759e
7 changed files with 36 additions and 6 deletions

View File

@ -12,6 +12,10 @@
go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/protoc-gen-go
```
- Node.js
```bash
npm install -g grpc-tools
```
- Web
```bash
git clone https://github.com/grpc/grpc-web
@ -27,4 +31,4 @@
### 编译
- 在本项目打开控制台,或者切换工作路径到本项目
- 执行 `./gen-{{platform}}`
- 执行 `./scripts/gen-{{platform}}`

View File

@ -1,5 +1,5 @@
@echo off
cd /d "%~dp0"
cd /d "%~dp0.."
set dir=.\gen\go
set exe=protoc
set gen=protoc-gen-go

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
cd "${0%/*}"
dir=gen/go
cd "${0%/*}/.."
dir=gen/nodejs
mkdir -p $dir
protoc -I . --go_out=plugins=grpc:$dir bdledger/api/common.proto
protoc -I . --go_out=plugins=grpc:$dir bdledger/api/error_details.proto

10
scripts/gen-node.js.sh Normal file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
cd "${0%/*}/.."
dir=gen/nodejs
plugin=`which grpc_tools_node_protoc_plugin`
mkdir -p $dir
%exe% --js_out=import_style=commonjs,binary:%dir --grpc_out=%dir --plugin=protoc-gen-grpc=$plugin bdledger/api/common.proto
%exe% --js_out=import_style=commonjs,binary:%dir --grpc_out=%dir --plugin=protoc-gen-grpc=$plugin bdledger/api/error_details.proto
%exe% --js_out=import_style=commonjs,binary:%dir --grpc_out=%dir --plugin=protoc-gen-grpc=$plugin bdledger/api/node.proto
%exe% --js_out=import_style=commonjs,binary:%dir --grpc_out=%dir --plugin=protoc-gen-grpc=$plugin bdledger/api/ledger.proto
%exe% --js_out=import_style=commonjs,binary:%dir --grpc_out=%dir --plugin=protoc-gen-grpc=$plugin bdledger/api/query.proto

16
scripts/gen-nodejs.bat Normal file
View File

@ -0,0 +1,16 @@
@echo off
cd /d "%~dp0.."
set dir=.\gen\nodejs
set exe=grpc_tools_node_protoc
for /f %%i in ('where grpc_tools_node_protoc_plugin') do set plugin=%%i
where /q %exe% || echo missing %exe% && exit /B
if not exist %dir% mkdir %dir%
call %exe% --js_out=import_style=commonjs,binary:%dir% --grpc_out=%dir% --plugin=protoc-gen-grpc=%plugin% bdledger/api/common.proto
call %exe% --js_out=import_style=commonjs,binary:%dir% --grpc_out=%dir% --plugin=protoc-gen-grpc=%plugin% bdledger/api/error_details.proto
call %exe% --js_out=import_style=commonjs,binary:%dir% --grpc_out=%dir% --plugin=protoc-gen-grpc=%plugin% bdledger/api/node.proto
call %exe% --js_out=import_style=commonjs,binary:%dir% --grpc_out=%dir% --plugin=protoc-gen-grpc=%plugin% bdledger/api/ledger.proto
call %exe% --js_out=import_style=commonjs,binary:%dir% --grpc_out=%dir% --plugin=protoc-gen-grpc=%plugin% bdledger/api/query.proto
echo all done

View File

@ -1,5 +1,5 @@
@echo off
cd /d "%~dp0"
cd /d "%~dp0.."
set dir=.\gen\web
set exe=protoc
set gen=protoc-protoc-gen-grpc-web

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
cd "${0%/*}"
cd "${0%/*}/.."
dir=gen/web
mkdir -p $dir
protoc -I . --js_out=import_style=commonjs:$dir --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$dir bdledger/api/common.proto