# ============================================================ # OpenHIS 前端部署脚本 (Windows PowerShell) # 用法: .\deploy-frontend.ps1 [-Env prod|test|staging|dev] # ============================================================ param( [ValidateSet("prod","test","staging","dev")] [string]$Env = "prod" ) $ErrorActionPreference = "Stop" $ProjectDir = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path) $UiDir = "$ProjectDir\openhis-ui-vue3" $DistDir = "$UiDir\dist" Write-Host "==========================================" -ForegroundColor Cyan Write-Host " OpenHIS 前端部署" -ForegroundColor Cyan Write-Host " 环境: $Env" -ForegroundColor Cyan Write-Host " 目录: $UiDir" -ForegroundColor Cyan Write-Host "==========================================" -ForegroundColor Cyan # ---------- 1. 环境检查 ---------- Write-Host "`n[1/5] 环境检查..." -ForegroundColor Yellow try { $nodeVer = node -v } catch { Write-Host "错误: 未找到 node" -ForegroundColor Red; exit 1 } try { $npmVer = npm -v } catch { Write-Host "错误: 未找到 npm" -ForegroundColor Red; exit 1 } $nodeMajor = [int]($nodeVer -replace 'v','' -split '\.')[0] if ($nodeMajor -lt 18) { Write-Host "错误: Node.js >= 18,当前 $nodeVer" -ForegroundColor Red exit 1 } Write-Host " Node.js: $nodeVer ✓" Write-Host " npm: $npmVer ✓" # ---------- 2. 安装依赖 ---------- Write-Host "`n[2/5] 安装依赖..." -ForegroundColor Yellow Set-Location $UiDir npm install --legacy-peer-deps Write-Host " 依赖安装完成 ✓" -ForegroundColor Green # ---------- 3. 构建 ---------- Write-Host "`n[3/5] 构建 ($Env)..." -ForegroundColor Yellow npm run "build:$Env" Write-Host " 构建完成 ✓" -ForegroundColor Green # ---------- 4. 产物信息 ---------- Write-Host "`n[4/5] 构建产物:" -ForegroundColor Yellow $totalSize = (Get-ChildItem $DistDir -Recurse -File | Measure-Object -Property Length -Sum).Sum $fileCount = (Get-ChildItem $DistDir -Recurse -File).Count Write-Host " 路径: $DistDir" Write-Host " 大小: $([math]::Round($totalSize/1MB, 2)) MB" Write-Host " 文件: $fileCount 个" # ---------- 5. 部署提示 ---------- Write-Host "`n[5/5] 后续操作:" -ForegroundColor Yellow Write-Host "" Write-Host " 将 $DistDir 目录内容上传到服务器 Nginx 根目录" Write-Host " 然后在服务器执行: nginx -s reload" Write-Host "" Write-Host "==========================================" -ForegroundColor Cyan Write-Host " 构建完成!" -ForegroundColor Green Write-Host "==========================================" -ForegroundColor Cyan