forked from dfinke/NameIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NameIT.psm1
78 lines (68 loc) · 1.8 KB
/
NameIT.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
$Script:ModuleBase = $PSScriptRoot
$Subs = @(
@{
Path = 'Classes'
Export = $false
Recurse = $false
Filter = '*.Class.ps1'
Exclude = @(
'*.Tests.ps1'
)
} ,
@{
Path = 'Private'
Export = $false
Recurse = $true
Filter = '*-*.ps1'
Exclude = @(
'*.Tests.ps1'
)
} ,
@{
Path = 'Public'
Export = $false # we use static exports for discovery
Recurse = $false
Filter = '*-*.ps1'
Exclude = @(
'*.Tests.ps1'
)
} ,
@{
Path = 'Generators'
Export = $false
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 = $ModuleBase | 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
}
}
}
Set-Alias -Name 'ig' -Value Invoke-Generate
## Explicit Export for module auto-loading
Export-ModuleMember -Alias @(
'ig'
) -Function @(
'Invoke-Generate'
, 'New-NameItTemplate'
)