-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscripts_egsave.ps1
executable file
·59 lines (53 loc) · 1.67 KB
/
scripts_egsave.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/pwsh -nop
#Requires -PSEdition Core
<#
.SYNOPSIS
Generate example scripts from the current repository.
.EXAMPLE
./scripts_egsave.ps1
#>
begin {
$ErrorActionPreference = 'Stop'
# set location to workspace folder
Push-Location $PSScriptRoot
# check if the Invoke-ExampleScriptSave function is available, otherwise clone ps-modules repo
try {
Get-Command Invoke-ExampleScriptSave -CommandType Function | Out-Null
} catch {
$targetRepo = 'ps-modules'
# determine if target repository exists and clone if necessary
$getOrigin = { git config --get remote.origin.url }
try {
Push-Location "../$targetRepo"
if ((Invoke-Command $getOrigin) -match "github\.com[:/]szymonos/$targetRepo\b") {
# refresh target repository
git fetch --prune --quiet
git switch main --force --quiet
git reset --hard --quiet origin/main
} else {
Write-Warning "Another `"$targetRepo`" repository exists."
exit 1
}
Pop-Location
} catch {
$remote = (Invoke-Command $getOrigin) -replace '([:/]szymonos/)[\w-]+', "`$1$targetRepo"
# clone target repository
git clone $remote "../$targetRepo"
}
Import-Module -Name (Resolve-Path '../ps-modules/modules/do-common/do-common.psd1')
}
}
process {
# save example scripts
$folders = @(
'scripts/linux'
'scripts/macos'
'scripts/windows'
)
foreach ($folder in $folders) {
Invoke-ExampleScriptSave $folder -FolderFromBase
}
}
end {
Pop-Location
}