#!/bin/bash # Get the full path to the dist directory APP_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # Function to check if a command exists command_exists() { command -v "$1" >/dev/null 2>&1 } # Check and install NVM if not present if ! command_exists nvm; then echo "NVM not found. Installing NVM..." # Check if curl is installed if ! command_exists curl; then echo "Curl is not installed. Installing curl..." if [[ "$OSTYPE" == "darwin"* ]]; then # macOS brew install curl elif [[ "$OSTYPE" == "linux"* ]]; then # Linux (assuming Ubuntu/Debian) sudo apt-get update sudo apt-get install -y curl else echo "Unsupported OS. Please install curl manually." exit 1 fi fi # Install NVM curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash # Source NVM to make it available in the current script export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" fi # Use Node.js newest version nvm install node nvm use node # Check and install Wrangler if not present if ! command_exists wrangler; then echo "Wrangler not found. Installing Wrangler globally..." npm install -g wrangler fi # Check if logged into Wrangler if ! wrangler whoami &> /dev/null; then echo "Not logged into Wrangler. Please run 'wrangler login' and authenticate." wrangler login fi if [ -f "$APP_PATH/packages.json" ]; then # Install project dependencies npm install # Build your project npm run build fi # Deploy to Cloudflare Pages using the full path to dist wrangler pages deploy "$APP_PATH/www"