-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
UpdateManifest.ps1
51 lines (41 loc) · 1.61 KB
/
UpdateManifest.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
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, Position = 0)]
[System.IO.DirectoryInfo]
[string]
$ModulePath
)
function GetFunctionAliases ($functions) {
$aliases = @()
foreach ($function in $functions) {
$definition = (Get-Command $function).Definition.Split("`n")
$paramStartLine = ($definition | Select-String -Pattern "^\s*[Pp]aram").LineNumber
$aliases += ($definition | Select-String -Pattern "(?<!#\s*)\[Alias\([\""|'](\w+)[\""|']\)\]" | Where-Object LineNumber -LT $paramStartLine).Matches | ForEach-Object {if ($_.Groups.Count -gt 0) { $_.Groups[1].Value }}
}
return $aliases
}
if (-not (Test-Path $ModulePath)) {
Write-Error "Could not find module $ModulePath" -ErrorAction Stop
}
Push-Location $ModulePath
# Add all the functions this module uses into our scope
Get-ChildItem *.ps1 -Path Export,Private -Recurse | Foreach-Object {
. $_.FullName
}
$currentMetadata = Test-ModuleManifest -Path "$ModulePath.psd1"
$functionsToExport = Get-ChildItem *.ps1 -Path Export -Recurse | `
# Get the name of the function
Select-Object -ExpandProperty BaseName | `
Sort-Object
Update-ModuleManifest -Path "$ModulePath.psd1" `
-RootModule "$ModulePath.psm1" `
-FunctionsToExport $functionsToExport `
-AliasesToExport (GetFunctionAliases $functionsToExport)
Test-ModuleManifest -Path "$ModulePath.psd1"
# Remove the functions loaded during the manifest update
Get-ChildItem *.ps1 -Path Export,Private -Recurse | ForEach-Object {
Remove-Item -Path "Function:\$($_.BaseName)" -ErrorAction SilentlyContinue
Remove-Variable * -Scope Script -ErrorAction SilentlyContinue
}
Pop-Location