# TraceStudio 快速启动脚本(Windows PowerShell) # 用于同时启动前后端服务 Write-Host "🚀 TraceStudio 启动中..." -ForegroundColor Cyan Write-Host "" # 检查 Python Write-Host "📍 检查 Python 环境..." -ForegroundColor Yellow $pythonCheck = python --version 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host "❌ Python 未安装或不在 PATH 中" -ForegroundColor Red Write-Host " 请安装 Python 3.11+ 或激活 conda 环境:" -ForegroundColor Red Write-Host " conda activate tracestudio" -ForegroundColor White exit 1 } Write-Host "✅ $pythonCheck" -ForegroundColor Green # 检查 Node.js Write-Host "📍 检查 Node.js 环境..." -ForegroundColor Yellow $nodeCheck = node --version 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host "❌ Node.js 未安装或不在 PATH 中" -ForegroundColor Red Write-Host " 请安装 Node.js 18+" -ForegroundColor Red exit 1 } Write-Host "✅ Node.js $nodeCheck" -ForegroundColor Green Write-Host "" # 启动后端 Write-Host "🔧 启动后端服务..." -ForegroundColor Cyan $backendJob = Start-Job -ScriptBlock { Set-Location $using:PSScriptRoot\server python main.py } Write-Host " 后端服务启动中 (Job ID: $($backendJob.Id))" -ForegroundColor Gray Start-Sleep -Seconds 3 # 启动前端 Write-Host "🎨 启动前端服务..." -ForegroundColor Cyan $frontendJob = Start-Job -ScriptBlock { Set-Location $using:PSScriptRoot\web npm run dev } Write-Host " 前端服务启动中 (Job ID: $($frontendJob.Id))" -ForegroundColor Gray Start-Sleep -Seconds 5 Write-Host "" Write-Host "=" * 60 -ForegroundColor Cyan Write-Host "✨ TraceStudio 已启动!" -ForegroundColor Green Write-Host "=" * 60 -ForegroundColor Cyan Write-Host "" Write-Host "📡 后端 API: http://127.0.0.1:8000" -ForegroundColor White Write-Host "📊 API 文档: http://127.0.0.1:8000/docs" -ForegroundColor White Write-Host "🎨 前端界面: http://localhost:5173" -ForegroundColor White Write-Host "" Write-Host "按 Ctrl+C 停止所有服务" -ForegroundColor Yellow Write-Host "" # 监控服务 try { while ($true) { Start-Sleep -Seconds 2 # 检查后端 $backendState = Get-Job -Id $backendJob.Id if ($backendState.State -eq "Failed") { Write-Host "❌ 后端服务异常退出" -ForegroundColor Red Receive-Job -Id $backendJob.Id break } # 检查前端 $frontendState = Get-Job -Id $frontendJob.Id if ($frontendState.State -eq "Failed") { Write-Host "❌ 前端服务异常退出" -ForegroundColor Red Receive-Job -Id $frontendJob.Id break } } } finally { Write-Host "" Write-Host "🛑 正在停止服务..." -ForegroundColor Yellow Stop-Job -Id $backendJob.Id -ErrorAction SilentlyContinue Stop-Job -Id $frontendJob.Id -ErrorAction SilentlyContinue Remove-Job -Id $backendJob.Id -ErrorAction SilentlyContinue Remove-Job -Id $frontendJob.Id -ErrorAction SilentlyContinue Write-Host "✅ 所有服务已停止" -ForegroundColor Green }