From 45081f759e51f5bb965118540a91da1ef5f29209 Mon Sep 17 00:00:00 2001 From: Nex Date: Sat, 14 Mar 2020 21:48:59 +0800 Subject: [PATCH] Add node.js gen scripts --- README.md | 6 +++++- gen-go.bat => scripts/gen-go.bat | 2 +- gen-go.sh => scripts/gen-go.sh | 4 ++-- scripts/gen-node.js.sh | 10 ++++++++++ scripts/gen-nodejs.bat | 16 ++++++++++++++++ gen-web.bat => scripts/gen-web.bat | 2 +- gen-web.sh => scripts/gen-web.sh | 2 +- 7 files changed, 36 insertions(+), 6 deletions(-) rename gen-go.bat => scripts/gen-go.bat (97%) rename gen-go.sh => scripts/gen-go.sh (92%) create mode 100644 scripts/gen-node.js.sh create mode 100644 scripts/gen-nodejs.bat rename gen-web.bat => scripts/gen-web.bat (98%) rename gen-web.sh => scripts/gen-web.sh (97%) diff --git a/README.md b/README.md index 972bc79..9b32f06 100644 --- a/README.md +++ b/README.md @@ -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}}` diff --git a/gen-go.bat b/scripts/gen-go.bat similarity index 97% rename from gen-go.bat rename to scripts/gen-go.bat index 68e633f..e1d08c5 100644 --- a/gen-go.bat +++ b/scripts/gen-go.bat @@ -1,5 +1,5 @@ @echo off -cd /d "%~dp0" +cd /d "%~dp0.." set dir=.\gen\go set exe=protoc set gen=protoc-gen-go diff --git a/gen-go.sh b/scripts/gen-go.sh similarity index 92% rename from gen-go.sh rename to scripts/gen-go.sh index e619eef..b17a915 100644 --- a/gen-go.sh +++ b/scripts/gen-go.sh @@ -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 diff --git a/scripts/gen-node.js.sh b/scripts/gen-node.js.sh new file mode 100644 index 0000000..035da88 --- /dev/null +++ b/scripts/gen-node.js.sh @@ -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 diff --git a/scripts/gen-nodejs.bat b/scripts/gen-nodejs.bat new file mode 100644 index 0000000..9e331e2 --- /dev/null +++ b/scripts/gen-nodejs.bat @@ -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 diff --git a/gen-web.bat b/scripts/gen-web.bat similarity index 98% rename from gen-web.bat rename to scripts/gen-web.bat index 71f4b85..593d664 100644 --- a/gen-web.bat +++ b/scripts/gen-web.bat @@ -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 diff --git a/gen-web.sh b/scripts/gen-web.sh similarity index 97% rename from gen-web.sh rename to scripts/gen-web.sh index 5fdebba..257ca78 100644 --- a/gen-web.sh +++ b/scripts/gen-web.sh @@ -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