- Modified build command in package.json for improved reporting. - Updated pnpm-lock.yaml to remove obsolete dependencies and add new ones. - Enhanced TypeScript configuration in BFF for better compatibility with ES2024. - Refactored app.module.ts for clearer module organization and added comments for better understanding. - Adjusted next.config.mjs to conditionally enable standalone output based on environment. - Improved InternetPlansPage to fetch and display installation options alongside internet plans. - Cleaned up unnecessary comments and code in VPN plans page for better readability. - Updated manage.sh script to build shared packages and BFF before starting development applications.
179 lines
5.4 KiB
Bash
Executable File
179 lines
5.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 🔧 Development Environment Manager
|
|
# Manages development services with clean, organized structure
|
|
|
|
set -e
|
|
|
|
# Configuration
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
COMPOSE_FILE="$PROJECT_ROOT/docker/dev/docker-compose.yml"
|
|
ENV_FILE="$PROJECT_ROOT/.env"
|
|
PROJECT_NAME="portal-dev"
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m'
|
|
|
|
log() { echo -e "${GREEN}[DEV] $1${NC}"; }
|
|
warn() { echo -e "${YELLOW}[DEV] $1${NC}"; }
|
|
error() { echo -e "${RED}[DEV] ERROR: $1${NC}"; exit 1; }
|
|
|
|
# Change to project root
|
|
cd "$PROJECT_ROOT"
|
|
|
|
# Start development services
|
|
start_services() {
|
|
log "🚀 Starting development services..."
|
|
|
|
if [ ! -f "$ENV_FILE" ]; then
|
|
warn "Environment file not found at $ENV_FILE"
|
|
log "Creating from template..."
|
|
cp .env.example .env
|
|
warn "Please edit .env with your actual values"
|
|
fi
|
|
|
|
# Start PostgreSQL and Redis
|
|
docker compose -f "$COMPOSE_FILE" -p "$PROJECT_NAME" up -d postgres redis
|
|
|
|
# Wait for database
|
|
log "⏳ Waiting for database to be ready..."
|
|
timeout=30
|
|
while [ $timeout -gt 0 ]; do
|
|
if docker compose -f "$COMPOSE_FILE" -p "$PROJECT_NAME" exec -T postgres pg_isready -U dev -d portal_dev 2>/dev/null; then
|
|
log "✅ Database is ready!"
|
|
break
|
|
fi
|
|
sleep 2
|
|
timeout=$((timeout - 2))
|
|
done
|
|
|
|
if [ $timeout -eq 0 ]; then
|
|
error "Database failed to start within 30 seconds"
|
|
fi
|
|
|
|
log "✅ Development services are running!"
|
|
log "🔗 Database: postgresql://dev:dev@localhost:5432/portal_dev"
|
|
log "🔗 Redis: redis://localhost:6379"
|
|
}
|
|
|
|
# Start with admin tools
|
|
start_with_tools() {
|
|
log "🛠️ Starting development services with admin tools..."
|
|
docker compose -f "$COMPOSE_FILE" -p "$PROJECT_NAME" --profile tools up -d
|
|
|
|
log "🔗 Database Admin: http://localhost:8080"
|
|
log "🔗 Redis Commander: http://localhost:8081"
|
|
}
|
|
|
|
# Stop services
|
|
stop_services() {
|
|
log "⏹️ Stopping development services..."
|
|
docker compose -f "$COMPOSE_FILE" -p "$PROJECT_NAME" down
|
|
log "✅ Services stopped"
|
|
}
|
|
|
|
# Show status
|
|
show_status() {
|
|
log "📊 Development Services Status:"
|
|
docker compose -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps
|
|
}
|
|
|
|
# Show logs
|
|
show_logs() {
|
|
docker compose -f "$COMPOSE_FILE" -p "$PROJECT_NAME" logs -f "${@:2}"
|
|
}
|
|
|
|
# Start apps (services + local development)
|
|
start_apps() {
|
|
log "🚀 Starting development services and applications..."
|
|
|
|
# Start services if not running
|
|
if ! docker compose -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps | grep -q "Up"; then
|
|
start_services
|
|
fi
|
|
|
|
log "Starting development applications..."
|
|
# Export root env so both apps can read from central .env
|
|
set -a
|
|
source "$ENV_FILE" 2>/dev/null || true
|
|
set +a
|
|
|
|
# Build shared package first (required by both apps)
|
|
log "🔨 Building shared package..."
|
|
pnpm --filter @customer-portal/shared build
|
|
|
|
# Build BFF first to ensure dist directory exists for watch mode
|
|
log "🔨 Building BFF for initial setup..."
|
|
pnpm --filter @customer-portal/bff build
|
|
|
|
# Show startup information
|
|
log "🎯 Starting development applications..."
|
|
log "🔗 BFF API: http://localhost:${BFF_PORT:-4000}/api"
|
|
log "🔗 Frontend: http://localhost:${NEXT_PORT:-3000}"
|
|
log "🔗 Database: postgresql://dev:dev@localhost:5432/portal_dev"
|
|
log "🔗 Redis: redis://localhost:6379"
|
|
log "📚 API Docs: http://localhost:${BFF_PORT:-4000}/api/docs"
|
|
log "Starting apps with hot-reload..."
|
|
|
|
# Prisma Studio can be started manually with: pnpm db:studio
|
|
|
|
# Start apps (portal + bff) with hot reload in parallel
|
|
pnpm --parallel --filter @customer-portal/portal --filter @customer-portal/bff run dev
|
|
}
|
|
|
|
# Reset environment
|
|
reset_env() {
|
|
log "🔄 Resetting development environment..."
|
|
stop_services
|
|
docker compose -f "$COMPOSE_FILE" -p "$PROJECT_NAME" down -v
|
|
docker system prune -f
|
|
log "✅ Development environment reset"
|
|
}
|
|
|
|
# Run database migrations
|
|
migrate_db() {
|
|
log "🗄️ Running database migrations..."
|
|
|
|
if ! docker compose -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps postgres | grep -q "Up"; then
|
|
error "Database service not running. Run 'pnpm dev:start' first"
|
|
fi
|
|
|
|
pnpm db:migrate
|
|
log "✅ Database migrations completed"
|
|
}
|
|
|
|
# Main function
|
|
case "${1:-help}" in
|
|
"start") start_services ;;
|
|
"stop") stop_services ;;
|
|
"restart") stop_services && start_services ;;
|
|
"status") show_status ;;
|
|
"logs") show_logs "$@" ;;
|
|
"tools") start_with_tools ;;
|
|
"apps") start_apps ;;
|
|
"migrate") migrate_db ;;
|
|
"reset") reset_env ;;
|
|
"help"|*)
|
|
echo "🔧 Development Environment Manager"
|
|
echo ""
|
|
echo "Usage: $0 {command}"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " start - Start development services (PostgreSQL + Redis)"
|
|
echo " stop - Stop all development services"
|
|
echo " restart - Restart all services"
|
|
echo " status - Show service status"
|
|
echo " logs - Show service logs"
|
|
echo " tools - Start services with admin tools"
|
|
echo " apps - Start services + run development apps"
|
|
echo " migrate - Run database migrations"
|
|
echo " reset - Reset development environment"
|
|
echo " help - Show this help"
|
|
exit 0
|
|
;;
|
|
esac
|