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 May 3, 2024
1 parent 873447f commit dabf310
Show file tree
Hide file tree
Showing 25 changed files with 4,716 additions and 93 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ AKASH_DEVCACHE_NODE_BIN=${AKASH_DEVCACHE_NODE_MODULES}/node_modules/.bin
AKASH_TS_ROOT=${AKASH_ROOT}/ts
AKASH_TS_PACKAGE_FILE=${AKASH_TS_ROOT}/package.json
AKASH_TS_NODE_MODULES=${AKASH_TS_ROOT}/node_modules
AKASH_TS_NODE_BIN=${AKASH_TS_NODE_MODULES}/.bin
AKASH_TS_NODE_BIN=${AKASH_TS_NODE_MODULES}/.bin
AKASH_DEVCACHE_TS_TMP=${AKASH_DEVCACHE_BASE}/tmp/ts
1 change: 1 addition & 0 deletions make/setup-cache.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $(AKASH_DEVCACHE):
mkdir -p $(AKASH_DEVCACHE_VERSIONS)
mkdir -p $(AKASH_DEVCACHE_NODE_MODULES)
mkdir -p $(AKASH_DEVCACHE)/run
mkdir -p $(AKASH_DEVCACHE_TS_TMP)/generated-grpc-js
cache: $(AKASH_DEVCACHE)

$(BUF_VERSION_FILE): $(AKASH_DEVCACHE)
Expand Down
50 changes: 46 additions & 4 deletions script/protocgen-legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ set -eo pipefail
PATH=$(pwd)/.cache/bin/legacy:$PATH
export PATH=$PATH

TMP_GRPC_JS_SERVICES_DIR="${AKASH_DEVCACHE_TS_TMP}/generated-grpc-js"

function cleanup {
rm -rf github.com
rm -rf "$TMP_GRPC_JS_SERVICES_DIR"
}

trap cleanup EXIT
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,45 @@ 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

# merge generated grpc-js services to the main generated directory
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

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

Expand Down
Loading

0 comments on commit dabf310

Please sign in to comment.