AudioForge / scripts /launch.ps1
OnyxlMunkey's picture
c618549
# AudioForge Master Launch Script (PowerShell)
# Windows equivalent of launch.sh
param(
[string]$Environment = "development",
[switch]$SkipTests = $false,
[switch]$DryRun = $false,
[switch]$Help = $false
)
# Colors
$Colors = @{
Red = "Red"
Green = "Green"
Yellow = "Yellow"
Blue = "Cyan"
Purple = "Magenta"
Cyan = "Cyan"
}
function Write-Info { Write-Host "[INFO] $args" -ForegroundColor $Colors.Blue }
function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor $Colors.Green }
function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor $Colors.Yellow }
function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor $Colors.Red }
function Write-Step {
Write-Host "`n═══ $args ═══`n" -ForegroundColor $Colors.Purple
}
if ($Help) {
Write-Host @"
AudioForge Master Launch Script
Usage:
.\scripts\launch.ps1 [-Environment ENV] [-SkipTests] [-DryRun] [-Help]
Options:
-Environment ENV Target environment (development|staging|production)
-SkipTests Skip test suite (not recommended for production)
-DryRun Show what would be done without executing
-Help Show this help message
"@
exit 0
}
$ProjectRoot = Split-Path -Parent $PSScriptRoot
function Test-Command {
param([string]$Command)
$null = Get-Command $Command -ErrorAction SilentlyContinue
return $?
}
function Invoke-Step {
param([scriptblock]$Action)
if ($DryRun) {
Write-Host "[DRY-RUN] Would execute: $Action" -ForegroundColor Yellow
} else {
& $Action
}
}
# Verify Prerequisites
Write-Step "Verifying Prerequisites"
if (-not (Test-Command python)) {
Write-Error "Python not found!"
exit 1
}
$pythonVersion = python --version
Write-Info "Python version: $pythonVersion"
if (-not (Test-Command node)) {
Write-Error "Node.js not found!"
exit 1
}
$nodeVersion = node --version
Write-Info "Node version: $nodeVersion"
if (-not (Test-Command pnpm)) {
Write-Warning "pnpm not found, installing..."
npm install -g pnpm
}
Write-Success "All prerequisites satisfied"
# Run Verification
Write-Step "Running Verification Checks"
Set-Location $ProjectRoot
if (-not $DryRun) {
python scripts/launch_verification.py --verbose --json launch-verification.json
if ($LASTEXITCODE -ne 0) {
Write-Error "Verification failed!"
exit 1
}
}
Write-Success "Verification checks passed"
# Setup Environment
Write-Step "Setting Up Environment: $Environment"
if (-not (Test-Path "backend\.env")) {
Write-Warning "Backend .env not found, creating from example..."
Copy-Item "backend\.env.example" "backend\.env"
}
if (-not (Test-Path "frontend\.env.local")) {
Write-Warning "Frontend .env.local not found, creating..."
if ($Environment -eq "production") {
"NEXT_PUBLIC_API_URL=https://api.yourdomain.com" | Out-File -FilePath "frontend\.env.local" -Encoding UTF8
} else {
"NEXT_PUBLIC_API_URL=http://localhost:8000" | Out-File -FilePath "frontend\.env.local" -Encoding UTF8
}
}
Write-Success "Environment configured"
# Install Dependencies
Write-Step "Installing Dependencies"
Write-Info "Installing backend dependencies..."
Set-Location "$ProjectRoot\backend"
Invoke-Step { pip install -e ".[dev]" }
Write-Info "Installing frontend dependencies..."
Set-Location "$ProjectRoot\frontend"
Invoke-Step { pnpm install --frozen-lockfile }
Write-Success "Dependencies installed"
# Run Tests
if (-not $SkipTests) {
Write-Step "Running Test Suite"
Write-Info "Running backend tests..."
Set-Location "$ProjectRoot\backend"
Invoke-Step { pytest tests/ -v --cov=app }
Write-Info "Running frontend tests..."
Set-Location "$ProjectRoot\frontend"
Invoke-Step { pnpm test }
Invoke-Step { pnpm run type-check }
Write-Success "All tests passed"
} else {
Write-Warning "Skipping tests (--SkipTests flag)"
}
# Build Applications
Write-Step "Building Applications"
Write-Info "Building frontend..."
Set-Location "$ProjectRoot\frontend"
Invoke-Step { pnpm run build }
Write-Success "Applications built successfully"
# Setup Database
Write-Step "Setting Up Database"
Set-Location "$ProjectRoot\backend"
Write-Info "Running database migrations..."
Invoke-Step { python scripts/init_db.py }
Write-Success "Database initialized"
# Start Services
Write-Step "Starting Services"
Set-Location $ProjectRoot
if (Test-Command docker-compose) {
Write-Info "Starting services with Docker Compose..."
Invoke-Step { docker-compose up -d }
if (-not $DryRun) {
Write-Info "Waiting for services to be healthy..."
Start-Sleep -Seconds 10
# Check backend health
for ($i = 0; $i -lt 30; $i++) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
Write-Success "Backend is healthy"
break
}
} catch {}
Start-Sleep -Seconds 2
}
# Check frontend health
for ($i = 0; $i -lt 30; $i++) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
Write-Success "Frontend is healthy"
break
}
} catch {}
Start-Sleep -Seconds 2
}
}
} else {
Write-Warning "Docker Compose not available, starting services manually..."
Write-Info "Starting backend..."
Set-Location "$ProjectRoot\backend"
Start-Process -FilePath "uvicorn" -ArgumentList "app.main:app --host 0.0.0.0 --port 8000" -NoNewWindow
Write-Info "Starting frontend..."
Set-Location "$ProjectRoot\frontend"
Start-Process -FilePath "pnpm" -ArgumentList "start" -NoNewWindow
}
Write-Success "Services started"
# Generate Report
Write-Step "Generating Launch Report"
Set-Location $ProjectRoot
Invoke-Step { python scripts/generate_launch_report.py }
Write-Success "Launch report generated: LAUNCH_REPORT.html"
# Post-Launch Verification
Write-Step "Post-Launch Verification"
if (-not $DryRun) {
Write-Info "Testing backend endpoint..."
try {
$response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing
Write-Success "Backend responding"
} catch {
Write-Error "Backend not responding"
exit 1
}
Write-Info "Testing frontend..."
try {
$response = Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing
Write-Success "Frontend responding"
} catch {
Write-Error "Frontend not responding"
exit 1
}
}
Write-Success "Post-launch verification complete"
# Success Message
Write-Host "`n" -NoNewline
Write-Host "╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "β•‘ β•‘" -ForegroundColor Green
Write-Host "β•‘ πŸŽ‰ LAUNCH SUCCESSFUL! πŸŽ‰ β•‘" -ForegroundColor Green
Write-Host "β•‘ β•‘" -ForegroundColor Green
Write-Host "β•‘ AudioForge is now running and ready! β•‘" -ForegroundColor Green
Write-Host "β•‘ β•‘" -ForegroundColor Green
Write-Host "╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host ""
Write-Success "Backend: http://localhost:8000"
Write-Success "Frontend: http://localhost:3000"
Write-Success "API Docs: http://localhost:8000/docs"
Write-Success "Launch Report: file://$ProjectRoot/LAUNCH_REPORT.html"
Write-Host ""
if ($Environment -eq "production") {
Write-Warning "Production deployment complete. Monitor logs and metrics closely."
}
Write-Info "🐼⚑ The panda has spoken. The launch is complete. 🎡"