46 lines
1.1 KiB
Bash
Executable File
46 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
APP_DIR=/var/www/app
|
|
FRONTEND_DIR="$APP_DIR/apps/frontend"
|
|
BACKEND_DIR="$APP_DIR/apps/backend"
|
|
PUBLIC_DIR="$BACKEND_DIR/public"
|
|
|
|
cd "$FRONTEND_DIR"
|
|
|
|
echo "[FRONTEND BUILD] Installation des dépendances npm..."
|
|
npm install --prefer-offline --no-audit
|
|
|
|
echo "[FRONTEND BUILD] Compilation Vite/React..."
|
|
npm run build
|
|
|
|
if [ ! -d "dist" ]; then
|
|
echo "❌ Erreur: Le dossier 'dist' n'a pas été généré par Vite."
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$PUBLIC_DIR"
|
|
|
|
# Nettoyage sécurisé
|
|
find "$PUBLIC_DIR" -mindepth 1 \
|
|
! -name 'index.php' \
|
|
! -name '.htaccess' \
|
|
! -name 'storage' \
|
|
-delete 2>/dev/null || true
|
|
|
|
echo "[FRONTEND BUILD] Copie vers $PUBLIC_DIR..."
|
|
cp -r dist/* "$PUBLIC_DIR/"
|
|
|
|
if [ -f "$PUBLIC_DIR/index.html" ]; then
|
|
mkdir -p "$BACKEND_DIR/resources/views"
|
|
cp "$PUBLIC_DIR/index.html" "$BACKEND_DIR/resources/views/app.blade.php"
|
|
rm -f "$PUBLIC_DIR/index.html"
|
|
fi
|
|
|
|
if [ ! -L "$PUBLIC_DIR/storage" ] && [ ! -e "$PUBLIC_DIR/storage" ]; then
|
|
ln -sfn "$BACKEND_DIR/storage/app/public" "$PUBLIC_DIR/storage"
|
|
fi
|
|
|
|
echo "[FRONTEND BUILD] Build React terminé et déployé dans $PUBLIC_DIR ✅"
|
|
exit 0
|