Aetheria/tools/clean-ignored-worktree.ps1

181 lines
4.7 KiB
PowerShell
Raw Normal View History

2026-06-21 11:14:21 +01:00
param(
[switch]$CleanBuild,
[switch]$CleanDaemonGenerated,
2026-06-21 14:05:53 +01:00
[switch]$CleanMaterializedState,
2026-06-21 11:14:21 +01:00
[switch]$CleanUnityCache,
[switch]$CleanWwiseGenerated,
[switch]$IncludeAgentState,
[switch]$Apply
)
$ErrorActionPreference = "Stop"
function Invoke-GitClean {
param(
[string]$Label,
[string[]]$Paths
)
2026-06-21 14:05:53 +01:00
$resolvedPaths = foreach ($path in $Paths) {
if ([System.Management.Automation.WildcardPattern]::ContainsWildcardCharacters($path)) {
Get-ChildItem -Path $path -Force -ErrorAction SilentlyContinue |
ForEach-Object { $_.FullName }
continue
}
if (Test-Path -LiteralPath $path) {
(Resolve-Path -LiteralPath $path).Path
}
}
$relativePaths = $resolvedPaths |
Where-Object { -not [string]::IsNullOrWhiteSpace($_) } |
Sort-Object -Unique |
ForEach-Object { Resolve-Path -LiteralPath $_ -Relative }
if ($relativePaths.Count -eq 0) {
2026-06-21 11:14:21 +01:00
return
}
Write-Host ""
Write-Host "== $Label =="
$mode = if ($Apply) { "-fdX" } else { "-ndX" }
2026-06-21 14:05:53 +01:00
& git clean $mode -- $relativePaths
2026-06-21 11:14:21 +01:00
}
function Get-PathSizeMb {
param([string]$Path)
if (-not (Test-Path -LiteralPath $Path)) {
return $null
}
$size = (Get-ChildItem -LiteralPath $Path -Recurse -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum).Sum
[PSCustomObject]@{
Path = $Path
MB = [math]::Round(($size / 1MB), 2)
}
}
function Show-Summary {
$ignoredCount = (& git ls-files -i -o --exclude-standard | Measure-Object).Count
Write-Host "Ignored path count: $ignoredCount"
$roots = @(
"Library",
"Temp",
"GameData",
"Aetheria-Economy_WwiseProject",
"Aetheria.State\bin",
"Aetheria.State\obj",
"Aetheria.State.Verify\bin",
"Aetheria.State.Verify\obj",
"Aetheria.State.Unity\bin",
"Aetheria.State.Unity\obj",
"obj",
".brokkr",
".codex",
".idea",
"UserSettings"
)
$sizes = foreach ($root in $roots) {
Get-PathSizeMb $root
}
$sizes |
Where-Object { $null -ne $_ } |
Sort-Object MB -Descending |
Format-Table -AutoSize
}
$anyCleanSwitch =
$CleanBuild -or
$CleanDaemonGenerated -or
2026-06-21 14:05:53 +01:00
$CleanMaterializedState -or
2026-06-21 11:14:21 +01:00
$CleanUnityCache -or
$CleanWwiseGenerated -or
$IncludeAgentState
if (-not $anyCleanSwitch) {
Show-Summary
Write-Host ""
Write-Host "Dry-run examples:"
Write-Host " tools\clean-ignored-worktree.ps1 -CleanBuild"
Write-Host " tools\clean-ignored-worktree.ps1 -CleanDaemonGenerated"
2026-06-21 14:05:53 +01:00
Write-Host " tools\clean-ignored-worktree.ps1 -CleanMaterializedState"
2026-06-21 11:14:21 +01:00
Write-Host " tools\clean-ignored-worktree.ps1 -CleanUnityCache"
Write-Host ""
Write-Host "Add -Apply to actually delete the selected ignored paths."
exit 0
}
if ($CleanBuild) {
Invoke-GitClean "Build and generated IDE files" @(
"Aetheria.State/bin",
"Aetheria.State/obj",
"Aetheria.State.Daemon/bin",
"Aetheria.State.Daemon/obj",
"Aetheria.State.Import/bin",
"Aetheria.State.Import/obj",
"Aetheria.State.Replica/bin",
"Aetheria.State.Replica/obj",
"Aetheria.State.Smoke/bin",
"Aetheria.State.Smoke/obj",
"Aetheria.State.Unity/bin",
"Aetheria.State.Unity/obj",
"Aetheria.State.Unity.Smoke/bin",
"Aetheria.State.Unity.Smoke/obj",
"Aetheria.State.Verify/bin",
"Aetheria.State.Verify/obj",
"Economy.Server/bin",
"Economy.Server/obj",
"Economy.Shared/bin",
"Economy.Shared/obj",
"obj"
)
}
if ($CleanDaemonGenerated) {
2026-06-21 14:05:53 +01:00
Invoke-GitClean "Daemon generated scratch sidecars" @(
2026-06-21 11:14:21 +01:00
"GameData/*.cc.daemon.*.cc",
"GameData/*.cc.eve.pending",
"GameData/*.cc.before-*"
)
}
2026-06-21 14:05:53 +01:00
if ($CleanMaterializedState) {
Invoke-GitClean "Materialized typed state backing store" @(
"GameData/*.cc.records",
"GameData/*.cc.records.*",
"GameData/*.cultmesh"
)
}
2026-06-21 11:14:21 +01:00
if ($CleanUnityCache) {
Invoke-GitClean "Unity transient cache" @(
"Library",
"Temp",
"UserSettings"
)
}
if ($CleanWwiseGenerated) {
Invoke-GitClean "Wwise generated/cache/profiling files" @(
"Aetheria-Economy_WwiseProject/.cache",
"Aetheria-Economy_WwiseProject/GeneratedSoundBanks",
"Aetheria-Economy_WwiseProject/*.prof",
"Assets/StreamingAssets/Audio/GeneratedSoundBanks"
)
}
if ($IncludeAgentState) {
Invoke-GitClean "Local agent/editor runtime state" @(
".brokkr",
".codex",
".idea"
)
}