#!/usr/bin/env bash set -euo pipefail # ─── Color output ────────────────────────────────────────────── RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' CYAN='\033[0;36m' NC='\033[0m' # No Color info() { echo -e "${CYAN}[INFO]${NC} $*"; } ok() { echo -e "${GREEN}[OK]${NC} $*"; } warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } error() { echo -e "${RED}[ERROR]${NC} $*"; } # ─── Prerequisites ────────────────────────────────────────────── info "Checking prerequisites..." command -v docker >/dev/null 2>&1 || { error "Docker is required but not installed."; exit 1; } ok "Docker $(docker --version)" docker compose version >/dev/null 2>&1 || { error "Docker Compose is required but not installed."; exit 1; } ok "Docker Compose $(docker compose version --short)" command -v node >/dev/null 2>&1 || { error "Node.js is required but not installed."; exit 1; } ok "Node.js $(node --version)" command -v pnpm >/dev/null 2>&1 || { error "pnpm is required but not installed. Install it: npm install -g pnpm"; exit 1; } ok "pnpm $(pnpm --version)" # ─── Project root ─────────────────────────────────────────────── SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" cd "${PROJECT_ROOT}" # ─── Environment file ─────────────────────────────────────────── if [ ! -f .env ]; then if [ -f .env.example ]; then cp .env.example .env info "Created .env from .env.example — please review and update credentials." else warn "No .env.example found. Creating minimal .env..." cat > .env <<-EOF POSTGRES_USER=investplay POSTGRES_PASSWORD=investplay_dev_pass POSTGRES_DB=investplay DATABASE_URL=postgresql://investplay:investplay_dev_pass@localhost:5432/investplay REDIS_URL=redis://localhost:6379 MINIO_ROOT_USER=minioadmin MINIO_ROOT_PASSWORD=minioadmin_dev MINIO_ENDPOINT=localhost MINIO_PORT=9000 MINIO_USE_SSL=false JWT_SECRET=change-me-in-production EOF ok "Created minimal .env" fi else ok ".env already exists" fi # ─── Start infrastructure services ────────────────────────────── info "Starting infrastructure (PostgreSQL, Redis, MinIO)..." docker compose -f docker-compose.dev.yml up -d postgres redis minio info "Waiting for PostgreSQL to become healthy..." until docker compose -f docker-compose.dev.yml exec -T postgres pg_isready -U "${POSTGRES_USER:-investplay}" 2>/dev/null; do sleep 2 done ok "PostgreSQL is ready" info "Waiting for Redis to become healthy..." until docker compose -f docker-compose.dev.yml exec -T redis redis-cli ping 2>/dev/null | grep -q PONG; do sleep 1 done ok "Redis is ready" info "Waiting for MinIO to become healthy..." until docker compose -f docker-compose.dev.yml exec -T minio mc ready local 2>/dev/null; do sleep 2 done ok "MinIO is ready" # ─── Install dependencies ─────────────────────────────────────── info "Installing pnpm dependencies..." pnpm install ok "Dependencies installed" # ─── Generate Prisma client ───────────────────────────────────── info "Running Prisma migrations..." if [ -f apps/api/prisma/schema.prisma ]; then pnpm --filter @investplay/api exec prisma generate pnpm --filter @investplay/api exec prisma migrate dev --name init 2>/dev/null || true ok "Prisma client generated and migrations applied" else warn "No Prisma schema found at apps/api/prisma/schema.prisma — skipping migrations" fi # ─── Seed database ───────────────────────────────────────────── if [ -f apps/api/prisma/seed.ts ] || [ -f apps/api/prisma/seed.js ]; then info "Seeding database..." pnpm --filter @investplay/api exec prisma db seed 2>/dev/null || true ok "Database seeded" else info "No seed script found — skipping" fi # ─── Start remaining services ────────────────────────────────── info "Starting API, Web, and CMS..." docker compose -f docker-compose.dev.yml up -d api web cms ok "All services started" # ─── Summary ──────────────────────────────────────────────────── echo "" echo -e "${GREEN}══════════════════════════════════════════════════════════${NC}" echo -e "${GREEN} InvestPlay development environment is ready!${NC}" echo -e "${GREEN}══════════════════════════════════════════════════════════${NC}" echo "" echo -e " ${CYAN}Web App:${NC} http://localhost:5173" echo -e " ${CYAN}API:${NC} http://localhost:3001" echo -e " ${CYAN}CMS:${NC} http://localhost:3000" echo -e " ${CYAN}MinIO Console:${NC} http://localhost:9001" echo -e " ${CYAN}PostgreSQL:${NC} localhost:5432" echo -e " ${CYAN}Redis:${NC} localhost:6379" echo "" echo -e " ${YELLOW}Run 'docker compose -f docker-compose.dev.yml logs -f' to tail logs${NC}" echo ""