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.

158 lines
5.8 KiB

# client-package.ps1
5 months ago
# 一键打包前端项目:zdxt-admin-plus-ui + 3 个独立 App
# - zdxt-efcode-enterprise-app -> zdxt-ent-app
# - zdxt-efcode-enforcement-app -> zdxt-enf-app
# - zdxt-efcode-supervision-app -> zdxt-sup-app
# 输出到 /dist/{timestamp}_{env}/ 目录
#
# 用法:
# .\client-package.ps1 # 默认 dev 环境
# .\client-package.ps1 -BuildEnv prod # prod 环境
param(
[ValidateSet("dev", "prod")]
[string]$BuildEnv = "dev"
)
$ErrorActionPreference = "Stop"
$projectRoot = (Get-Item $PSScriptRoot).Parent.FullName
$timestamp = Get-Date -Format "yyyy-MM-dd_HH"
$folderName = "{0}_{1}" -f $timestamp, $BuildEnv
$deployDir = Join-Path $projectRoot "dist\$folderName"
# --- 项目配置 ---
$uiProjectDir = Join-Path $projectRoot "zdxt-web-client\zdxt-admin-plus-ui"
$uiName = "zdxt-admin-plus-ui"
$uiOutputName = "zdxt-sup-web"
5 months ago
# 3 个独立 App 项目配置
$appProjects = @(
@{ dir = "zdxt-efcode-enterprise-app"; mode = "enterprise"; output = "zdxt-ent-app" },
@{ dir = "zdxt-efcode-enforcement-app"; mode = "enforcement"; output = "zdxt-enf-app" },
@{ dir = "zdxt-efcode-supervision-app"; mode = "supervision"; output = "zdxt-sup-app" }
)
5 months ago
$totalParts = 1 + $appProjects.Count # 1(UI) + 3(Apps)
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " ZDXT Client 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 ""
# ======================================================
# Part 1: zdxt-admin-plus-ui
# ======================================================
5 months ago
Write-Host (">>> [Part 1/{0}] zdxt-admin-plus-ui" -f $totalParts) -ForegroundColor Magenta
Write-Host ""
# 1.1 npm install
Write-Host "[1/3] npm install ..." -ForegroundColor Yellow
Set-Location $uiProjectDir
if (-not (Test-Path (Join-Path $uiProjectDir "node_modules"))) {
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "npm install Failed!" -ForegroundColor Red
exit 1
}
Write-Host "[1/3] npm install Success" -ForegroundColor Green
} else {
Write-Host "[1/3] node_modules exists, skip install" -ForegroundColor Green
}
# 1.2 Vite Build
Write-Host ""
5 months ago
$buildScript = "build-{0}:{1}" -f $uiName, $BuildEnv
Write-Host ("[2/3] npm run {0} ..." -f $buildScript) -ForegroundColor Yellow
npm run $buildScript
if ($LASTEXITCODE -ne 0) {
Write-Host "Vite Build Failed!" -ForegroundColor Red
exit 1
}
Write-Host "[2/3] Vite Build Success" -ForegroundColor Green
# 1.3 Copy
Write-Host ""
Write-Host "[3/3] Copy Artifacts ..." -ForegroundColor Yellow
$buildOutputDir = Join-Path $uiProjectDir "dist\$BuildEnv"
if (-not (Test-Path $buildOutputDir)) {
Write-Host (" Build output not found: {0}" -f $buildOutputDir) -ForegroundColor Red
exit 1
}
$targetDir = Join-Path $deployDir $uiOutputName
New-Item -ItemType Directory -Force -Path $targetDir | Out-Null
Copy-Item -Path (Join-Path $buildOutputDir "*") -Destination $targetDir -Recurse -Force
Write-Host (" [ui] {0}" -f $uiOutputName) -ForegroundColor Green
# ======================================================
5 months ago
# Part 2~4: 3 个独立 App (enterprise / enforcement / supervision)
# ======================================================
5 months ago
$partIndex = 1
foreach ($app in $appProjects) {
$partIndex++
$appDir = Join-Path $projectRoot ("zdxt-web-client\{0}" -f $app.dir)
$mode = $app.mode
$outputName = $app.output
5 months ago
Write-Host ""
Write-Host (">>> [Part {0}/{1}] {2}" -f $partIndex, $totalParts, $app.dir) -ForegroundColor Magenta
Write-Host ""
5 months ago
# npm install
Write-Host "[1/3] npm install ..." -ForegroundColor Yellow
Set-Location $appDir
if (-not (Test-Path (Join-Path $appDir "node_modules"))) {
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host ("npm install Failed for {0}!" -f $app.dir) -ForegroundColor Red
exit 1
}
Write-Host "[1/3] npm install Success" -ForegroundColor Green
} else {
Write-Host "[1/3] node_modules exists, skip install" -ForegroundColor Green
}
5 months ago
# Vite Build
Write-Host ""
5 months ago
$script = "build-app:{0}-{1}" -f $mode, $BuildEnv
5 months ago
Write-Host ("[2/3] npm run {0} ..." -f $script) -ForegroundColor Yellow
npm run $script
if ($LASTEXITCODE -ne 0) {
Write-Host (" Build [{0}] Failed!" -f $mode) -ForegroundColor Red
exit 1
}
Write-Host (" Build [{0}] Success" -f $mode) -ForegroundColor Green
5 months ago
# Copy
Write-Host ""
Write-Host "[3/3] Copy Artifacts ..." -ForegroundColor Yellow
$appBuildDir = Join-Path $appDir ("dist\{0}-{1}" -f $mode, $BuildEnv)
if (-not (Test-Path $appBuildDir)) {
Write-Host (" Build output not found: {0}" -f $appBuildDir) -ForegroundColor Red
exit 1
}
$appTargetDir = Join-Path $deployDir $outputName
New-Item -ItemType Directory -Force -Path $appTargetDir | Out-Null
Copy-Item -Path (Join-Path $appBuildDir "*") -Destination $appTargetDir -Recurse -Force
Write-Host (" [app] {0}" -f $outputName) -ForegroundColor Green
}
# ============ Done ============
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " All Client Builds Done!" -ForegroundColor Cyan
Write-Host (" Output: {0}" -f $deployDir) -ForegroundColor Cyan
Write-Host " |- zdxt-sup-web" -ForegroundColor Cyan
Write-Host " |- zdxt-ent-app" -ForegroundColor Cyan
Write-Host " |- zdxt-enf-app" -ForegroundColor Cyan
5 months ago
Write-Host " |- zdxt-sup-app" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""