diff --git a/run_dev.sh b/run_dev.sh deleted file mode 100755 index 15819d7..0000000 --- a/run_dev.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -# Function to kill background processes on exit -cleanup() { - echo "Stopping services..." - kill $(jobs -p) 2>/dev/null - exit -} - -trap cleanup SIGINT SIGTERM - -echo "๐Ÿš€ Starting GoHorseJobs Development Environment..." - -# Update Backend -echo "๐Ÿ”น Checking Backend Dependencies..." -cd backend && go mod tidy -# Generate Swagger Docs -# Generate Swagger Docs -if ! command -v swag &> /dev/null; then - if [ -f "$HOME/go/bin/swag" ]; then - export PATH=$PATH:$HOME/go/bin - else - echo "โš ๏ธ 'swag' command not found. Installing..." - go install github.com/swaggo/swag/cmd/swag@latest - export PATH=$PATH:$HOME/go/bin - fi -fi - -echo "๐Ÿ”น Generating Swagger Docs..." -swag init -g cmd/api/main.go --parseDependency --parseInternal -cd .. - -# Check Frontend Dependencies -echo "๐Ÿ”น Checking Frontend Dependencies..." -if [ ! -d "frontend/node_modules" ]; then - echo "โš ๏ธ node_modules not found. Running npm install..." - cd frontend && npm install && cd .. -fi - -# Start Backend -echo "๐Ÿ”น Starting Backend (Go) on port 8521..." -(cd backend && go run cmd/api/main.go) & -BACKEND_PID=$! - -# Wait a moment for backend to initialize -sleep 2 - -# Start Frontend -echo "๐Ÿ”น Starting Frontend (Next.js) on port 8963..." -(cd frontend && npm run dev -- -p 8963) & -FRONTEND_PID=$! - -echo "" -echo "๐Ÿ“ก Services running:" -echo " - Backend: http://localhost:8521" -echo " - Frontend: http://localhost:8963" -echo "" - -# Wait for both processes -wait $BACKEND_PID $FRONTEND_PID diff --git a/run_dev_seed.sh b/run_dev_seed.sh deleted file mode 100755 index 527d129..0000000 --- a/run_dev_seed.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash - -# Function to kill background processes on exit -cleanup() { - echo "Stopping services..." - kill $(jobs -p) 2>/dev/null - exit -} - -trap cleanup SIGINT SIGTERM - -echo "๐ŸŒฑ Starting GoHorseJobs Development with Seeding..." - -# ---------------------------------------- -# 1. Update Backend & Docs -# ---------------------------------------- -echo "๐Ÿ”น Checking Backend Dependencies..." -cd backend && go mod tidy -echo "๐Ÿ”น Generating Swagger Docs..." -if command -v swag &> /dev/null; then - swag init -g cmd/api/main.go --parseDependency --parseInternal -fi -cd .. - -# ---------------------------------------- -# 2. Reset Database (Clean Slate) -# ---------------------------------------- -echo "๐Ÿ”น Checking Seeder Dependencies..." -cd seeder-api -if [ ! -d "node_modules" ]; then - npm install -fi - -echo "๐Ÿ”น Resetting Database (Dropping Tables)..." -# This needs DB to be up. DB is assumed up (Postgres service). -npm run seed:reset -if [ $? -ne 0 ]; then - echo "โŒ Database reset failed! Check DB connection." - cleanup -fi -cd .. - -# ---------------------------------------- -# 3. Start Backend (Run Migrations) -# ---------------------------------------- -echo "๐Ÿ”น Starting Backend (Go)..." -(cd backend && go run cmd/api/main.go) & -BACKEND_PID=$! - -echo "โณ Waiting for Backend to be ready (and migrations to finish)..." -# Poll health endpoint -MAX_RETRIES=30 -COUNT=0 -URL="http://localhost:8080/health" - -while ! curl -s $URL > /dev/null; do - echo " ... waiting for backend ($COUNT/$MAX_RETRIES)" - sleep 1 - COUNT=$((COUNT+1)) - if [ $COUNT -ge $MAX_RETRIES ]; then - echo "โŒ Backend failed to start in time." - cleanup - fi -done - -echo "โœ… Backend is UP and Migrations Applied!" - -# ---------------------------------------- -# 4. Seed Data (Populate Tables) -# ---------------------------------------- -echo "๐Ÿ”น Seeding Database..." -cd seeder-api -npm run seed -if [ $? -ne 0 ]; then - echo "โŒ Seeding failed!" - cleanup -fi -cd .. - -# ---------------------------------------- -# 4. Start Frontend -# ---------------------------------------- -echo "๐Ÿ”น Checking Frontend Dependencies..." -if [ ! -d "frontend/node_modules" ]; then - cd frontend && npm install && cd .. -fi - -echo "๐Ÿ”น Starting Frontend (Next.js)..." -(cd frontend && npm run dev) & -FRONTEND_PID=$! - -# Wait for both processes -wait $BACKEND_PID $FRONTEND_PID diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..30f9d40 --- /dev/null +++ b/start.sh @@ -0,0 +1,181 @@ +#!/bin/bash + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +# Function to kill background processes on exit +cleanup() { + echo -e "\n${YELLOW}๐Ÿ›‘ Stopping services...${NC}" + kill $(jobs -p) 2>/dev/null + exit +} + +trap cleanup SIGINT SIGTERM + +# Header +clear +echo -e "${CYAN}" +echo "โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—" +echo "โ•‘ ๐Ÿด GoHorse Jobs - Dev Server โ•‘" +echo "โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•" +echo -e "${NC}" + +# Interactive menu +echo -e "${GREEN}Select an option:${NC}\n" +echo -e " ${YELLOW}1)${NC} ๐Ÿš€ Start (Frontend + Backend)" +echo -e " ${YELLOW}2)${NC} ๐ŸŒฑ Start with Seed (Reset DB + Seed + Start)" +echo -e " ${YELLOW}3)${NC} ๐Ÿ“ฆ Start All (Frontend + Backend + Backoffice)" +echo -e " ${YELLOW}4)${NC} ๐Ÿงช Run Tests (Backend E2E)" +echo -e " ${YELLOW}5)${NC} ๐ŸŒฟ Seed Only (No restart)" +echo -e " ${YELLOW}0)${NC} โŒ Exit" +echo "" +read -p "Enter option [1-5, 0]: " choice + +case $choice in + 1) + echo -e "\n${GREEN}๐Ÿš€ Starting Development Environment...${NC}\n" + + # Backend + echo -e "${BLUE}๐Ÿ”น Checking Backend...${NC}" + cd backend && go mod tidy + if command -v swag &> /dev/null; then + echo -e "${BLUE}๐Ÿ”น Generating Swagger Docs...${NC}" + swag init -g cmd/api/main.go --parseDependency --parseInternal 2>/dev/null + fi + cd .. + + # Frontend deps + if [ ! -d "frontend/node_modules" ]; then + echo -e "${BLUE}๐Ÿ”น Installing Frontend Dependencies...${NC}" + cd frontend && npm install && cd .. + fi + + # Start services + echo -e "${BLUE}๐Ÿ”น Starting Backend on port 8521...${NC}" + (cd backend && go run cmd/api/main.go) & + BACKEND_PID=$! + sleep 2 + + echo -e "${BLUE}๐Ÿ”น Starting Frontend on port 8963...${NC}" + (cd frontend && npm run dev -- -p 8963) & + FRONTEND_PID=$! + + echo -e "\n${GREEN}โœ… Services running:${NC}" + echo -e " ${CYAN}Backend:${NC} http://localhost:8521" + echo -e " ${CYAN}Frontend:${NC} http://localhost:8963" + echo -e " ${CYAN}Swagger:${NC} http://localhost:8521/swagger/index.html" + echo "" + + wait $BACKEND_PID $FRONTEND_PID + ;; + + 2) + echo -e "\n${GREEN}๐ŸŒฑ Starting with Database Reset & Seed...${NC}\n" + + # Backend prep + echo -e "${BLUE}๐Ÿ”น Checking Backend...${NC}" + cd backend && go mod tidy + if command -v swag &> /dev/null; then + swag init -g cmd/api/main.go --parseDependency --parseInternal 2>/dev/null + fi + cd .. + + # Seeder deps + cd seeder-api + if [ ! -d "node_modules" ]; then + echo -e "${BLUE}๐Ÿ”น Installing Seeder Dependencies...${NC}" + npm install + fi + + echo -e "${YELLOW}๐Ÿ”น Resetting Database...${NC}" + npm run seed:reset + cd .. + + # Start backend + echo -e "${BLUE}๐Ÿ”น Starting Backend...${NC}" + (cd backend && go run cmd/api/main.go) & + BACKEND_PID=$! + + echo -e "${YELLOW}โณ Waiting for Backend...${NC}" + sleep 5 + + # Seed + echo -e "${BLUE}๐Ÿ”น Seeding Database (30 companies, 990 jobs)...${NC}" + cd seeder-api && npm run seed && cd .. + + # Frontend + if [ ! -d "frontend/node_modules" ]; then + cd frontend && npm install && cd .. + fi + + echo -e "${BLUE}๐Ÿ”น Starting Frontend...${NC}" + (cd frontend && npm run dev -- -p 8963) & + FRONTEND_PID=$! + + echo -e "\n${GREEN}โœ… Services running with fresh data!${NC}" + echo -e " ${CYAN}Backend:${NC} http://localhost:8521" + echo -e " ${CYAN}Frontend:${NC} http://localhost:8963" + echo "" + + wait $BACKEND_PID $FRONTEND_PID + ;; + + 3) + echo -e "\n${GREEN}๐Ÿ“ฆ Starting All Services (Including Backoffice)...${NC}\n" + + # Backend + cd backend && go mod tidy && cd .. + + # Dependencies + [ ! -d "frontend/node_modules" ] && (cd frontend && npm install && cd ..) + [ ! -d "backoffice/node_modules" ] && (cd backoffice && npm install && cd ..) + + echo -e "${BLUE}๐Ÿ”น Starting Backend on port 8521...${NC}" + (cd backend && go run cmd/api/main.go) & + sleep 2 + + echo -e "${BLUE}๐Ÿ”น Starting Frontend on port 8963...${NC}" + (cd frontend && npm run dev -- -p 8963) & + + echo -e "${BLUE}๐Ÿ”น Starting Backoffice on port 3001...${NC}" + (cd backoffice && npm run start:dev) & + + echo -e "\n${GREEN}โœ… All services running:${NC}" + echo -e " ${CYAN}Backend:${NC} http://localhost:8521" + echo -e " ${CYAN}Frontend:${NC} http://localhost:8963" + echo -e " ${CYAN}Backoffice:${NC} http://localhost:3001" + echo -e " ${CYAN}Swagger:${NC} http://localhost:3001/api/docs" + echo "" + + wait + ;; + + 4) + echo -e "\n${GREEN}๐Ÿงช Running Backend E2E Tests...${NC}\n" + cd backend && go test -tags=e2e -v ./tests/e2e/... 2>&1 + echo -e "\n${GREEN}โœ… Tests completed!${NC}" + ;; + + 5) + echo -e "\n${GREEN}๐ŸŒฟ Seeding Database Only...${NC}\n" + cd seeder-api + [ ! -d "node_modules" ] && npm install + npm run seed + echo -e "\n${GREEN}โœ… Seeding completed!${NC}" + ;; + + 0) + echo -e "${YELLOW}Bye! ๐Ÿ‘‹${NC}" + exit 0 + ;; + + *) + echo -e "${RED}Invalid option. Exiting.${NC}" + exit 1 + ;; +esac