@@ -6,6 +6,7 @@ DIR="$(dirname "$0")"
66if [ ! -d " $DIR " ]; then
77 DIR=" $PWD "
88fi
9+ DIR=" $( cd " $DIR " && pwd) "
910
1011. ${DIR} /shared.sh
1112
@@ -14,41 +15,60 @@ if ! command -v ignite >/dev/null 2>&1; then
1415 exit 1
1516fi
1617
18+ # Create a temp directory to clone poktroll into
19+ WORK_DIR=$( mktemp -d -p " ${DIR} " )
20+ # Normalize WORK_DIR to absolute path
21+ WORK_DIR=$( cd " $WORK_DIR " && pwd)
22+
23+ if [ -z " $WORK_DIR " ]; then
24+ echo " Could not create temp dir"
25+ exit 1
26+ fi
27+
28+ echo " Working in $WORK_DIR "
29+
30+ cleanup () {
31+ info_log " Cleaning up..."
32+ rm -rf " $WORK_DIR "
33+ info_log " Cleanup done. Poktroll directory was deleted."
34+ }
35+
36+ # Remove the temp directory on exit
37+ trap cleanup EXIT
38+
1739default_branch=" main"
1840branch=${1:- $default_branch }
1941
20- rm -rf poktroll
21- info_log " Poktroll github repository is going to be clone..."
42+ cd ${WORK_DIR}
43+
44+ info_log " Cloning Poktroll from github.com/pokt-network/poktroll..."
2245git clone https://github.com/pokt-network/poktroll.git
23- {
24- info_log " Poktroll github repository is cloned..."
25- cd poktroll
26-
27- if [ " $branch " != " $default_branch " ]; then
28- info_log " Poktroll github repository is going to be checkout to $branch branch..."
29- git checkout $branch
30- fi
31-
32- info_log " TypeScript client files will be generated..."
33- echo " Y" | ignite generate ts-client --yes --use-cache
34-
35- info_log " TypeScript client files were generated. Now copying them to the project..."
36- cd ..
37- rm -rf ${DIR} /../src/client
38- mkdir -p ${DIR} /../src/client
39-
40- # Here we are copying the files from poktroll.application because every directory copied has the types directory with the same files inside.
41- cp -TR poktroll/ts-client/poktroll.application/types ${DIR} /../src/client
42- rm -f ${DIR} /../src/client/route-name.eta
43-
44- info_log " TypeScript client files were copied. Now copying proto files..."
45-
46- rm -rf ${DIR} /../proto/poktroll
47- mkdir -p ${DIR} /../proto/poktroll
48- cp -TR poktroll/proto/poktroll/ ${DIR} /../proto/poktroll
49- git add ${DIR} /../proto/poktroll
50-
51- info_log " Proto files were copied."
52- rm -rf poktroll
53- info_log " Poktroll folder cloned from github was deleted."
54- } || rm -rf poktroll
46+
47+ info_log " Poktroll from github.com/pokt-network/poktroll was cloned."
48+ cd poktroll
49+
50+ if [ " $branch " != " $default_branch " ]; then
51+ info_log " Checking out $branch branch in Poktroll repository..."
52+ git checkout $branch
53+ fi
54+
55+ info_log " Generating TypeScript client files..."
56+ echo " Y" | ignite generate ts-client --yes --use-cache
57+
58+ info_log " TypeScript client files were generated. Now copying them to the project..."
59+ cd ${WORK_DIR}
60+ # Deleting old TypeScript client files.
61+ rm -rf ${DIR} /../src/client/*
62+
63+ # Here we are copying the files from poktroll.application because every directory has the types directory with the same files inside generated by ignite.
64+ cp -TR poktroll/ts-client/poktroll.application/types ${DIR} /../src/client
65+ rm -f ${DIR} /../src/client/route-name.eta
66+
67+ info_log " TypeScript client files were copied. Now copying proto files..."
68+
69+ # Deleting old protobuf source files.
70+ rm -rf ${DIR} /../proto/poktroll/*
71+ cp -TR poktroll/proto/poktroll/ ${DIR} /../proto/poktroll
72+
73+ info_log " Proto files were copied."
74+
0 commit comments