feat(dev): 🎮 unified interactive start script
This commit is contained in:
parent
ee8ed3f1f3
commit
8544ca5cfc
3 changed files with 181 additions and 153 deletions
60
run_dev.sh
60
run_dev.sh
|
|
@ -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
|
||||
|
|
@ -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
|
||||
181
start.sh
Executable file
181
start.sh
Executable file
|
|
@ -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
|
||||
Loading…
Reference in a new issue