Files
zyt/admin/scripts/start-hospital-preview.ps1
T
2026-11-11 13:53:14 +08:00

19 lines
1.3 KiB
PowerShell

param(
[string]$PhpPath = 'C:\Users\isard\.cache\zyt-tools\php\php.exe'
)
$ErrorActionPreference = 'Stop'
$projectPath = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
if (-not (Test-Path -LiteralPath $PhpPath -PathType Leaf)) { throw 'PHP 可执行文件不存在' }
if (Get-NetTCPConnection -LocalPort 8090 -State Listen -ErrorAction SilentlyContinue) { throw '8090 端口已占用,未停止任何进程' }
& node (Join-Path $PSScriptRoot 'prepare-hospital-preview.mjs')
if ($LASTEXITCODE -ne 0) { throw '医院预览准备失败' }
$runtimePath = Join-Path $projectPath '.test-runtime\hospital-preview'
$routerPath = Join-Path $PSScriptRoot 'hospital-preview-router.php'
$publicPath = Join-Path $projectPath 'server\public'
$arguments = @('-S', '127.0.0.1:8090', '-t', ('"' + $publicPath + '"'), ('"' + $routerPath + '"'))
# 隐藏控制台,不将 PHP 请求日志重定向到文件,避免保存回调 URL 中的短码。
$process = Start-Process -FilePath $PhpPath -ArgumentList $arguments -WorkingDirectory (Join-Path $projectPath 'server') -WindowStyle Hidden -PassThru
$state = [ordered]@{ pid = $process.Id; port = 8090; path = $runtimePath }
$state | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $runtimePath 'status.json') -Encoding utf8
$state | ConvertTo-Json