diff --git a/Makefile b/Makefile index 1d114b81..b9d135f1 100644 --- a/Makefile +++ b/Makefile @@ -90,10 +90,4 @@ clean: rm -rf $(AKASH_DEVCACHE) rm -rf $(AKASH_TS_ROOT)/node_modules rm -rf $(AKASH_TS_ROOT)/dist - -.PHONY: clean-codegen -clean-codegen: $(AKASH_DEVCACHE_BASE)/tmp/ts rm -rf $(AKASH_TS_ROOT)/src/generated - -$(AKASH_DEVCACHE_BASE)/tmp/ts: - script/ts-patches.sh preserve \ No newline at end of file diff --git a/make/codegen.mk b/make/codegen.mk index 35ec76da..234bc851 100644 --- a/make/codegen.mk +++ b/make/codegen.mk @@ -1,7 +1,6 @@ .PHONY: proto-gen ifeq ($(PROTO_LEGACY), true) -proto-gen: modvendor $(PROTOC) $(PROTOC_GEN_GOCOSMOS) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_DOC) $(AKASH_TS_NODE_MODULES) clean-codegen - mkdir -p $(AKASH_TS_ROOT)/src/generated +proto-gen: modvendor $(PROTOC) $(PROTOC_GEN_GOCOSMOS) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_DOC) $(AKASH_TS_NODE_MODULES) ./script/protocgen-legacy.sh else proto-gen: modvendor gogoproto $(BUF) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_GO) diff --git a/script/protocgen-legacy.sh b/script/protocgen-legacy.sh index 17fca453..97144e5a 100755 --- a/script/protocgen-legacy.sh +++ b/script/protocgen-legacy.sh @@ -6,13 +6,18 @@ PATH=$(pwd)/.cache/bin/legacy:$PATH export PATH=$PATH function cleanup { - rm -rf github.com + # put absolute path + rm -rf "${AKASH_ROOT}/github.com" } trap cleanup EXIT ERR script/ts-patches.sh preserve +ts_generated="${AKASH_TS_ROOT}/src/generated" +rm -rf "$ts_generated" +mkdir -p "$ts_generated" + proto_dirs=$(find ./proto/node -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) #shellcheck disable=SC2046 for dir in $proto_dirs; do @@ -103,5 +108,4 @@ cp -rv github.com/akash-network/akash-api/* ./ script/ts-patches.sh restore -cd "$AKASH_TS_ROOT" && npm run format - +(cd "$AKASH_TS_ROOT" && npm run format) diff --git a/script/ts-patches.sh b/script/ts-patches.sh index aee07cb7..84da7b2a 100755 --- a/script/ts-patches.sh +++ b/script/ts-patches.sh @@ -25,7 +25,13 @@ preserve_patches() { done } +function cleanup { + rm -rf "$tmp_dir" +} + restore_patches() { + trap cleanup EXIT ERR + echo "Restoring TypeScript patches..." find "$tmp_dir" -type f -name "*.ts" | while read -r src_file; do original_file_path=${src_file/$tmp_dir\//} @@ -35,7 +41,6 @@ restore_patches() { mv "$generated_dir/$original_file_path" "$generated_dir/$renamed_original_file_path" mv "$tmp_dir/$original_file_path" "$generated_dir/$original_file_path" done - rm -rf "$tmp_dir" } case $1 in