Files
desktop-plugin/tool/package_windows.ps1
2026-09-28 10:48:38 +08:00

60 lines
2.6 KiB
PowerShell
Raw Permalink 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.
# 资安信插件助手 Windows 一键打包脚本(版本号自动注入)
# 用法:在项目根目录执行 powershell -ExecutionPolicy Bypass -File tool\package_windows.ps1
# 产物:dist\资安信插件助手-windows-setup-<版本>.exe
# 版本格式:1.0.<MMdd.HHmm>.<git短哈希>,同时写入:
# - lib\build_info.g.dart(App 内/manifest/启动日志可见)
# - 安装包文件名(一眼区分新旧包)
param(
[string]$InnoPath = "$env:LOCALAPPDATA\Programs\Inno Setup 6\ISCC.exe"
)
$ErrorActionPreference = 'Stop'
Set-Location (Join-Path $PSScriptRoot '..')
# ---- 1. 计算版本 ----
$gitHash = (git rev-parse --short HEAD).Trim()
if (-not $gitHash) { $gitHash = 'nogit' }
$stamp = Get-Date -Format 'MMdd.HHmm'
$version = "1.0.$stamp.$gitHash"
# ---- 2. 写入版本文件(UTF-8 无 BOM,Dart 兼容) ----
$dartContent = @"
// 由打包脚本自动生成(tool/package_windows.ps1 / tool/package_macos.sh),勿手改。
// 手动 flutter build 未跑脚本时保持上次打包的值;脚本打包会写入"版本+git提交+时间"。
const String kBuildVersion = '$version';
"@
[System.IO.File]::WriteAllText(
(Join-Path (Get-Location) 'lib\build_info.g.dart'),
$dartContent,
(New-Object System.Text.UTF8Encoding($false))
)
Write-Host "==> 版本号:$version(git=$gitHash)"
# ---- 3. flutter 构建 ----
Write-Host '==> flutter build windows --release'
flutter build windows --release
if ($LASTEXITCODE -ne 0) { throw 'flutter build 失败' }
# ---- 4. 定位 ISCC ----
if (-not (Test-Path $InnoPath)) {
$candidates = @(
'C:\Program Files (x86)\Inno Setup 6\ISCC.exe',
'C:\Program Files\Inno Setup 6\ISCC.exe'
)
$InnoPath = $candidates | Where-Object { Test-Path $_ } | Select-Object -First 1
}
if (-not $InnoPath) { throw "未找到 Inno Setup(ISCC.exe)。请安装 Inno 6:https://jrsoftware.org/isdl.php" }
# ---- 5. Inno 编译(带版本号注入安装包文件名) ----
Write-Host "==> iscc /DAppVersionFull=$version"
& $InnoPath "/DAppVersionFull=$version" 'windows\installer.iss'
if ($LASTEXITCODE -ne 0) { throw 'iscc 编译失败' }
# ---- 6. 收尾提示 ----
$out = "dist\资安信插件助手-windows-setup-$version.exe"
Write-Host ''
Write-Host '==> 打包完成'
if (Test-Path $out) { Get-Item $out | Select-Object Name, Length, LastWriteTime | Format-List }
Write-Host '提醒:安装新版前,先退出右下角托盘里旧版"资安信插件助手"(否则 38200 被旧实例占用,浏览器仍连旧版)。'
Write-Host "验证:安装后浏览器打开 http://127.0.0.1:38200/manifest ,version 字段应为:$version"