bdledger-apis/grpc/scripts/gen.bat

80 lines
2.4 KiB
Batchfile
Raw Normal View History

2020-04-07 13:28:09 +00:00
@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
2020-04-07 13:28:09 +00:00
for %%A in (%*) do (
if "%%A"=="-a" set cmd=start /b !cmd!
if "%%A"=="--async" set cmd=start /b !cmd!
2020-04-07 13:28:09 +00:00
if "%%A"=="go" (
set plugin=protoc-gen-go
where /q !plugin! || echo Missing !plugin! && exit /b
2020-06-16 07:12:53 +00:00
set vplugin=protoc-gen-govalidators
where /q !vplugin! || echo Missing !vplugin! && exit /b
set out=%gen_dir%\go
2020-04-07 13:28:09 +00:00
if not exist !out! mkdir !out!
echo Generating Go code
!cmd! ^
--go_out=!out! ^
--go-grpc_out=!out! ^
--govalidators_out=!out! ^
%pb_files%
2020-04-07 13:28:09 +00:00
)
2020-06-08 09:24:03 +00:00
if "%%A"=="gohttp" (
set plugin=protoc-gen-grpc-gateway
where /q !plugin! || echo Missing !plugin! && exit /b
set out=%gen_dir%\go
2020-06-08 09:24:03 +00:00
if not exist !out! mkdir !out!
echo Generating Go HTTP code
!cmd! ^
2020-12-05 03:11:36 +00:00
--grpc-gateway_out !out! ^
--grpc-gateway_opt grpc_api_configuration=bdware/bdledger/api/grpc-gateway.yml ^
--grpc-gateway_opt logtostderr=true ^
--openapiv2_out ..\..\docs\openapiv2 ^
2021-02-12 13:10:12 +00:00
--openapiv2_opt grpc_api_configuration=bdware/bdledger/api/grpc-gateway.yml ^
2020-12-05 03:11:36 +00:00
--openapiv2_opt logtostderr=true ^
%pb_files%
2020-06-08 09:24:03 +00:00
)
2020-04-07 13:28:09 +00:00
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
2020-04-07 13:28:09 +00:00
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
2020-04-07 13:28:09 +00:00
)
if "%%A"=="docs" (
2021-07-20 01:36:57 +00:00
set plugin=protoc-gen-doc
2020-04-07 13:28:09 +00:00
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%
2020-04-07 13:28:09 +00:00
)
)