/
Clean.psm1
44 lines (39 loc) · 1.03 KB
/
Clean.psm1
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
Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"
[String]$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
Import-Module "$ScriptDir\Helper.psm1"
Import-Module "$ScriptDir\Configuration.psm1"
# -------------------------------------------------------------------------------------------------------------------------------------
function Clean
{
Param
(
[Parameter()][string[]] $OutputPaths,
[Parameter()][switch] $PauseOnError
)
Try
{
Write-Host -Foreground "Green" "Removing old build output..."
foreach($path in $OutputPaths)
{
if (Test-Path $path -PathType Container)
{
Write-Host -ForegroundColor "Green" "Removing everything under '$path'..."
Remove-Item "$path" -Recurse -ErrorAction Ignore
}
else
{
Write-Host -ForegroundColor "Green" "Specified '$path' is not a folder or not existing"
}
}
}
Catch [Exception]
{
# tell the caller it has all gone wrong
echo $_.Exception|format-list -force
if ($PauseOnError) {
Read-Host "Press ANY key..."
}
exit(-1)
}
}