64 lines
2.8 KiB
PowerShell
64 lines
2.8 KiB
PowerShell
# Yuqei AI Contract Platform - one-click local startup.
|
|
# Usage (repo root): powershell -ExecutionPolicy Bypass -File .\start-dev.ps1
|
|
# Optional: add -WithReviewWorker to also start the contract review worker.
|
|
# NOTE: keep this file ASCII-only. Windows PowerShell 5.1 misreads UTF-8
|
|
# comments without BOM (GBK mojibake breaks the parser).
|
|
|
|
param(
|
|
[switch]$WithReviewWorker
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$root = $PSScriptRoot
|
|
$python = Join-Path $root ".venv-project\Scripts\python.exe"
|
|
|
|
if (-not (Test-Path $python)) {
|
|
Write-Host "Python not found: $python" -ForegroundColor Red
|
|
Write-Host "Rebuild the venv first: python -m venv .venv-project then .\.venv-project\Scripts\pip install -e yuqei-contract-platform\services\contract-api -e yuqei-ai-platform\services\ai-platform-api -e yuqei-ai-platform\services\worker -e yuqei-ai-sdk-python"
|
|
exit 1
|
|
}
|
|
|
|
function Start-ServiceWindow($title, $workDir, $command) {
|
|
Start-Process powershell -ArgumentList @(
|
|
"-NoExit", "-Command",
|
|
"`$Host.UI.RawUI.WindowTitle = '$title'; Set-Location '$workDir'; $command"
|
|
)
|
|
}
|
|
|
|
# 0) Database migration (idempotent; skips applied migrations; never blocks startup)
|
|
Write-Host "Running database migrations (alembic upgrade head)..." -ForegroundColor Cyan
|
|
$apiDir = Join-Path $root "yuqei-contract-platform\services\contract-api"
|
|
Push-Location $apiDir
|
|
& $python -m alembic upgrade head
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "Database migrations up to date." -ForegroundColor Green
|
|
} else {
|
|
Write-Host "Migration check did not complete (services will still start; re-run manually when the DB is reachable)." -ForegroundColor Yellow
|
|
}
|
|
Pop-Location
|
|
|
|
# 1) Contract API (port 8100)
|
|
Start-ServiceWindow "contract-api :8100" (Join-Path $root "yuqei-contract-platform\services\contract-api") `
|
|
"& '$python' -m uvicorn yuqei_contract_api.main:app --app-dir src --reload --port 8100"
|
|
|
|
# 2) AI Platform API (port 8101)
|
|
Start-ServiceWindow "ai-platform-api :8101" (Join-Path $root "yuqei-ai-platform\services\ai-platform-api") `
|
|
"& '$python' -m uvicorn yuqei_ai_platform_api.main:app --app-dir src --reload --port 8101"
|
|
|
|
# 3) Contract Web (port 3000)
|
|
Start-ServiceWindow "contract-web :3000" (Join-Path $root "yuqei-contract-platform\apps\contract-web") `
|
|
"npm run dev"
|
|
|
|
# 4) Optional: contract review worker
|
|
if ($WithReviewWorker) {
|
|
$workerDir = Join-Path $root "yuqei-contract-platform\services\contract-api"
|
|
Start-ServiceWindow "contract-review-worker" $workerDir `
|
|
"`$env:PYTHONPATH='src;..\..\..\yuqei-ai-sdk-python\src'; & '$python' -m yuqei_contract_api.review_worker"
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "Started: Contract API(8100) / AI Platform(8101) / Web(3000)" -ForegroundColor Green
|
|
if ($WithReviewWorker) { Write-Host "Started: contract review worker" -ForegroundColor Green }
|
|
Start-Sleep -Seconds 8
|
|
Start-Process "http://localhost:3000"
|