From de1405ba56db542f64fb8bf5a381a19126837cb2 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期一, 05 十月 2026 06:36:19 +0800
Subject: [PATCH] feat(deploy): pack-deploy 支持 -NoFrontend 生成单端口瘦包
---
pack-deploy.ps1 | 30 ++++++++++++++++++++++--------
1 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/pack-deploy.ps1 b/pack-deploy.ps1
index 0720fdc..ca4d065 100644
--- a/pack-deploy.ps1
+++ b/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
+ 鈥斺�� 鍗曠鍙g槮鍖咃細瀹屽叏涓嶆墦鍖呭墠绔紙涓嶆瀯寤� 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, # 鍗曠鍙g槮鍖咃細瀹屽叏涓嶆墦鍖呭墠绔紙涓嶆瀯寤�/涓嶅鍒� dist 涓� backend\web锛夛紝閮ㄧ讲鏈轰繚鐣欏師鏈� web/
[switch]$SkipBackend, # 澶嶇敤宸插瓨鍦ㄧ殑 jar锛堜笉閲嶇紪璇戙�佷笉鍔ㄦ簮鐮侀厤缃級锛屼粎鐢ㄤ簬琛ュ叏/閲嶇粍鍙戝竷鍖�
[switch]$SkipServiceWrapper # 涓嶆妸 WinSW 鏈嶅姟鍖呰鍣ㄦ墦杩涘寘锛堝嵆涓嶆彁渚涒�滄敞鍐屾垚 Windows 鏈嶅姟鈥濈殑寮�鏈鸿嚜鍚級
)
@@ -106,8 +110,10 @@
Write-Host ' 閫氳繃锛歫ar 鍐呯疆閰嶇疆鍏ㄩ儴涓哄崰浣嶇锛屾棤鏄庢枃瀵嗛挜/鍙d护銆�'
# ---------- [3/5] 鍓嶇鏋勫缓 ----------
-Write-Host '[3/5] 鏋勫缓鍓嶇锛坣pm run build锛屽彲 -SkipFrontend 璺宠繃锛�...'
-if (-not $SkipFrontend) {
+Write-Host '[3/5] 鏋勫缓鍓嶇锛坣pm run build锛屽彲 -SkipFrontend / -NoFrontend 璺宠繃锛�...'
+if ($NoFrontend) {
+ Write-Host ' 宸叉寜 -NoFrontend 璺宠繃锛氭湰娆′笉鎵撳墠绔紙鍗曠鍙g槮鍖咃紝閮ㄧ讲鏈轰繚鐣欏師鏈� 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锛圵indows 鏈嶅姟鍖呰鍣級鍑嗗锛氭湰鍦扮紦瀛樹紭鍏堬紝缂哄け鏃朵粠瀹樻柟鍙戝竷椤典笅杞藉苟鏍¢獙 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锛氳繍琛屾椂妯℃澘 + 鐢ㄦ埛鏂囨。锛涙帓闄ゅ紑鍙戣繃绋嬫枃妗d笌缂撳瓨/澶囦唤锛堝噺灏忎綋绉�侀伩鍏嶆妸鍐呴儴娓呭崟甯﹀嚭鍘伙級
$docsDest = Join-Path $dest 'backend\docs'
@@ -188,7 +202,7 @@
cmd /c "robocopy `"$root\docs`" `"$docsDest`" /E /NFL /NDL /NJH /NJS /NP /XD _cache 宸ヤ綔鏃ョ粨 鍔熻兘娴嬭瘯鎶ュ憡 闂姹囨�� /XF 鐢熸垚_*.xlsx _bak_* >nul"
if ($LASTEXITCODE -ge 8) { throw "docs 澶嶅埗澶辫触锛坮obocopy 杩斿洖 $LASTEXITCODE锛�" }
# db 鑴氭湰涔熸斁涓�浠藉埌 docs锛堜笌鏃у寘涓�鑷达細docs/init.sql 绛夛級
-Copy-Item (Join-Path $tplDir 'db\init.sql'), (Join-Path $tplDir 'db\sql_city_bus.sql'), (Join-Path $tplDir 'db\sql_city_taxi.sql'), (Join-Path $tplDir 'db\sql_wyc.sql'), (Join-Path $tplDir 'db\sql_holiday.sql'), (Join-Path $tplDir 'db\sql_holiday_decimal_migration.sql'), (Join-Path $tplDir 'db\sql_holiday_comparison_base_migration.sql') $docsDest -Force -ErrorAction SilentlyContinue
+Copy-Item (Join-Path $tplDir 'db\init.sql'), (Join-Path $tplDir 'db\sql_city_bus.sql'), (Join-Path $tplDir 'db\sql_city_taxi.sql'), (Join-Path $tplDir 'db\sql_wyc.sql'), (Join-Path $tplDir 'db\sql_holiday.sql'), (Join-Path $tplDir 'db\sql_holiday_decimal_migration.sql'), (Join-Path $tplDir 'db\sql_holiday_comparison_base_migration.sql'), (Join-Path $tplDir 'db\sql_holiday_previous_day_migration.sql'), (Join-Path $tplDir 'db\sql_observation_station.sql') $docsDest -Force -ErrorAction SilentlyContinue
# README锛氱敤妯℃澘骞舵浛鎹㈡棩鏈熷崰浣�
$readme = Get-Content (Join-Path $tplDir 'README-閮ㄧ讲璇存槑.txt') -Raw -Encoding UTF8
--
Gitblit v1.9.1