-
Notifications
You must be signed in to change notification settings - Fork 2
/
scripts_egsave.ps1
executable file
·48 lines (45 loc) · 1.42 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
#!/usr/bin/pwsh -nop
<#
.SYNOPSIS
Generate example scripts from the current repository.
.EXAMPLE
./scripts_egsave.ps1
#>
$ErrorActionPreference = 'Stop'
# check if the Invoke-ExampleScriptSave function is available import it from the do-common module otherwise
try {
Get-Command Invoke-ExampleScriptSave -CommandType Function | Out-Null
} catch {
# determine if ps-modules repository exist and clone if necessary
$remote = (git config --get remote.origin.url).Replace('vagrant-scripts', 'ps-modules')
try {
Push-Location '../ps-modules' -ErrorAction Stop
if ($remote -match '\bszymonos/ps-modules\.git$') {
# refresh ps-modules repository
git fetch --prune --quiet
$targetBranch = if ((git branch --show-current) -eq 'dev') {
'dev'
} else {
'main'
}
git switch $targetBranch --force --quiet 2>$null
git reset --hard --quiet "origin/$targetBranch"
git clean --force -d
}
Pop-Location
} catch {
# clone ps-modules repository
git clone $remote ../ps-modules
}
Import-Module -Name (Resolve-Path '../ps-modules/modules/do-common/do-common.psd1')
}
# save example scripts
$folders = @(
'wsl'
'.assets/provision'
'.assets/scripts'
'.assets/tools'
)
foreach ($folder in $folders) {
Invoke-ExampleScriptSave $folder -FolderFromBase
}