-
Notifications
You must be signed in to change notification settings - Fork 0
/
Idempotion.psm1
54 lines (49 loc) · 1.35 KB
/
Idempotion.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
45
46
47
48
49
50
51
52
53
54
$Subs = @(
@{
Path = 'Classes'
Export = $false
Recurse = $false
Filter = '*.Class.ps1'
Exclude = @(
'*.Tests.ps1'
)
} ,
@{
Path = 'Private'
Export = $false
Recurse = $false
Filter = '*-*.ps1'
Exclude = @(
'*.Tests.ps1'
)
} ,
@{
Path = 'Public'
Export = $true
Recurse = $false
Filter = '*-*.ps1'
Exclude = @(
'*.Tests.ps1'
)
}
)
$thisModule = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)
$varName = "__${thisModule}_Export_All"
$exportAll = Get-Variable -Scope Global -Name $varName -ValueOnly -ErrorAction Ignore
$Subs | ForEach-Object -Process {
$sub = $_
$thisDir = $PSScriptRoot | Join-Path -ChildPath $sub.Path | Join-Path -ChildPath '*'
$thisDir |
Get-ChildItem -Filter $sub.Filter -Exclude $sub.Exclude -Recurse:$sub.Recurse -ErrorAction Ignore | ForEach-Object -Process {
try {
$Unit = $_.FullName
. $Unit
if ($sub.Export -or $exportAll) {
Export-ModuleMember -Function $_.BaseName
}
} catch {
$e = "Could not import '$Unit' with exception: `n`n`n$($_.Exception)" -as $_.Exception.GetType()
throw $e
}
}
}