bdledger-apis/grpc/scripts/gen.bat

75 lines
2.2 KiB
Batchfile

@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0..\pb"
where /q protoc || echo Missing protoc && exit /b
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 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_dir%\go
if not exist !out! mkdir !out!
echo Generating Go code
!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_dir%\go
if not exist !out! mkdir !out!
echo Generating Go HTTP code
!cmd! ^
--grpc-gateway_out=grpc_api_configuration=bdware/bdledger/api/grpc-gateway.yml,logtostderr=true:!out! ^
%pb_files%
)
if "%%A"=="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 ^& 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
where /q !plugin! || echo missing !plugin! && exit /B
set out=..\..\docs
if not exist !out! mkdir !out!
echo Generating documentation
!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%
)
)