@@ -20,21 +20,36 @@ executeCommand() {
2020 echo " $result "
2121}
2222
23- # Check if Node.js and npm are installed
23+ # Check if Node.js is installed
2424if ! command -v node & > /dev/null; then
25- echo -e " ${RED} Ensure you have Node.js installed on your system.${RESET} "
25+ echo -e " ${RED} Node.js is not installed. Please install Node.js to proceed.${RESET} "
26+ exit 1
27+ fi
28+
29+ # Check if npm is installed
30+ if ! command -v npm & > /dev/null; then
31+ echo -e " ${RED} npm is not installed. Please install npm to proceed.${RESET} "
2632 exit 1
2733fi
2834
2935# Check if Wrangler is installed
3036if ! command -v wrangler & > /dev/null; then
3137 echo -e " ${YELLOW} Wrangler is not installed. Installing Wrangler...${RESET} "
3238 executeCommand " npm install -g wrangler &>/dev/null"
39+ if [ $? -ne 0 ]; then
40+ echo -e " ${YELLOW} Retrying Wrangler installation with sudo...${RESET} "
41+ executeCommand " sudo npm install -g wrangler &>/dev/null"
42+ if [ $? -ne 0 ]; then
43+ echo -e " ${RED} Failed to install Wrangler.${RESET} "
44+ exit 1
45+ fi
46+ fi
3347fi
3448
3549# Check if the repository is already cloned
3650REPO_DIR=" gradle-mirror-cloudflare-worker"
3751REPO_URL=" https://github.com/ehsannarmani/gradle-mirror-cloudflare-worker"
52+
3853if [ -d " $REPO_DIR " ]; then
3954 echo -e " ${CYAN} Repository already cloned.${RESET} "
4055else
5065cd " $REPO_DIR " || exit
5166
5267# Check if Wrangler is logged in by running `wrangler whoami`
53- echo -e " ${CYAN} Checking if you are logged in to wrangler ...${RESET} "
68+ echo -e " ${CYAN} Checking if you are logged in to Wrangler ...${RESET} "
5469
5570whoami_output=$( wrangler whoami 2>&1 )
5671
8499 echo -e " ${RED} Error: Unable to extract the worker URL from the deployment output.${RESET} "
85100 exit 1
86101fi
102+
103+ # Cleanup: Delete the repository folder if it was cloned in this session
104+ cd .. || exit
105+ rm -rf " $REPO_DIR "
0 commit comments