Files
PartsInquiry/backend/scripts/package-backend.ps1
2025-10-08 19:15:20 +08:00

34 lines
1.2 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

param(
[string]$OutputPath,
[switch]$IncludeData
)
$ErrorActionPreference = 'Stop'
$BackendRoot = Resolve-Path (Join-Path $PSScriptRoot '..')
$Time = Get-Date -Format 'yyyyMMddHHmmss'
if (-not $OutputPath) {
$OutputPath = Join-Path $BackendRoot ("backend_source_$Time.zip")
}
$Staging = Join-Path $env:TEMP ("backend_source_$Time")
if (Test-Path $Staging) { Remove-Item -Recurse -Force $Staging }
New-Item -ItemType Directory -Path $Staging | Out-Null
# 构建 Robocopy 排除目录/文件列表
$excludeDirs = @('target','dist','node_modules','.git','.idea','.vscode','txm\__pycache__','txm\venv','txm\.venv','txm\debug_out','logs')
if (-not $IncludeData) { $excludeDirs += 'data' }
$excludeFiles = @('*.log','*.jar','*.iml','*.pyc','run.log','backend_source_*.zip')
# 复制源码到临时目录(保留 .mvn 以支持 mvnw
robocopy $BackendRoot $Staging /MIR /NFL /NDL /NJH /NJS /R:1 /W:1 /XD $excludeDirs /XF $excludeFiles | Out-Null
if (Test-Path $OutputPath) { Remove-Item -Force $OutputPath }
Compress-Archive -Path (Join-Path $Staging '*') -DestinationPath $OutputPath -Force
Write-Host "Created: $OutputPath"
# 清理临时目录
Remove-Item -Recurse -Force $Staging