78 lines
2.0 KiB
Bash
Executable File
78 lines
2.0 KiB
Bash
Executable File
#! /bin/bash
|
|
|
|
# Get the full path to the dist directory
|
|
APP_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
# The name of your Cloudflare project
|
|
CF_PROJECT="wakale-casa"
|
|
|
|
# Function to check if a command exists
|
|
command_exists() {
|
|
command -v "$1" > /dev/null 2>&1
|
|
}
|
|
|
|
# Check and install NVM if not present
|
|
if [ ! -d "$HOME/.nvm/.git" ]; 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
|
|
fi
|
|
|
|
# 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"
|
|
|
|
if ! command_exists npm; then
|
|
echo "NPM not installed, installing."
|
|
nvm install node
|
|
fi
|
|
|
|
# Use Node.js newest version
|
|
echo "Using version of node.js"
|
|
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
|
|
echo "Install project dependencies"
|
|
npm install
|
|
|
|
echo "Build your project"
|
|
npm run build
|
|
fi
|
|
|
|
# Deploy to Cloudflare Pages using the full path to dist
|
|
echo "Deploying $APP_PATH/www"
|
|
|
|
wrangler pages deploy --project-name "$CF_PROJECT" "$APP_PATH/www"
|
|
|
|
echo "DONE."
|