53 lines
1.6 KiB
PowerShell
53 lines
1.6 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
||
|
||
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||
Set-Location -LiteralPath $root
|
||
|
||
$envFile = Join-Path $root '.env'
|
||
if (-not (Test-Path -LiteralPath $envFile)) {
|
||
throw "缺少 $envFile 。复制 .env.example 为 .env,只在本机填 RPA_ORACLE_PASSWORD,不要 git add。"
|
||
}
|
||
|
||
foreach ($raw in Get-Content -LiteralPath $envFile) {
|
||
$line = $raw.Trim()
|
||
if ($line -eq '' -or $line.StartsWith('#')) {
|
||
continue
|
||
}
|
||
$eq = $line.IndexOf('=')
|
||
if ($eq -lt 1) {
|
||
continue
|
||
}
|
||
$key = $line.Substring(0, $eq).Trim()
|
||
$value = $line.Substring($eq + 1).Trim()
|
||
if ($value.Length -ge 2) {
|
||
$quote = $value[0]
|
||
if (($quote -eq '"' -or $quote -eq "'") -and $value[-1] -eq $quote) {
|
||
$value = $value.Substring(1, $value.Length - 2)
|
||
}
|
||
}
|
||
Set-Item -Path "Env:$key" -Value $value
|
||
}
|
||
|
||
if ([string]::IsNullOrWhiteSpace($env:RPA_ORACLE_PASSWORD)) {
|
||
throw "rpa_oms/.env 里 RPA_ORACLE_PASSWORD 为空。只写本机文件,不要提交。"
|
||
}
|
||
|
||
$venvPy = Join-Path $root '.venv\Scripts\python.exe'
|
||
if (Test-Path -LiteralPath $venvPy) {
|
||
& $venvPy @('-m', 'uvicorn', 'app.main:app', '--host', '0.0.0.0', '--port', '8001')
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "uvicorn 退出码 $LASTEXITCODE"
|
||
}
|
||
return
|
||
}
|
||
|
||
$uv = Get-Command uv -ErrorAction SilentlyContinue
|
||
if ($null -eq $uv) {
|
||
throw "找不到 uv,也没有 rpa_oms\.venv\Scripts\python.exe"
|
||
}
|
||
|
||
& $uv.Source @('run', '--python', '3.12', 'uvicorn', 'app.main:app', '--host', '0.0.0.0', '--port', '8001')
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "uvicorn 退出码 $LASTEXITCODE"
|
||
}
|