-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-PSModuleFunctionsToExport.ps1
More file actions
46 lines (40 loc) · 2.01 KB
/
Get-PSModuleFunctionsToExport.ps1
File metadata and controls
46 lines (40 loc) · 2.01 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
function Get-PSModuleFunctionsToExport {
<#
.SYNOPSIS
Gets the functions to export from the module manifest.
.DESCRIPTION
This function will get the functions to export from the module manifest.
.EXAMPLE
Get-PSModuleFunctionsToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')]
[OutputType([array])]
param(
# Path to the folder where the module source code is located.
[Parameter(Mandatory)]
[string] $SourceFolderPath
)
$manifestPropertyName = 'FunctionsToExport'
Write-Host "[$manifestPropertyName]"
Write-Host "[$manifestPropertyName] - Checking path for functions and filters"
$publicFolderPath = Join-Path -Path $SourceFolderPath -ChildPath 'functions/public'
if (-not (Test-Path -Path $publicFolderPath -PathType Container)) {
Write-Host "[$manifestPropertyName] - [Folder not found] - [$publicFolderPath]"
return $functionsToExport
}
Write-Host "[$manifestPropertyName] - [$publicFolderPath]"
$functionsToExport = [Collections.Generic.List[string]]::new()
$scriptFiles = Get-ChildItem -Path $publicFolderPath -Recurse -File -ErrorAction SilentlyContinue -Include '*.ps1'
Write-Host "[$manifestPropertyName] - [$($scriptFiles.Count)]"
foreach ($file in $scriptFiles) {
$fileContent = Get-Content -Path $file.FullName -Raw
$containsFunction = ($fileContent -match 'function ') -or ($fileContent -match 'filter ')
Write-Host "[$manifestPropertyName] - [$($file.BaseName)] - [$containsFunction]"
if ($containsFunction) {
$functionsToExport.Add($file.BaseName)
}
}
[array]$functionsToExport
}