82 lines
2.4 KiB
Bash
Executable File
82 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Define colors
|
|
RED='\033[0;31m'
|
|
YELLOW='\033[1;33m'
|
|
GREEN='\033[0;32m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Required Node.js version
|
|
REQUIRED_NODE_VERSION="v22.15.0"
|
|
|
|
# Check Node.js version
|
|
NODE_VERSION=$(node -v 2>/dev/null)
|
|
if [ "$NODE_VERSION" != "$REQUIRED_NODE_VERSION" ]; then
|
|
echo -e "${YELLOW}Warning:${NC} Node.js version is $NODE_VERSION, but required is $REQUIRED_NODE_VERSION."
|
|
else
|
|
echo -e "${GREEN}Node.js version is correct: $NODE_VERSION${NC}"
|
|
fi
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
REPO_ROOT="$SCRIPT_DIR/.."
|
|
|
|
# Cleanup function to kill backend server on script exit
|
|
cleanup() {
|
|
echo -e "\n${BLUE}Stopping backend server...${NC}"
|
|
if [ -n "$BACKEND_PID" ]; then
|
|
kill $BACKEND_PID 2>/dev/null || true
|
|
echo -e "${GREEN}Backend server stopped.${NC}"
|
|
fi
|
|
exit 0
|
|
}
|
|
|
|
# Register the cleanup function for script termination
|
|
trap cleanup INT TERM EXIT
|
|
|
|
# Source the .env.dev file to get environment variables
|
|
if [ -f "$REPO_ROOT/.env.dev" ]; then
|
|
echo -e "${BLUE}Loading environment variables from .env.dev...${NC}"
|
|
set -a # automatically export all variables
|
|
source "$REPO_ROOT/.env.dev"
|
|
set +a
|
|
echo -e "${GREEN}Development environment variables loaded.${NC}"
|
|
else
|
|
echo -e "${RED}Error:${NC} .env.dev file not found in repository root!"
|
|
exit 1
|
|
fi
|
|
|
|
# Start the backend server
|
|
cd "$REPO_ROOT/backend" || exit 1
|
|
echo -e "${BLUE}Starting backend server...${NC}"
|
|
go run main.go &
|
|
BACKEND_PID=$!
|
|
echo -e "${GREEN}Backend server started with PID $BACKEND_PID.${NC}"
|
|
|
|
# Start the frontend dev server from anywhere in the repo
|
|
cd "$REPO_ROOT/frontend" || exit 1
|
|
|
|
# Install dependencies
|
|
if [ -f package.json ]; then
|
|
echo -e "${BLUE}Installing dependencies...${NC}"
|
|
npm install
|
|
echo -e "${GREEN}Dependencies installed.${NC}"
|
|
else
|
|
echo -e "${RED}Error:${NC} package.json not found in frontend directory!"
|
|
exit 1
|
|
fi
|
|
|
|
# Run dev server
|
|
echo -e "${BLUE}Starting frontend dev server...${NC}"
|
|
npm run dev &
|
|
FRONTEND_PID=$!
|
|
echo -e "${GREEN}Frontend dev server started with PID $FRONTEND_PID.${NC}"
|
|
|
|
# Keep script running until explicitly terminated
|
|
echo -e "${BLUE}Development environment running. Press Ctrl+C to stop all servers.${NC}"
|
|
wait $BACKEND_PID
|
|
echo -e "${YELLOW}Backend server exited. Frontend server may still be running.${NC}"
|
|
wait $FRONTEND_PID
|
|
echo -e "${YELLOW}Frontend server exited. Press Ctrl+C to exit the script.${NC}"
|
|
# Wait indefinitely
|
|
tail -f /dev/null |