-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts): implement grpc-js client services (#184)
Issue: #184
- Loading branch information
1 parent
b7813c9
commit 2a3fc30
Showing
24 changed files
with
4,779 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env bash | ||
|
||
TMP_GRPC_JS_SERVICES_DIR="${AKASH_DEVCACHE_BASE}/ts/generated-grpc-js" | ||
|
||
function run_ts_proto() { | ||
local ts_proto_opt | ||
local inputs=() | ||
local dir | ||
local out | ||
|
||
while (( "$#" )); do | ||
case "$1" in | ||
--opt) | ||
ts_proto_opt=$2 | ||
shift 2 | ||
;; | ||
-I) | ||
inputs+=("$2") | ||
shift 2 | ||
;; | ||
--dir) | ||
dir=$2 | ||
shift 2 | ||
;; | ||
--out) | ||
out=$2 | ||
shift 2 | ||
;; | ||
--) | ||
shift | ||
break | ||
;; | ||
*) | ||
echo "Error: Invalid argument - $1" | ||
return 1 | ||
;; | ||
esac | ||
done | ||
|
||
local I_opts="" | ||
for input in "${inputs[@]}"; do | ||
I_opts+="-I ${input} " | ||
done | ||
|
||
if [ ! -d "$out" ]; then | ||
mkdir -p "$out" | ||
fi | ||
|
||
.cache/bin/protoc \ | ||
${I_opts} \ | ||
-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="${out}" \ | ||
--ts_proto_opt="esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,${ts_proto_opt}" \ | ||
$(find "${dir}" -maxdepth 1 -name '*.proto') | ||
} | ||
|
||
function add_grpc_js_services() { | ||
local ts_grpc_js_services | ||
local file | ||
local dest_path | ||
local index_file_path | ||
local index_file_name | ||
local index_file_path | ||
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" | ||
} |
Oops, something went wrong.