Skip to content

Commit

Permalink
refactor(codegen): keep ts cleanup within protogen script (#169)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <troian.ap@gmail.com>
  • Loading branch information
troian authored May 3, 2024
1 parent 7208ef5 commit 3644a92
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions make/codegen.mk
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 7 additions & 3 deletions script/protocgen-legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
7 changes: 6 additions & 1 deletion script/ts-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\//}
Expand All @@ -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
Expand Down

0 comments on commit 3644a92

Please sign in to comment.