React + Vite sudoku app with 5 difficulty levels, dark mode, celebration effects, localStorage save, and deploy script. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
72 lines
1.9 KiB
Bash
Executable File
72 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# === Configuració ===
|
|
REMOTE_USER="root"
|
|
REMOTE_HOST="ontanem.net"
|
|
REMOTE_DIR="/var/www/simple-sudoku"
|
|
SSH_TARGET="${REMOTE_USER}@${REMOTE_HOST}"
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
info() { echo -e "${GREEN}[✓]${NC} $1"; }
|
|
warn() { echo -e "${YELLOW}[!]${NC} $1"; }
|
|
error() { echo -e "${RED}[✗]${NC} $1"; exit 1; }
|
|
|
|
# === Comprovacions prèvies ===
|
|
echo ""
|
|
echo "🚀 Deploy Sudoku → ${SSH_TARGET}:${REMOTE_DIR}"
|
|
echo "─────────────────────────────────────────────"
|
|
|
|
# Verificar que estem al directori del projecte
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
if [ ! -f "package.json" ]; then
|
|
error "No s'ha trobat package.json. Executa l'script des del directori del projecte."
|
|
fi
|
|
|
|
# Verificar connexió SSH
|
|
info "Comprovant connexió SSH..."
|
|
if ! ssh -o ConnectTimeout=5 -o BatchMode=yes "$SSH_TARGET" "echo ok" &>/dev/null; then
|
|
error "No s'ha pogut connectar a ${SSH_TARGET}. Verifica la configuració SSH."
|
|
fi
|
|
|
|
# === Build ===
|
|
info "Instal·lant dependències..."
|
|
npm ci --silent
|
|
|
|
info "Generant build de producció..."
|
|
npx vite build --emptyOutDir
|
|
|
|
if [ ! -d "dist" ]; then
|
|
error "El build ha fallat: no s'ha creat el directori dist/"
|
|
fi
|
|
|
|
# === Deploy ===
|
|
info "Creant directori remot si no existeix..."
|
|
ssh "$SSH_TARGET" "mkdir -p ${REMOTE_DIR}"
|
|
|
|
info "Pujant fitxers amb rsync..."
|
|
rsync -azP --delete \
|
|
dist/ \
|
|
"${SSH_TARGET}:${REMOTE_DIR}/"
|
|
|
|
# === Verificació ===
|
|
info "Verificant fitxers al servidor..."
|
|
REMOTE_INDEX=$(ssh "$SSH_TARGET" "test -f ${REMOTE_DIR}/index.html && echo 'ok' || echo 'fail'")
|
|
|
|
if [ "$REMOTE_INDEX" = "ok" ]; then
|
|
echo ""
|
|
info "Deploy completat correctament! ✨"
|
|
echo ""
|
|
echo " Fitxers desplegats a: ${SSH_TARGET}:${REMOTE_DIR}/"
|
|
echo ""
|
|
else
|
|
error "Alguna cosa ha anat malament: index.html no trobat al servidor."
|
|
fi
|