-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClean-Project.ps1
More file actions
72 lines (63 loc) · 2.63 KB
/
Clean-Project.ps1
File metadata and controls
72 lines (63 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Clean-Project.ps1
# Removes all bin, obj, and publish directories across the solution to ensure a clean build state.
param(
[Parameter(Mandatory = $false)]
[switch]$IncludePublish = $false,
[Parameter(Mandatory = $false)]
[ValidateSet("all", "win-x64", "linux-x64")]
[string]$Platform = "all"
)
$ErrorActionPreference = "Continue"
Write-Host "Cleaning Swarm project..." -ForegroundColor Cyan
# Find and remove bin/obj directories
$directories = Get-ChildItem -Path . -Include bin, obj -Recurse -Directory
if ($directories.Count -eq 0) {
Write-Host "No build artifacts (bin/obj) found to clean." -ForegroundColor Green
}
else {
foreach ($dir in $directories) {
try {
Write-Host "Removing: $($dir.FullName)" -ForegroundColor Gray
Remove-Item -Path $dir.FullName -Recurse -Force
}
catch {
Write-Warning "Could not remove $($dir.FullName): $($_.Exception.Message)"
}
}
}
# Optionally clean publish directory
if ($IncludePublish) {
if ($Platform -eq "all" -and (Test-Path "publish")) {
Write-Host "Removing: entire publish directory" -ForegroundColor Gray
try {
Remove-Item -Path "publish" -Recurse -Force
Write-Host "Removed publish directory." -ForegroundColor Green
}
catch {
Write-Warning "Could not remove publish directory: $($_.Exception.Message)"
}
}
elseif ($Platform -ne "all") {
$PlatformDir = "publish/$Platform"
if (Test-Path $PlatformDir) {
Write-Host "Removing: $PlatformDir" -ForegroundColor Gray
try {
Remove-Item -Path $PlatformDir -Recurse -Force
Write-Host "Removed $Platform publish directory." -ForegroundColor Green
}
catch {
Write-Warning "Could not remove ${PlatformDir}: $($_.Exception.Message)"
}
}
else {
Write-Host "No publish directory for $Platform found." -ForegroundColor Yellow
}
}
}
Write-Host "Done cleaning build artifacts." -ForegroundColor Green
# Usage hints
Write-Host "`nUsage:" -ForegroundColor Yellow
Write-Host " .\Clean-Project.ps1 # Clean bin/obj only" -ForegroundColor Gray
Write-Host " .\Clean-Project.ps1 -IncludePublish # Clean bin/obj and all publish dirs" -ForegroundColor Gray
Write-Host " .\Clean-Project.ps1 -IncludePublish -Platform win-x64 # Clean bin/obj + win-x64 publish" -ForegroundColor Gray
Write-Host " .\Clean-Project.ps1 -IncludePublish -Platform linux-x64 # Clean bin/obj + linux-x64 publish" -ForegroundColor Gray