-
Notifications
You must be signed in to change notification settings - Fork 0
/
PkgStore.Vault.psm1
51 lines (42 loc) · 1.85 KB
/
PkgStore.Vault.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
$ModuleManifest = (Get-ChildItem -Path $PSScriptRoot | Where-Object { $_.Extension -eq '.psd1' })
$CurrentManifest = (Test-ModuleManifest $ModuleManifest)
$Aliases = @()
$PrivateFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') | Where-Object { $_.Extension -eq '.ps1' })
$PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') | Where-Object { $_.Extension -eq '.ps1' })
(@($PrivateFunctions) + @($PublicFunctions)) | ForEach-Object {
try {
Write-Verbose "Loading: '$($_.FullName)'."
. $_.FullName
} catch {
$_.Exception.Message | Write-Warning
}
}
@($PublicFunctions) | ForEach-Object {
$Alias = (Get-Alias -Definition $_.BaseName -ErrorAction 'SilentlyContinue')
if ($Alias) {
$Aliases += $Alias
Export-ModuleMember -Function $_.BaseName -Alias $Alias
} else {
Export-ModuleMember -Function $_.BaseName
}
}
$FunctionsAdded = ($PublicFunctions | Where-Object { $_.BaseName -notin $CurrentManifest.ExportedFunctions.Keys })
$FunctionsRemoved = ($CurrentManifest.ExportedFunctions.Keys | Where-Object { $_ -notin $PublicFunctions.BaseName })
$AliasesAdded = ($Aliases | Where-Object { $_ -notin $CurrentManifest.ExportedAliases.Keys })
$AliasesRemoved = ($CurrentManifest.ExportedAliases.Keys | Where-Object { $_ -notin $Aliases })
if ($FunctionsAdded -or $FunctionsRemoved -or $AliasesAdded -or $AliasesRemoved) {
try {
$UpdateModuleManifestParams = @{}
$UpdateModuleManifestParams.Add('Path', $ModuleManifest)
$UpdateModuleManifestParams.Add('ErrorAction', 'Stop')
if ($Aliases.Count -gt 0) {
$UpdateModuleManifestParams.Add('AliasesToExport', $Aliases)
}
if ($PublicFunctions.Count -gt 0) {
$UpdateModuleManifestParams.Add('FunctionsToExport', $PublicFunctions.BaseName)
}
Update-ModuleManifest @UpdateModuleManifestParams
} catch {
$_ | Write-Error
}
}