Files
ykxmz/_build/clean_build_artifacts.ps1

78 lines
2.7 KiB
PowerShell

# 清掉误入仓库的构建产物 + 更新 .gitignore
$ErrorActionPreference = "Continue"
$git = "C:\Program Files\Git\bin\git.exe"
$root = "C:\Users\shu\Desktop\deepseekagent\LanRemote"
Set-Location $root
Write-Host "===== 1. 补充 .gitignore =====" -ForegroundColor Cyan
$extra = @'
# ---- PyInstaller 中间产物 ----
/_build/pyinstaller_work/
/_build/*.spec
# ---- Android 构建中间件 ----
/android/build/
/android/gen/
/android/bin/
/android/*.keystore
/android/*.jks
# ---- 其它构建产物 ----
*.pyz
*.toc
*.pkg
'@
$ignorePath = Join-Path $root ".gitignore"
$current = if (Test-Path $ignorePath) { [System.IO.File]::ReadAllText($ignorePath) } else { "" }
if ($current -notmatch "pyinstaller_work") {
[System.IO.File]::WriteAllText($ignorePath, $current + $extra, (New-Object System.Text.UTF8Encoding $false))
Write-Host " 已补充 .gitignore"
} else {
Write-Host " 已包含"
}
Write-Host ""
Write-Host "===== 2. 从索引里移除构建产物 =====" -ForegroundColor Cyan
$targets = @("_build/pyinstaller_work", "android/build", "android/gen", "android/bin")
foreach ($t in $targets) {
& $git rm -r --cached $t -q 2>&1 | Out-Null
Write-Host " 移除 $t"
}
Write-Host ""
Write-Host "===== 3. 重新暂存并检查 =====" -ForegroundColor Cyan
& $git add -A 2>&1 | Out-Null
$files = @(& $git -c core.quotepath=false diff --cached --name-only |
Where-Object { $_ -and $_.Trim() -ne "" })
Write-Host " 待提交: $($files.Count) 个"
$files | ForEach-Object { Write-Host " $_" }
Write-Host ""
Write-Host "===== 4. 确认大文件清理干净 =====" -ForegroundColor Cyan
$big = foreach ($f in $files) {
$p = Join-Path $root ($f -replace '/','\')
if (Test-Path -LiteralPath $p -PathType Leaf) {
$len = (Get-Item -LiteralPath $p).Length
if ($len -gt 500KB) { [pscustomobject]@{ Name = $f; MB = [math]::Round($len/1MB,2) } }
}
}
if ($big) { $big | ForEach-Object { Write-Host " ⚠ $($_.MB) MB $($_.Name)" -ForegroundColor Yellow } }
else { Write-Host " ✓ 没有超过 500KB 的文件" -ForegroundColor Green }
Write-Host ""
Write-Host "===== 5. 提交 =====" -ForegroundColor Cyan
& $git commit -q -m "chore: 排除 PyInstaller / Android 构建中间产物" 2>&1 | ForEach-Object { Write-Host " $_" }
& $git log --oneline 2>&1 | Select-Object -First 2 | ForEach-Object { Write-Host " $_" }
Write-Host ""
Write-Host "===== 6. 仓库最终规模 =====" -ForegroundColor Cyan
$all = & $git ls-files 2>$null
$total = 0
foreach ($f in $all) {
$p = Join-Path $root ($f -replace '/','\')
if (Test-Path -LiteralPath $p -PathType Leaf) { $total += (Get-Item -LiteralPath $p).Length }
}
Write-Host " 文件数: $(($all | Measure-Object).Count)"
Write-Host " 合计: $([math]::Round($total/1MB,2)) MB"