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