fix: 修复 Windows start.ps1 闪退,保持终端不关闭便于 Debug
Test start.ps1 (Windows) / test-windows (push) Waiting to run

- 增加 trap 错误捕获与堆栈输出
- 增加 Wait-ForExit 结束时暂停,避免窗口闪退
- 使用 $PSScriptRoot 获取脚本目录
- README 补充 Windows 权限配置与启动说明

Made-with: Cursor
This commit is contained in:
2026-03-10 22:13:12 +08:00
parent b7a11abe9f
commit fe370bd5bc
2 changed files with 64 additions and 5 deletions
+26 -5
View File
@@ -4,6 +4,23 @@
# 一行命令: git clone https://git.51easyai.com/wangbo/easyai; cd easyai; .\start.ps1
$ErrorActionPreference = "Stop"
trap {
Write-Host ""
Write-Host "========================================" -ForegroundColor Red
Write-Host " 发生错误(便于 Debug" -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
if ($_.ScriptStackTrace) { Write-Host "`n$($_.ScriptStackTrace)" }
Wait-ForExit
exit 1
}
# 结束时保持窗口不关闭,便于查看输出和 Debug(CI 环境自动跳过)
function Wait-ForExit {
if ($env:CI -eq "true") { return }
Write-Host ""
Read-Host "按 Enter 键退出"
}
# 仅配置模式:DEPLOY_DRY_RUN=1 只生成配置文件,不执行 Docker 安装和启动
$script:DeployDryRun = if ($env:DEPLOY_DRY_RUN -eq "1") { $true } else { $false }
@@ -15,12 +32,13 @@ $DockerDesktopUrl = "https://desktop.docker.com/win/main/amd64/Docker%20Desktop%
function Write-Step { param($Msg) Write-Host $Msg }
function Write-Ok { param($Msg) Write-Host "$Msg" -ForegroundColor Green }
function Write-Err { param($Msg) Write-Host "$Msg" -ForegroundColor Red; exit 1 }
function Write-Err { param($Msg) Write-Host "$Msg" -ForegroundColor Red; throw $Msg }
function Write-Warn { param($Msg) Write-Host "⚠️ $Msg" -ForegroundColor Yellow }
# ==================== 项目初始化 ====================
function Init-ProjectDir {
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$scriptDir = $PSScriptRoot
if (-not $scriptDir) { throw "无法获取脚本所在目录。请在 easyai 目录下打开 PowerShell 执行: .\start.ps1" }
$composePath = Join-Path $scriptDir "docker-compose.yml"
if (Test-Path $composePath) {
Set-Location $scriptDir
@@ -122,7 +140,7 @@ function Install-DockerDesktop {
if (-not $isWin) {
Write-Warn "自动安装仅支持 Windows。请手动安装 Docker Desktop。"
Write-Host "下载地址: $DockerDesktopUrl"
exit 1
Wait-ForExit; exit 1
}
# 优先 winget,其次 Chocolatey
@@ -145,7 +163,7 @@ function Install-DockerDesktop {
Write-Warn "未找到 winget 或 Chocolatey,请手动安装 Docker Desktop。"
Write-Host "下载地址: $DockerDesktopUrl"
exit 1
Wait-ForExit; exit 1
}
function Test-Docker {
@@ -179,7 +197,7 @@ function Test-Docker {
if ($env:OS -eq "Windows_NT") {
Start-Process $DockerDesktopUrl
}
exit 1
Wait-ForExit; exit 1
}
"2" {
Install-DockerDesktop
@@ -259,6 +277,9 @@ function Main {
$accessIp = if ($script:DeployIP) { $script:DeployIP } else { "127.0.0.1" }
Write-Host "访问地址: http://${accessIp}:3010"
Write-Host ""
Wait-ForExit
}
Write-Host "EasyAI Windows 部署脚本启动中..." -ForegroundColor Cyan
Write-Host ""
Main