73 lines
1.9 KiB
Bash
Executable File
73 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Colors for output
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
NC='\033[0m' # No Color
|
||
|
||
echo -e "${YELLOW}🚀 Starting build and test process...${NC}\n"
|
||
|
||
# Kill any running Next.js processes
|
||
echo -e "📌 Cleaning up previous processes..."
|
||
pkill -f "next" || true
|
||
|
||
# Remove build artifacts and dependencies
|
||
echo -e "🧹 Cleaning build artifacts..."
|
||
npx rimraf .next node_modules
|
||
|
||
# Install dependencies
|
||
echo -e "\n📦 Installing dependencies..."
|
||
if npm install; then
|
||
echo -e "${GREEN}✓ Dependencies installed successfully${NC}"
|
||
else
|
||
echo -e "${RED}✗ Failed to install dependencies${NC}"
|
||
exit 1
|
||
fi
|
||
|
||
# Type checking
|
||
echo -e "\n📝 Running type check..."
|
||
if npm run typecheck; then
|
||
echo -e "${GREEN}✓ Type check passed${NC}"
|
||
else
|
||
echo -e "${RED}✗ Type check failed${NC}"
|
||
exit 1
|
||
fi
|
||
|
||
# Build the application
|
||
echo -e "\n🏗️ Building the application..."
|
||
if npm run build; then
|
||
echo -e "${GREEN}✓ Build successful${NC}"
|
||
else
|
||
echo -e "${RED}✗ Build failed${NC}"
|
||
exit 1
|
||
fi
|
||
|
||
# Start with PM2
|
||
echo -e "\n🚀 Starting application with PM2..."
|
||
pm2 delete warme 2>/dev/null || true
|
||
if pm2 start npm --name "warme" -- start; then
|
||
echo -e "${GREEN}✓ Application started successfully${NC}"
|
||
else
|
||
echo -e "${RED}✗ Failed to start application${NC}"
|
||
exit 1
|
||
fi
|
||
|
||
# Show logs
|
||
echo -e "\n📋 Recent application logs:"
|
||
pm2 logs warme --lines 20 --nostream
|
||
|
||
# Health check
|
||
echo -e "\n🏥 Performing health check..."
|
||
sleep 5 # Wait for app to fully start
|
||
if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q "200"; then
|
||
echo -e "${GREEN}✓ Application is responding${NC}"
|
||
else
|
||
echo -e "${RED}✗ Application is not responding${NC}"
|
||
# Show error logs
|
||
echo -e "\n❌ Error logs:"
|
||
pm2 logs warme --err --lines 20 --nostream
|
||
exit 1
|
||
fi
|
||
|
||
echo -e "\n${GREEN}✅ Build and test process completed successfully!${NC}" |