-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-PSModuleClassesToExport.ps1
More file actions
40 lines (33 loc) · 1.46 KB
/
Get-PSModuleClassesToExport.ps1
File metadata and controls
40 lines (33 loc) · 1.46 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
function Get-PSModuleClassesToExport {
<#
.SYNOPSIS
Gets the classes to export from the module source code.
.DESCRIPTION
This function will get the classes to export from the module source code.
.EXAMPLE
Get-PSModuleClassesToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
Book
BookList
This will return the classes to export from the module source code.
.NOTES
Inspired by [about_Classes | Exporting classes with type accelerators](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-7.4#exporting-classes-with-type-accelerators)
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')]
[CmdletBinding()]
param (
# The path to the module root folder.
[Parameter(Mandatory)]
[string] $SourceFolderPath
)
$files = Get-ChildItem -Path $SourceFolderPath -Recurse -Include '*.ps1' | Sort-Object -Property FullName
foreach ($file in $files) {
$content = Get-Content -Path $file.FullName -Raw
$stringMatches = [Regex]::Matches($content, '(?i)^(class|enum)\s+([^\s{]+)', 'Multiline')
foreach ($match in $stringMatches) {
[pscustomobject]@{
Type = $match.Groups[1].Value
Name = $match.Groups[2].Value
}
}
}
}