#!/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}"