Skip to content

Commit

Permalink
feat(ts): implement grpc-js client services (#158)
Browse files Browse the repository at this point in the history
refs akash-network/support#184

ensure non-conflicting dirs for patch preservation
improve formatting to make sure it works from the root dir
  • Loading branch information
ygrishajev committed May 3, 2024
1 parent 3644a92 commit c0913e0
Show file tree
Hide file tree
Showing 27 changed files with 4,717 additions and 95 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ 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
AKASH_DEVCACHE_TS_TMP_GRPC_JS=${AKASH_DEVCACHE_TS_TMP}/generated-grpc-js
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,3 @@ clean:
rm -rf $(AKASH_DEVCACHE)
rm -rf $(AKASH_TS_ROOT)/node_modules
rm -rf $(AKASH_TS_ROOT)/dist
rm -rf $(AKASH_TS_ROOT)/src/generated
2 changes: 2 additions & 0 deletions make/setup-cache.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ $(AKASH_DEVCACHE):
mkdir -p $(AKASH_DEVCACHE_VERSIONS)
mkdir -p $(AKASH_DEVCACHE_NODE_MODULES)
mkdir -p $(AKASH_DEVCACHE)/run
mkdir -p $(AKASH_DEVCACHE_TS_TMP_GRPC_JS)

cache: $(AKASH_DEVCACHE)

$(BUF_VERSION_FILE): $(AKASH_DEVCACHE)
Expand Down
50 changes: 45 additions & 5 deletions script/protocgen-legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export PATH=$PATH
function cleanup {
# put absolute path
rm -rf "${AKASH_ROOT}/github.com"
rm -rf "$AKASH_DEVCACHE_TS_TMP_GRPC_JS"
}

trap cleanup EXIT ERR
Expand Down Expand Up @@ -39,13 +40,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="$AKASH_DEVCACHE_TS_TMP_GRPC_JS" \
--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 @@ -73,14 +84,43 @@ 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="$AKASH_DEVCACHE_TS_TMP_GRPC_JS" \
--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 "$AKASH_DEVCACHE_TS_TMP_GRPC_JS" -name 'service.ts')

for file in $ts_grpc_js_services; do
dest_path=$(dirname "${file/$AKASH_DEVCACHE_TS_TMP_GRPC_JS/$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
Expand Down Expand Up @@ -108,4 +148,4 @@ cp -rv github.com/akash-network/akash-api/* ./

script/ts-patches.sh restore

(cd "$AKASH_TS_ROOT" && npm run format)
npm run format --prefix "$AKASH_TS_ROOT"
2 changes: 1 addition & 1 deletion script/ts-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -eo pipefail

generated_dir="$AKASH_TS_ROOT/src/generated"
tmp_dir="$AKASH_DEVCACHE_BASE/tmp/ts"
tmp_dir="$AKASH_DEVCACHE_TS_TMP/patches"

if [ ! -d "$generated_dir" ]; then
echo "Directory $generated_dir does not exist. Skipping..."
Expand Down
Loading

0 comments on commit c0913e0

Please sign in to comment.