# 用途: devflow 打包换装双通道脚本(verify=快速编译验证 / full=全量发版换装) # 生命周期: 长期保留(挂机模式打包组件的雏形,接力棒 M1 落地后由其接管安装段) # 用法: .\scripts\package-devflow.ps1 -Mode verify # 只验 release 编译,分钟级 # .\scripts\package-devflow.ps1 -Mode full # tauri build -> 杀进程 -> /S 静默装 -> 启动验证 param( [ValidateSet("verify", "full")] [string]$Mode = "verify" ) $ErrorActionPreference = "Continue" $repo = "E:\wk-lab\devflow" $exe = "$env:LOCALAPPDATA\devflow\devflow.exe" $minFreeGB = 10 Set-Location $repo function Get-FreeGB($path) { $drive = (Get-Item $path).PSDrive return [math]::Round($drive.Free / 1GB, 1) } $free = Get-FreeGB $repo if ($free -lt $minFreeGB) { Write-Host "[预检失败] E 盘剩余 ${free}GB < ${minFreeGB}GB,先清 target\debug\incremental(历史教训 os error 112)" exit 1 } Write-Host "[预检] E 盘剩余 ${free}GB,通过" if ($Mode -eq "verify") { Write-Host "== 通道1: 快速编译验证(cargo build --release,不打安装包) ==" cmd /c "cargo build --release 2>&1" if ($LASTEXITCODE -ne 0) { Write-Host "[失败] 编译未过"; exit 1 } Write-Host "[通过] release 编译成功(未打安装包)" exit 0 } Write-Host "== 通道2: 全量发版换装(tauri build -> 静默安装 -> 启动验证) ==" Write-Host "[1/4] tauri build(可能 10 分钟级)..." cmd /c "cargo tauri build 2>&1" if ($LASTEXITCODE -ne 0) { Write-Host "[失败] tauri build"; exit 1 } $bundle = Get-ChildItem "$repo\target\release\bundle\nsis\*.exe" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 if (-not $bundle) { Write-Host "[失败] 未找到安装包产物"; exit 1 } Write-Host "[2/4] 安装包: $($bundle.Name) ($([math]::Round($bundle.Length/1MB,1))MB, $($bundle.LastWriteTime))" Write-Host "[3/4] 杀旧进程 -> 静默安装..." Get-Process devflow -ErrorAction SilentlyContinue | Stop-Process -Force Start-Sleep -Seconds 2 Start-Process $bundle.FullName -ArgumentList "/S" -Wait if (-not (Test-Path $exe)) { Write-Host "[失败] 安装后未找到 $exe"; exit 1 } $exeTime = (Get-Item $exe).LastWriteTime Write-Host "[4/4] 启动验证(装机 exe 时间: $exeTime)..." Start-Process $exe Start-Sleep -Seconds 6 $proc = Get-Process devflow -ErrorAction SilentlyContinue if ($proc) { Write-Host "[换装成功] PID $($proc.Id) 存活,装机时间 $exeTime" } else { Write-Host "[警告] 启动后 6 秒未见进程,请人工确认(可能仍在初始化)" exit 1 }