xyc
3 天以前 de1405ba56db542f64fb8bf5a381a19126837cb2
pack-deploy.ps1
@@ -3,6 +3,9 @@
  用法:
    powershell -NoProfile -ExecutionPolicy Bypass -File pack-deploy.ps1
    powershell -NoProfile -ExecutionPolicy Bypass -File pack-deploy.ps1 -OutRoot "E:\试验" -SkipFrontend
    powershell -NoProfile -ExecutionPolicy Bypass -File pack-deploy.ps1 -NoFrontend
      —— 单端口瘦包:完全不打包前端(不构建 npm、不复制 frontend/dist 与 backend/web),
         部署机保留原有 backend\web,仅替换 jar,可显著减小包体积。
  做五件事:
    1) 用 deploy-templates\jar-application.yml(全占位符)临时替换源码 application.yml,
@@ -22,6 +25,7 @@
param(
  [string]$OutRoot = '',
  [switch]$SkipFrontend,
  [switch]$NoFrontend,      # 单端口瘦包:完全不打包前端(不构建/不复制 dist 与 backend\web),部署机保留原有 web/
  [switch]$SkipBackend,     # 复用已存在的 jar(不重编译、不动源码配置),仅用于补全/重组发布包
  [switch]$SkipServiceWrapper   # 不把 WinSW 服务包装器打进包(即不提供“注册成 Windows 服务”的开机自启)
)
@@ -106,8 +110,10 @@
Write-Host '      通过:jar 内置配置全部为占位符,无明文密钥/口令。'
# ---------- [3/5] 前端构建 ----------
Write-Host '[3/5] 构建前端(npm run build,可 -SkipFrontend 跳过)...'
if (-not $SkipFrontend) {
Write-Host '[3/5] 构建前端(npm run build,可 -SkipFrontend / -NoFrontend 跳过)...'
if ($NoFrontend) {
  Write-Host '      已按 -NoFrontend 跳过:本次不打前端(单端口瘦包,部署机保留原有 backend\web)'
} elseif (-not $SkipFrontend) {
  Push-Location (Join-Path $root 'traffic-audit-web')
  try {
    cmd /c "npm.cmd run build > ..\pack-front.log 2>&1"
@@ -118,7 +124,7 @@
} else {
  Write-Host '      已按 -SkipFrontend 跳过,使用现有 dist'
}
if (-not (Test-Path $webDist)) { throw "未找到前端产物:$webDist(去掉 -SkipFrontend 重新构建)" }
if (-not $NoFrontend -and -not (Test-Path $webDist)) { throw "未找到前端产物:$webDist(去掉 -SkipFrontend 重新构建)" }
# ---------- WinSW(Windows 服务包装器)准备:本地缓存优先,缺失时从官方发布页下载并校验 SHA-256 ----------
# WinSW v2.12.0 官方产物未做 Authenticode 签名,所以以固定 SHA-256 作为完整性校验。
@@ -160,7 +166,11 @@
$dest = Join-Path $OutRoot ("traffic-audit-deploy-" + $stamp)
$n = 2
while (Test-Path $dest) { $dest = Join-Path $OutRoot ("traffic-audit-deploy-" + $stamp + "-" + $n); $n++ }
New-Item -ItemType Directory -Force -Path (Join-Path $dest 'backend'), (Join-Path $dest 'frontend'), (Join-Path $dest 'db') | Out-Null
if ($NoFrontend) {
  New-Item -ItemType Directory -Force -Path (Join-Path $dest 'backend'), (Join-Path $dest 'db') | Out-Null
} else {
  New-Item -ItemType Directory -Force -Path (Join-Path $dest 'backend'), (Join-Path $dest 'frontend'), (Join-Path $dest 'db') | Out-Null
}
Copy-Item $jar (Join-Path $dest 'backend') -Force
Copy-Item (Join-Path $tplDir 'backend\application.yml') (Join-Path $dest 'backend') -Force
@@ -175,12 +185,16 @@
  Copy-Item (Join-Path $tplDir 'backend\install-service.ps1') (Join-Path $dest 'backend') -Force
  Copy-Item (Join-Path $tplDir 'backend\install-service.cmd') (Join-Path $dest 'backend') -Force
}
Copy-Item $webDist (Join-Path $dest 'frontend') -Recurse -Force
Copy-Item (Join-Path $tplDir 'frontend\nginx.conf.example') (Join-Path $dest 'frontend') -Force
if (-not $NoFrontend) {
  Copy-Item $webDist (Join-Path $dest 'frontend') -Recurse -Force
  Copy-Item (Join-Path $tplDir 'frontend\nginx.conf.example') (Join-Path $dest 'frontend') -Force
}
Copy-Item (Join-Path $tplDir 'db\*.sql') (Join-Path $dest 'db') -Force
# 单端口 8090 模式:后端从 jar 同级 web\ 读前端静态文件,必须和 dist 内容一致
Copy-Item $webDist (Join-Path $dest 'backend\web') -Recurse -Force
if (-not $NoFrontend) {
  Copy-Item $webDist (Join-Path $dest 'backend\web') -Recurse -Force
}
# docs:运行时模板 + 用户文档;排除开发过程文档与缓存/备份(减小体积、避免把内部清单带出去)
$docsDest = Join-Path $dest 'backend\docs'