Skip to content

Commit

Permalink
feat(ts): implement grpc-js client services (#184)
Browse files Browse the repository at this point in the history
Issue: #184
  • Loading branch information
ygrishajev committed Apr 30, 2024
1 parent b7813c9 commit b54ba45
Show file tree
Hide file tree
Showing 24 changed files with 4,732 additions and 92 deletions.
34 changes: 30 additions & 4 deletions script/protocgen-legacy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source ./script/ts-proto.sh

set -eo pipefail

PATH=$(pwd)/.cache/bin/legacy:$PATH
Expand All @@ -10,6 +12,7 @@ function cleanup {
}

trap cleanup EXIT
prepare_grpc_js

proto_dirs=$(find ./proto/node -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
#shellcheck disable=SC2046
Expand All @@ -32,13 +35,23 @@ for dir in $proto_dirs; do
$(find "${dir}" -maxdepth 1 -name '*.proto')

.cache/bin/protoc \
-I "proto/node" \
-I ".cache/include/google/protobuf" \
-I "proto/node" \
-I "vendor/github.com/cosmos/cosmos-sdk/proto" \
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated" \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true \
--ts_proto_opt="esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true" \
$(find "${dir}" -maxdepth 1 -name '*.proto')

.cache/bin/protoc \
-I ".cache/include/google/protobuf" \
-I "proto/node" \
-I "vendor/github.com/cosmos/cosmos-sdk/proto" \
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="$TMP_GRPC_JS_SERVICES_DIR" \
--ts_proto_opt="esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputServices=grpc-js" \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done

Expand Down Expand Up @@ -66,16 +79,29 @@ for dir in $proto_dirs; do

.cache/bin/protoc \
-I "proto/provider" \
-I "proto/node" \
-I ".cache/include" \
-I "proto/node" \
-I "vendor/github.com/cosmos/cosmos-sdk/proto" \
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated" \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true \
--ts_proto_opt="esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true" \
$(find "${dir}" -maxdepth 1 -name '*.proto')

.cache/bin/protoc \
-I "proto/provider" \
-I ".cache/include" \
-I "proto/node" \
-I "vendor/github.com/cosmos/cosmos-sdk/proto" \
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="$TMP_GRPC_JS_SERVICES_DIR" \
--ts_proto_opt="esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputServices=grpc-js" \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done

add_grpc_js_services

# move proto files to the right places
cp -rv github.com/akash-network/akash-api/* ./

Expand Down
35 changes: 35 additions & 0 deletions script/ts-proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

TMP_GRPC_JS_SERVICES_DIR="${AKASH_DEVCACHE_BASE}/ts/generated-grpc-js"

function prepare_grpc_js() {
mkdir -p "$TMP_GRPC_JS_SERVICES_DIR"
}

function add_grpc_js_services() {
local ts_grpc_js_services
local file
local dest_path
local index_file_path
local index_file_name
local export_statement

ts_grpc_js_services=$(find "$TMP_GRPC_JS_SERVICES_DIR" -name 'service.ts')

for file in $ts_grpc_js_services; do
dest_path=$(dirname "${file/$TMP_GRPC_JS_SERVICES_DIR/$AKASH_TS_ROOT\/src\/generated}")
dest_file="${dest_path}/service.grpc-js.ts"

mv "$file" "$dest_file"

path_from_gen_dir=${dest_file#"${AKASH_TS_ROOT}/src/generated/"}
index_file_name_base=${path_from_gen_dir%/service.grpc-js.ts}
index_file_name="index.${index_file_name_base//\//.}.grpc-js.ts"
index_file_path="${AKASH_TS_ROOT}/src/generated/$index_file_name"
export_statement="export * from \"./${path_from_gen_dir%.ts}\";"

echo "$export_statement" > "$index_file_path"
done

rm -rf "$TMP_GRPC_JS_SERVICES_DIR"
}
Loading

0 comments on commit b54ba45

Please sign in to comment.