You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

90 lines
3.6 KiB

# ep-package.ps1
# 一键打包脚本:构建 zdxt-admin-web-server (3个端点) + zdxt-gateway-web-server
# 输出到 /dist/{timestamp}/ 目录
#
# 用法:
# .\ep-package.ps1 # 默认 dev 环境
# .\ep-package.ps1 -BuildEnv prod # prod 环境
param(
[ValidateSet("dev", "prod")]
[string]$BuildEnv = "dev"
)
$ErrorActionPreference = "Stop"
$projectRoot = (Get-Item $PSScriptRoot).Parent.FullName
# Windows 文件名不支持冒号(:), 使用 yyyy-MM-dd_HH 格式
$timestamp = Get-Date -Format "yyyy-MM-dd_HH"
$folderName = "{0}_{1}" -f $timestamp, $BuildEnv
$deployDir = Join-Path $projectRoot "dist\$folderName"
$endpoints = @("enf-ep", "ent-ep", "sup-ep")
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " ZDXT Server Package Script" -ForegroundColor Cyan
Write-Host (" Env: {0} | Timestamp: {1}" -f $BuildEnv, $timestamp) -ForegroundColor Cyan
Write-Host (" Output: dist\{0}" -f $folderName) -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
# ============ 1. Maven Build ============
Write-Host "[1/3] Maven Build admin-web-server + gateway-web-server ..." -ForegroundColor Yellow
Set-Location $projectRoot
$modules = "zdxt-web-server/zdxt-admin-web-server,zdxt-web-server/zdxt-gateway-web-server"
mvn clean package -P $BuildEnv -pl $modules -am -DskipTests
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "Maven Build Failed!" -ForegroundColor Red
exit 1
}
Write-Host "[1/3] Maven Build Success" -ForegroundColor Green
# ============ 2. Prepare Output Dir ============
Write-Host ""
Write-Host ("[2/3] Prepare Dir: {0}" -f $deployDir) -ForegroundColor Yellow
New-Item -ItemType Directory -Force -Path $deployDir | Out-Null
# ============ 3. Copy Artifacts ============
Write-Host ""
Write-Host "[3/3] Copy Artifacts ..." -ForegroundColor Yellow
# --- admin-web-server (3 endpoints) ---
$adminSource = Join-Path $projectRoot "zdxt-web-server\zdxt-admin-web-server\target\zdxt-admin-web-server.jar"
if (-not (Test-Path $adminSource)) {
Write-Host (" Admin artifact not found: {0}" -f $adminSource) -ForegroundColor Red
exit 1
}
foreach ($ep in $endpoints) {
$targetName = "zdxt-{0}.jar" -f $ep
Copy-Item $adminSource (Join-Path $deployDir $targetName) -Force
Write-Host (" [admin] {0}" -f $targetName) -ForegroundColor Green
}
# --- gateway-web-server ---
$gatewaySource = Join-Path $projectRoot "zdxt-web-server\zdxt-gateway-web-server\target\zdxt-gateway-web-server.jar"
if (-not (Test-Path $gatewaySource)) {
Write-Host (" Gateway artifact not found: {0}" -f $gatewaySource) -ForegroundColor Red
exit 1
}
$gatewayTargetName = "zdxt-gateway-web-server.jar"
Copy-Item $gatewaySource (Join-Path $deployDir $gatewayTargetName) -Force
Write-Host (" [gateway] {0}" -f $gatewayTargetName) -ForegroundColor Green
# ============ Done ============
$totalCount = $endpoints.Count + 1
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host (" Done! {0} jars" -f $totalCount) -ForegroundColor Cyan
Write-Host (" Output: {0}" -f $deployDir) -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Startup examples:" -ForegroundColor Yellow
foreach ($ep in $endpoints) {
$jarName = "zdxt-{0}.jar" -f $ep
Write-Host (" java -jar {0} --spring.profiles.include={1}-{2}" -f $jarName, $BuildEnv, $ep) -ForegroundColor Gray
}
Write-Host (" java -jar {0}" -f $gatewayTargetName) -ForegroundColor Gray
Write-Host ""