#!/bin/bash set -e echo "======================================" echo "🔍 Pre-Deployment Checks" echo "======================================" ERRORS=0 # Check 1: Frontend build echo "" echo "1️⃣ Checking frontend build..." cd /root/maternal-app/maternal-web if npm run build > /tmp/frontend-build.log 2>&1; then echo "✅ Frontend build successful" else echo "❌ Frontend build failed" echo "See /tmp/frontend-build.log for details" ERRORS=$((ERRORS + 1)) fi # Check 2: Backend build echo "" echo "2️⃣ Checking backend build..." cd /root/maternal-app/maternal-app/maternal-app-backend if npm run build > /tmp/backend-build.log 2>&1; then echo "✅ Backend build successful" else echo "❌ Backend build failed" echo "See /tmp/backend-build.log for details" tail -20 /tmp/backend-build.log ERRORS=$((ERRORS + 1)) fi # Check 2.5: Admin Panel build echo "" echo "2️⃣.5 Checking admin panel build..." cd /root/maternal-app/parentflow-admin if npm run build > /tmp/admin-build.log 2>&1; then echo "✅ Admin panel build successful" else echo "❌ Admin panel build failed" echo "See /tmp/admin-build.log for details" tail -20 /tmp/admin-build.log ERRORS=$((ERRORS + 1)) fi # Check 3: Uncommitted changes echo "" echo "3️⃣ Checking for uncommitted changes..." cd /root/maternal-app if [ -z "$(git status --porcelain)" ]; then echo "✅ No uncommitted changes" else echo "⚠️ Uncommitted changes detected:" git status --short echo "" echo "You may want to commit these before deploying" fi # Check 4: Current branch echo "" echo "4️⃣ Checking current branch..." BRANCH=$(git branch --show-current) if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then echo "✅ On branch: $BRANCH" else echo "⚠️ On branch: $BRANCH (not main/master)" fi # Check 5: Remote sync echo "" echo "5️⃣ Checking if local is ahead of remote..." git fetch origin --quiet LOCAL=$(git rev-parse @) REMOTE=$(git rev-parse @{u}) if [ "$LOCAL" = "$REMOTE" ]; then echo "✅ Local and remote are in sync" elif [ "$LOCAL" != "$REMOTE" ]; then AHEAD=$(git rev-list --count @{u}..HEAD) if [ "$AHEAD" -gt 0 ]; then echo "⚠️ Local is $AHEAD commit(s) ahead of remote (need to push)" else echo "⚠️ Local is behind remote (need to pull)" fi fi # Check 6: Pending migrations echo "" echo "6️⃣ Checking for pending migrations..." cd /root/maternal-app/maternal-app/maternal-app-backend MIGRATIONS=$(find src/database/migrations -name "*.ts" 2>/dev/null | wc -l) echo "Found $MIGRATIONS migration files" # Check 7: Environment files echo "" echo "7️⃣ Checking environment files..." if [ -f "/root/maternal-app/maternal-web/.env.local" ]; then echo "✅ Frontend .env.local exists" else echo "⚠️ Frontend .env.local not found" fi if [ -f "/root/maternal-app/maternal-app/maternal-app-backend/.env" ]; then echo "✅ Backend .env exists" else echo "⚠️ Backend .env not found" fi if [ -f "/root/maternal-app/parentflow-admin/.env.local" ]; then echo "✅ Admin panel .env.local exists" else echo "⚠️ Admin panel .env.local not found" fi # Summary echo "" echo "======================================" if [ $ERRORS -eq 0 ]; then echo "✅ All critical checks passed! Ready to deploy." echo "" echo "📋 Next steps:" echo " 1. Review any warnings above" echo " 2. git add . (if uncommitted changes)" echo " 3. git commit -m 'your message'" echo " 4. git push origin main" echo " 5. SSH to production server" echo " 6. Run: /var/www/maternal-app/deploy.sh" echo "" else echo "❌ $ERRORS critical check(s) failed!" echo "" echo "Fix the following before deploying:" if [ -f /tmp/frontend-build.log ]; then echo " - Frontend build errors" fi if [ -f /tmp/backend-build.log ]; then echo " - Backend build errors" fi if [ -f /tmp/admin-build.log ]; then echo " - Admin panel build errors" fi echo "" exit 1 fi echo "======================================"