$ErrorActionPreference = 'Stop' $ProjectRoot = 'D:\Idea Project\publish' $tmpDir = "$env:TEMP\publish_deploy_$((Get-Date).ToString('yyyyMMdd_HHmmss'))" Write-Host '=== 打包 publish_deploy.zip ===' -ForegroundColor Cyan # 1. 准备目录 New-Item -ItemType Directory -Path "$tmpDir\frontend" -Force | Out-Null # 2. 复制前端构建产物 Copy-Item "D:\Idea Project\publish\dist\index.html" "$tmpDir\frontend\" -Force Copy-Item "D:\Idea Project\publish\dist\assets" "$tmpDir\frontend\" -Recurse -Force Copy-Item "D:\Idea Project\publish\server.js" "$tmpDir\frontend\" -Force Write-Host ' [OK] 前端文件就位' -ForegroundColor Green # 3. 复制后端 jar(从 Maven build output) $jarPath = "D:\Idea Project\publish\target\daily-report-distribution-1.0.0.jar" if (-not (Test-Path $jarPath)) { Write-Host " [ERROR] Backend jar not found at $jarPath. Run 'mvnw.cmd package' first." -ForegroundColor Red exit 1 } Copy-Item $jarPath "$tmpDir\app.jar" -Force Write-Host ' [OK] 后端 jar 就位' -ForegroundColor Green # 4. 打包 $outputZip = "D:\Idea Project\publish\deploy\publish_deploy.zip" Compress-Archive -Path "$tmpDir\*" -DestinationPath $outputZip -Force $size = [math]::Round((Get-Item $outputZip).Length / 1MB, 1) Write-Host " [OK] 打包完成: $size MB" -ForegroundColor Green # 5. 清理 Remove-Item $tmpDir -Recurse -Force -ErrorAction SilentlyContinue Write-Host '' Write-Host '=== 完成 ===' -ForegroundColor Green Write-Host "文件位置: $outputZip"