Files
md-preview/agent/scripts/build.ps1
Richard Wu 1e8cbea902 feat: zoom content with Ctrl+wheel (5% step, 50-300%)
- Ctrl+wheel zooms preview and editor; 90ms throttle; preventDefault stops WebView2 page zoom
- Range widened to 50-300%, step unified at 5% for wheel, toolbar buttons and Ctrl +/-
- No mouse-anchor (same scrolling behavior as button zoom)
- Add agent/AGENTS.md: workspace boundary is the top rule; build/test temp dirs stay in target/
- build.ps1 redirects TEMP/TMP into target/tmp
2026-10-21 16:23:00 +08:00

97 lines
3.3 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#requires -Version 5.1
<#
MD Preview 发布构建脚本
固定产物:D:\Scripts\md-preview\MD-Preview-windows-x64.exe
运行环境:普通 PowerShell(Medium),或 DSH 的 danger-full-access。
workspace-write 是 Low 完整性级别,写不动本目录(EPERM / os error 5)。
#>
[CmdletBinding()]
param(
[string]$OutputPath = 'D:\Scripts\md-preview\MD-Preview-windows-x64.exe',
[switch]$SkipTests
)
$ErrorActionPreference = 'Stop'
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
Set-Location $repoRoot
# 工作区规则(agent/AGENTS.md):构建/测试的临时文件也留在 target\ 下,不污染 %TEMP%。
$tmpRoot = Join-Path $repoRoot 'target\tmp'
New-Item -ItemType Directory -Force $tmpRoot | Out-Null
$env:TEMP = $tmpRoot
$env:TMP = $tmpRoot
$cargo = Join-Path $env:USERPROFILE '.cargo\bin\cargo.exe'
if (-not (Test-Path $cargo)) {
$cargo = (Get-Command cargo -ErrorAction Stop).Source
}
function Step([string]$text) { Write-Host ('==> ' + $text) -ForegroundColor Cyan }
function Assert-TargetNotRunning([string]$path) {
$ids = @()
foreach ($p in (Get-Process -ErrorAction SilentlyContinue)) {
$pPath = $null
try { $pPath = $p.Path } catch { }
if ($pPath -eq $path) { $ids += $p.Id }
}
if ($ids.Count -gt 0) {
throw ('MD Preview 正在运行(PID ' + ($ids -join ', ') + '),请先关闭窗口再构建。')
}
}
Assert-TargetNotRunning $OutputPath
if (-not $SkipTests) {
Step 'cargo test'
& $cargo test
if ($LASTEXITCODE -ne 0) { throw 'cargo test failed' }
}
Step 'cargo build --release'
& $cargo build --release
if ($LASTEXITCODE -ne 0) { throw 'cargo build failed' }
$built = Join-Path $repoRoot 'target\release\md-preview.exe'
if (-not (Test-Path $built)) { throw ('missing build output: ' + $built) }
Step ('copy -> ' + $OutputPath)
$outDir = Split-Path -Parent $OutputPath
if (-not (Test-Path $outDir)) { New-Item -ItemType Directory -Path $outDir | Out-Null }
Assert-TargetNotRunning $OutputPath
try {
Copy-Item $built $OutputPath -Force -ErrorAction Stop
} catch {
throw ('复制失败(目标可能被占用):' + $_.Exception.Message)
}
$info = Get-Item $OutputPath
$hash = (Get-FileHash $OutputPath -Algorithm SHA256).Hash
Write-Host ('size : {0:N0} bytes' -f $info.Length)
Write-Host ('sha256 : ' + $hash)
Write-Host ('version : ' + $info.VersionInfo.FileVersion)
Step 'check removed update strings'
$bytes = [IO.File]::ReadAllBytes($OutputPath)
$ascii = [Text.Encoding]::ASCII.GetString($bytes)
$forbidden = @('api.github', 'btn-update', 'Check for Updates', 'powershell', 'update-check-result', 'open-url')
$bad = @()
foreach ($needle in $forbidden) {
$count = ([regex]::Matches($ascii, [regex]::Escape($needle), 'IgnoreCase')).Count
Write-Host (' {0,-20} {1}' -f $needle, $count)
if ($count -ne 0) { $bad += $needle }
}
if ($bad.Count -gt 0) { throw ('removed features still present: ' + ($bad -join ', ')) }
Step 'check integrity level'
$acl = (icacls $OutputPath | Out-String)
if ($acl -match 'Medium Mandatory Level') {
Write-Host ' Medium - OK'
} else {
Write-Warning '不是 Medium:启动时可能报 os error 5,见 agent/docs/HANDOFF.md 第 4 节'
}
Write-Host ''
Write-Host ('DONE ' + $OutputPath) -ForegroundColor Green