-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-PSModuleVariablesToExport.ps1
More file actions
50 lines (42 loc) · 1.74 KB
/
Get-PSModuleVariablesToExport.ps1
File metadata and controls
50 lines (42 loc) · 1.74 KB
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
function Get-PSModuleVariablesToExport {
<#
.SYNOPSIS
Gets the variables to export from the module manifest.
.DESCRIPTION
This function will get the variables to export from the module manifest.
.EXAMPLE
Get-PSModuleVariablesToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', '', Scope = 'Function',
Justification = 'Want to just write to the console, not the pipeline.'
)]
[OutputType([string])]
[OutputType([Collections.Generic.List[string]])]
[CmdletBinding()]
param(
# Path to the folder where the module source code is located.
[Parameter(Mandatory)]
[string] $SourceFolderPath
)
$manifestPropertyName = 'VariablesToExport'
Write-Host "[$manifestPropertyName]"
$variablesToExport = [Collections.Generic.List[string]]::new()
$variableFolderPath = Join-Path -Path $SourceFolderPath -ChildPath 'variables/public'
if (-not (Test-Path -Path $variableFolderPath -PathType Container)) {
Write-Host "[$manifestPropertyName] - [Folder not found] - [$variableFolderPath]"
return ''
}
$scriptFilePaths = Get-ChildItem -Path $variableFolderPath -Recurse -File -Filter *.ps1 | Select-Object -ExpandProperty FullName
$scriptFilePaths | ForEach-Object {
$ast = [System.Management.Automation.Language.Parser]::ParseFile($_, [ref]$null, [ref]$null)
$variables = Get-RootLevelVariable -Ast $ast
$variables | ForEach-Object {
$variablesToExport.Add($_)
}
}
$variablesToExport | ForEach-Object {
Write-Host "[$manifestPropertyName] - [$_]"
}
$variablesToExport
}