Restructure project

This commit is contained in:
Nex 2020-04-07 21:28:09 +08:00
parent af67a473c9
commit 935d130a98
16 changed files with 114 additions and 84 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
/gen/ /grpc/gen/
# Created by https://www.gitignore.io/api/windows,osx,linux,jetbrains,visualstudiocode # Created by https://www.gitignore.io/api/windows,osx,linux,jetbrains,visualstudiocode
# Edit at https://www.gitignore.io/?templates=windows,osx,linux,jetbrains,visualstudiocode # Edit at https://www.gitignore.io/?templates=windows,osx,linux,jetbrains,visualstudiocode

View File

@ -1,48 +1,5 @@
## BDLedger gRPC API ## BDLedger APIs
### Generating gRPC code in languages This repository contains the original interface definitions of BDLedger APIs that currently support gRPC protocols. Reading the original interface definitions can provide a better understanding of BDLedger APIs and help you to utilize them more efficiently. You can also use these definitions with open source tools to generate client libraries, documentation, and other artifacts.
#### Installling tools - [gRPC APIs](grpc/README.md)
Download the [Protocol Buffers compiler](https://github.com/protocolbuffers/protobuf/releases) (protoc-3.11.4-*) for your platform and add `protoc` to `PATH` environment variable
For generating Go code:
```bash
GIT_TAG="v1.4.0-rc.4"
go get -d -u github.com/golang/protobuf/protoc-gen-go
git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
go install github.com/golang/protobuf/protoc-gen-go
```
(Update to google.golang.org/protobuf when https://github.com/grpc/grpc-go/pull/3435 resolves)
For generating Java code: From `bdledger-sdk-java` run `gradle generateProto`
For generating Node.js code:
```bash
npm install -g grpc-tools
```
For generating TypeScript definitions, also run:
```bash
npm install -g protoc-gen-ts
```
For frontend JavaScript:
```bash
git clone https://github.com/grpc/grpc-web
cd grpc-web
sudo make install-plugin
```
References:
- [Go Quick Start](https://grpc.io/docs/quickstart/go.html#prerequisites)
- [gRPC Go FAQ](https://github.com/grpc/grpc-go#faq)
**TODO: Look into [protobuf.js](https://github.com/protobufjs/protobuf.js) for Nodes.js and frontend**
**TODO: Look into [Kroto+](https://github.com/marcoferrer/kroto-plus) for Kotlin**
#### Generating code
Run
```bash
./scripts/gen [go] [nodejs] [ts]
```

63
grpc/README.md Normal file
View File

@ -0,0 +1,63 @@
## BDLedger API
### Documentation
See [API documentation](..\docs\apis.md)
### Development
#### Generating gRPC code in languages
##### Installling tools
Download the [Protocol Buffers compiler](https://github.com/protocolbuffers/protobuf/releases) (protoc-3.11.4-*) for your platform and add `protoc` to `PATH` environment variable
For generating Go code:
```bash
GIT_TAG="v1.4.0-rc.4"
go get -d -u github.com/golang/protobuf/protoc-gen-go
git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
go install github.com/golang/protobuf/protoc-gen-go
```
(Update to google.golang.org/protobuf when https://github.com/grpc/grpc-go/pull/3435 resolves)
For generating Java code: From `bdledger-sdk-java` run `gradle generateProto`
For generating Node.js code, install Node.js then run:
```bash
npm install -g grpc-tools
```
For generating TypeScript definitions, also run:
```bash
npm install -g protoc-gen-ts
```
For frontend JavaScript:
```bash
git clone https://github.com/grpc/grpc-web
cd grpc-web
sudo make install-plugin
```
References:
- [Go Quick Start](https://grpc.io/docs/quickstart/go.html#prerequisites)
- [gRPC Go FAQ](https://github.com/grpc/grpc-go#faq)
**TODO: Look into [protobuf.js](https://github.com/protobufjs/protobuf.js) for Nodes.js and frontend**
**TODO: Look into [Kroto+](https://github.com/marcoferrer/kroto-plus) for Kotlin**
##### Generating code
Run:
```bash
./scripts/gen [go] [nodejs] [ts]
```
#### Generateing documentation
Install Go then run:
```bash
go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
./scripts/gen docs
```

47
grpc/scripts/gen.bat Normal file
View File

@ -0,0 +1,47 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0..\pb"
where /q protoc || echo Missing protoc && exit /b
set gen=..\gen
set pbs=bdware/bdledger/api/*.proto
REM set protos=%pkg%/common.proto %pkg%/error_details.proto %pkg%/node.proto %pkg%/ledger.proto %pkg%/query.proto %pkg%/contract.proto
for %%A in (%*) do (
if "%%A"=="go" (
set plugin=protoc-gen-go
where /q !plugin! || echo Missing !plugin! && exit /b
set out=%gen%\go
if not exist !out! mkdir !out!
echo Generating Go code
start /b protoc --go_out=plugins=grpc:!out! %pbs%
)
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
if not exist !out! mkdir !out!
echo Generating Node.js code
start /b protoc --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
start /b protoc --ts_out=!out! --plugin=protoc-gen-ts=!pluginPath! %pbs% google/protobuf/empty.proto
)
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
start /b protoc --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
)
)

View File

@ -1,37 +0,0 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
where /q protoc || echo Missing protoc && exit /b
set gen=.\gen
set pkg=bdware/bdledger/api
set protos=%pkg%/common.proto %pkg%/error_details.proto %pkg%/node.proto %pkg%/ledger.proto %pkg%/query.proto %pkg%/contract.proto
for %%A in (%*) do (
if "%%A"=="go" (
set plugin=protoc-gen-go
where /q !plugin! || echo Missing !plugin! && exit /b
set out=%gen%\go
if not exist !out! mkdir !out!
echo Generating Go code
start /b protoc --go_out=plugins=grpc:!out! %protos%
)
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
if not exist !out! mkdir !out!
echo Generating Node.js code
start /b protoc --js_out=import_style=commonjs,binary:!nout! --grpc_out=!nout! --plugin=protoc-gen-grpc=!pluginPath! %protos%
)
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
start /b protoc --ts_out=!out! --plugin=protoc-gen-ts=!pluginPath! %protos%
)
)