254 lines
5.9 KiB
Bash
Executable File
254 lines
5.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Daily Journal Prompt Generator - Web Application Runner
|
|
# This script helps you run the web application with various options
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
print_header() {
|
|
echo -e "${BLUE}"
|
|
echo "=========================================="
|
|
echo "Daily Journal Prompt Generator - Web App"
|
|
echo "=========================================="
|
|
echo -e "${NC}"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}✓ $1${NC}"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}⚠ $1${NC}"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}✗ $1${NC}"
|
|
}
|
|
|
|
check_dependencies() {
|
|
print_header
|
|
echo "Checking dependencies..."
|
|
|
|
# Check Docker
|
|
if command -v docker &> /dev/null; then
|
|
print_success "Docker is installed"
|
|
else
|
|
print_warning "Docker is not installed. Docker is recommended for easiest setup."
|
|
fi
|
|
|
|
# Check Docker Compose
|
|
if command -v docker-compose &> /dev/null || docker compose version &> /dev/null; then
|
|
print_success "Docker Compose is available"
|
|
else
|
|
print_warning "Docker Compose is not available"
|
|
fi
|
|
|
|
# Check Python
|
|
if command -v python3 &> /dev/null; then
|
|
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
|
|
print_success "Python $PYTHON_VERSION is installed"
|
|
else
|
|
print_error "Python 3 is not installed"
|
|
exit 1
|
|
fi
|
|
|
|
# Check Node.js
|
|
if command -v node &> /dev/null; then
|
|
NODE_VERSION=$(node --version)
|
|
print_success "Node.js $NODE_VERSION is installed"
|
|
else
|
|
print_warning "Node.js is not installed (needed for frontend development)"
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
setup_environment() {
|
|
echo "Setting up environment..."
|
|
|
|
if [ ! -f ".env" ]; then
|
|
if [ -f ".env.example" ]; then
|
|
cp .env.example .env
|
|
print_success "Created .env file from template"
|
|
print_warning "Please edit .env file and add your API keys"
|
|
else
|
|
print_error ".env.example not found"
|
|
exit 1
|
|
fi
|
|
else
|
|
print_success ".env file already exists"
|
|
fi
|
|
|
|
# Check data directory
|
|
if [ ! -d "data" ]; then
|
|
mkdir -p data
|
|
print_success "Created data directory"
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
run_docker() {
|
|
print_header
|
|
echo "Starting with Docker Compose..."
|
|
echo ""
|
|
|
|
if command -v docker-compose &> /dev/null; then
|
|
docker-compose up --build
|
|
elif docker compose version &> /dev/null; then
|
|
docker compose up --build
|
|
else
|
|
print_error "Docker Compose is not available"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
run_backend() {
|
|
print_header
|
|
echo "Starting Backend API..."
|
|
echo ""
|
|
|
|
cd backend
|
|
|
|
# Check virtual environment
|
|
if [ ! -d "venv" ]; then
|
|
print_warning "Creating Python virtual environment..."
|
|
python3 -m venv venv
|
|
fi
|
|
|
|
# Activate virtual environment
|
|
if [ -f "venv/bin/activate" ]; then
|
|
source venv/bin/activate
|
|
elif [ -f "venv/Scripts/activate" ]; then
|
|
source venv/Scripts/activate
|
|
fi
|
|
|
|
# Install dependencies
|
|
if [ ! -f "venv/bin/uvicorn" ]; then
|
|
print_warning "Installing Python dependencies..."
|
|
pip install -r requirements.txt
|
|
fi
|
|
|
|
# Run backend
|
|
print_success "Starting FastAPI backend on http://localhost:8000"
|
|
echo "API Documentation: http://localhost:8000/docs"
|
|
echo ""
|
|
uvicorn main:app --reload --host 0.0.0.0 --port 8000
|
|
|
|
cd ..
|
|
}
|
|
|
|
run_frontend() {
|
|
print_header
|
|
echo "Starting Frontend..."
|
|
echo ""
|
|
|
|
cd frontend
|
|
|
|
# Check node_modules
|
|
if [ ! -d "node_modules" ]; then
|
|
print_warning "Installing Node.js dependencies..."
|
|
npm install
|
|
fi
|
|
|
|
# Run frontend
|
|
print_success "Starting Astro frontend on http://localhost:3000"
|
|
echo ""
|
|
npm run dev
|
|
|
|
cd ..
|
|
}
|
|
|
|
run_tests() {
|
|
print_header
|
|
echo "Running Backend Tests..."
|
|
echo ""
|
|
|
|
if [ -f "test_backend.py" ]; then
|
|
python test_backend.py
|
|
else
|
|
print_error "test_backend.py not found"
|
|
fi
|
|
}
|
|
|
|
show_help() {
|
|
print_header
|
|
echo "Usage: $0 [OPTION]"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " docker Run with Docker Compose (recommended)"
|
|
echo " backend Run only the backend API"
|
|
echo " frontend Run only the frontend"
|
|
echo " all Run both backend and frontend separately"
|
|
echo " test Run backend tests"
|
|
echo " setup Check dependencies and setup environment"
|
|
echo " help Show this help message"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 docker # Run full stack with Docker"
|
|
echo " $0 all # Run backend and frontend separately"
|
|
echo " $0 setup # Setup environment and check dependencies"
|
|
echo ""
|
|
}
|
|
|
|
case "${1:-help}" in
|
|
docker)
|
|
check_dependencies
|
|
setup_environment
|
|
run_docker
|
|
;;
|
|
backend)
|
|
check_dependencies
|
|
setup_environment
|
|
run_backend
|
|
;;
|
|
frontend)
|
|
check_dependencies
|
|
setup_environment
|
|
run_frontend
|
|
;;
|
|
all)
|
|
check_dependencies
|
|
setup_environment
|
|
print_header
|
|
echo "Starting both backend and frontend..."
|
|
echo "Backend: http://localhost:8000"
|
|
echo "Frontend: http://localhost:3000"
|
|
echo ""
|
|
echo "Open two terminal windows and run:"
|
|
echo "1. $0 backend"
|
|
echo "2. $0 frontend"
|
|
echo ""
|
|
;;
|
|
test)
|
|
check_dependencies
|
|
run_tests
|
|
;;
|
|
setup)
|
|
check_dependencies
|
|
setup_environment
|
|
print_success "Setup complete!"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Edit .env file and add your API keys"
|
|
echo "2. Run with: $0 docker (recommended)"
|
|
echo "3. Or run with: $0 all"
|
|
;;
|
|
help|--help|-h)
|
|
show_help
|
|
;;
|
|
*)
|
|
print_error "Unknown option: $1"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|
|
|