@@ -57,11 +57,20 @@ function Build-PSModuleRootModule {
57
57
if ($classes.count -gt 0 ) {
58
58
$classExports = @'
59
59
# Define the types to export with type accelerators.
60
- $ExportableTypes = @(
60
+ $ExportableClasses = @(
61
61
62
62
'@
63
- $classes | ForEach-Object {
64
- $classExports += " [$_ ]`n "
63
+ $classes | Where-Object Type -EQ ' class' | ForEach-Object {
64
+ $classExports += " [$ ( $_.Name ) ]`n "
65
+ }
66
+
67
+ $classExports += @'
68
+ )
69
+ $ExportableEnums = @(
70
+
71
+ '@
72
+ $classes | Where-Object Type -EQ ' enum' | ForEach-Object {
73
+ $classExports += " [$ ( $_.Name ) ]`n "
65
74
}
66
75
67
76
$classExports += @'
@@ -73,17 +82,27 @@ $TypeAcceleratorsClass = [psobject].Assembly.GetType(
73
82
# Ensure none of the types would clobber an existing type accelerator.
74
83
# If a type accelerator with the same name exists, throw an exception.
75
84
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
76
- foreach ($Type in $ExportableTypes) {
85
+ foreach ($Type in $ExportableEnums) {
86
+ if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
87
+ Write-Warning "Enum already exists [$($Type.FullName)]. Skipping."
88
+ } else {
89
+ $TypeAcceleratorsClass::Add($Type.FullName, $Type)
90
+ Write-Verbose "Exporting enum '$Type'."
91
+ }
92
+ }
93
+ foreach ($Type in $ExportableClasses) {
77
94
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
78
- Write-Debug "Accelerator already exists [$($Type.FullName)]"
95
+ Write-Warning "Class already exists [$($Type.FullName)]. Skipping. "
79
96
} else {
80
97
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
98
+ Write-Verbose "Exporting class '$Type'."
81
99
}
82
100
}
83
101
102
+
84
103
# Remove type accelerators when the module is removed.
85
104
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
86
- foreach ($Type in $ExportableTypes ) {
105
+ foreach ($Type in ($ExportableEnums + $ExportableClasses) ) {
87
106
$TypeAcceleratorsClass::Remove($Type.FullName)
88
107
}
89
108
}.GetNewClosure()
@@ -115,11 +134,11 @@ param()
115
134
# endregion - Module header
116
135
117
136
# region - Module post-header
118
- Add-Content - Path $rootModuleFile - Force - Value @'
119
- $scriptName = $MyInvocation.MyCommand.Name
120
- Write-Verbose "[$scriptName] Importing module"
137
+ Add-Content - Path $rootModuleFile - Force - Value @"
138
+ ` $ scriptName = ' $ModuleName '
139
+ Write-Verbose "[` $ scriptName] - Importing module"
121
140
122
- ' @
141
+ " @
123
142
# endregion - Module post-header
124
143
125
144
# region - Data and variables
@@ -131,9 +150,9 @@ Write-Verbose "[$scriptName] - [data] - Processing folder"
131
150
$dataFolder = (Join-Path $PSScriptRoot 'data')
132
151
Write-Verbose "[$scriptName] - [data] - [$dataFolder]"
133
152
Get-ChildItem -Path "$dataFolder" -Recurse -Force -Include '*.psd1' -ErrorAction SilentlyContinue | ForEach-Object {
134
- Write-Verbose "[$scriptName] - [data] - [$($_.Name )] - Importing"
153
+ Write-Verbose "[$scriptName] - [data] - [$($_.BaseName )] - Importing"
135
154
New-Variable -Name $_.BaseName -Value (Import-PowerShellDataFile -Path $_.FullName) -Force
136
- Write-Verbose "[$scriptName] - [data] - [$($_.Name )] - Done"
155
+ Write-Verbose "[$scriptName] - [data] - [$($_.BaseName )] - Done"
137
156
}
138
157
139
158
Write-Verbose "[$scriptName] - [data] - Done"
@@ -165,6 +184,7 @@ Write-Verbose "[$scriptName] - [data] - Done"
165
184
$files = $ModuleOutputFolder | Get-ChildItem - File - Force - Filter ' *.ps1'
166
185
foreach ($file in $files ) {
167
186
$relativePath = $file.FullName -Replace $ModuleOutputFolder , ' '
187
+ $relativePath = $relativePath -Replace $file.Extension , ' '
168
188
$relativePath = $relativePath.TrimStart ($pathSeparator )
169
189
$relativePath = $relativePath -Split $pathSeparator | ForEach-Object { " [$_ ]" }
170
190
$relativePath = $relativePath -Join ' - '
0 commit comments