forked from raspberrypi/pico-setup-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.ps1
43 lines (33 loc) · 882 Bytes
/
common.ps1
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
#Requires -Version 7.2
function crawl {
param ([string]$url)
(Invoke-WebRequest $url -UseBasicParsing).Links |
Where-Object {
($_ | Get-Member href) -and
[uri]::IsWellFormedUriString($_.href, [System.UriKind]::RelativeOrAbsolute)
} |
ForEach-Object {
$href = [System.Net.WebUtility]::HtmlDecode($_.href)
try {
(New-Object System.Uri([uri]$url, $href)).AbsoluteUri
}
catch {
$href
}
}
}
function mkdirp {
param ([string] $dir, [switch] $clean)
New-Item -Path $dir -Type Directory -Force | Out-Null
if ($clean) {
Remove-Item -Path "$dir\*" -Recurse -Force
}
}
function exec {
param ([scriptblock]$private:cmd)
$global:LASTEXITCODE = 0
& $cmd
if ($LASTEXITCODE -ne 0) {
throw "Command '$cmd' exited with code $LASTEXITCODE"
}
}