Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ts): implement grpc-js client services (#184) #158

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
ygrishajev marked this conversation as resolved.
Show resolved Hide resolved

$(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
Loading