feat(grpc): add npm package, update Node.js & TypeScript gRPC code and gen scripts

This commit is contained in:
Nex
2020-11-17 00:43:10 +08:00
parent 0845a71aba
commit a6d6428393
4 changed files with 2903 additions and 59 deletions

View File

@@ -3,48 +3,54 @@ setlocal EnableDelayedExpansion
cd /d "%~dp0..\pb"
where /q protoc || echo Missing protoc && exit /b
set gen=..\gen
set pbs=bdware/bdledger/api/*.proto
set exec=protoc
set gen_dir=..\gen
set pb_files=bdware/bdledger/api/*.proto
set emptypb_file=google/protobuf/empty.proto
set cmd=protoc
for %%A in (%*) do (
if "%%A"=="-a" set exec=start /b protoc
if "%%A"=="--async" set exec=start /b protoc
if "%%A"=="-a" set cmd=start /b !cmd!
if "%%A"=="--async" set cmd=start /b !cmd!
if "%%A"=="go" (
set plugin=protoc-gen-go
where /q !plugin! || echo Missing !plugin! && exit /b
set vplugin=protoc-gen-govalidators
where /q !vplugin! || echo Missing !vplugin! && exit /b
set out=%gen%\go
set out=%gen_dir%\go
if not exist !out! mkdir !out!
echo Generating Go code
!exec! --go_out=!out! --go-grpc_out=!out! --govalidators_out=!out! %pbs%
!cmd! ^
--go_out=!out! ^
--go-grpc_out=!out! ^
--govalidators_out=!out! ^
%pb_files%
)
if "%%A"=="gohttp" (
set plugin=protoc-gen-grpc-gateway
where /q !plugin! || echo Missing !plugin! && exit /b
set out=%gen%\go
set out=%gen_dir%\go
if not exist !out! mkdir !out!
echo Generating Go HTTP code
!exec! --grpc-gateway_out=grpc_api_configuration=bdware/bdledger/api/grpc-gateway.yml,logtostderr=true:!out! %pbs%
!cmd! ^
--grpc-gateway_out=grpc_api_configuration=bdware/bdledger/api/grpc-gateway.yml,logtostderr=true:!out! ^
%pb_files%
)
if "%%A"=="nodejs" (
set plugin=grpc_tools_node_protoc_plugin
where /q !plugin! || echo missing !plugin! && exit /b
for /f %%i in ('where !plugin!') do set pluginPath=%%i
set out=%gen%\nodejs
for /f %%i in ('npm bin') do set npmBinPath=%%i
set jsCmd=!npmBinPath!\grpc_tools_node_protoc
if "%%A"=="-a" set jsCmd=start /b !cmd!
if "%%A"=="--async" set jsCmd=start /b !cmd!
set pluginPath=!npmBinPath!\protoc-gen-ts.cmd
set out=%gen_dir%\nodejs
if not exist !out! mkdir !out!
echo Generating Node.js code
!exec! --js_out=import_style=commonjs,binary:!out! --grpc_out=!out! --plugin=protoc-gen-grpc=!pluginPath! %pbs% google/protobuf/empty.proto
)
if "%%A"=="ts" (
set plugin=protoc-gen-ts
where /q !plugin! || echo missing !plugin! && exit /B
for /f %%i in ('where !plugin!') do set pluginPath=%%i
set out=%gen%\nodejs
if not exist !out! mkdir !out!
echo Generating TypeScript definitions
!exec! --ts_out=!out! --plugin=protoc-gen-ts=!pluginPath! %pbs% google/protobuf/empty.proto
echo Generating Node.js code ^& TypeScript definitions
!jsCmd! ^
--plugin=protoc-gen-ts=!pluginPath! ^
--js_out=import_style=commonjs,binary:!out! ^
--grpc_out=grpc_js:!out! ^
--ts_out=grpc_js:!out! ^
%pb_files% %emptypb_file%
@echo off
)
if "%%A"=="docs" (
set plugin=protoc-gen-ts
@@ -52,8 +58,17 @@ for %%A in (%*) do (
set out=..\..\docs
if not exist !out! mkdir !out!
echo Generating documentation
!exec! --doc_out=!out! --doc_opt=html,apis.html %pbs% google/protobuf/empty.proto
start /b protoc --doc_out=!out! --doc_opt=markdown,apis.md %pbs% google/protobuf/empty.proto
start /b protoc --doc_out=!out! --doc_opt=json,apis.json %pbs% google/protobuf/empty.proto
!cmd! ^
--doc_out=!out! ^
--doc_opt=html,apis.html ^
%pb_files% %emptypb_file%
start /b protoc ^
--doc_out=!out! ^
--doc_opt=markdown,apis.md ^
%pb_files% %emptypb_file%
start /b protoc ^
--doc_out=!out! ^
--doc_opt=json,apis.json ^
%pb_files% %emptypb_file%
)
)