@@ -57,11 +57,20 @@ function Build-PSModuleRootModule {
5757 if ($classes.count -gt 0 ) {
5858 $classExports = @'
5959# Define the types to export with type accelerators.
60- $ExportableTypes = @(
60+ $ExportableClasses = @(
6161
6262'@
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 "
6574 }
6675
6776 $classExports += @'
@@ -73,17 +82,27 @@ $TypeAcceleratorsClass = [psobject].Assembly.GetType(
7382# Ensure none of the types would clobber an existing type accelerator.
7483# If a type accelerator with the same name exists, throw an exception.
7584$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) {
7794 if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
78- Write-Debug "Accelerator already exists [$($Type.FullName)]"
95+ Write-Warning "Class already exists [$($Type.FullName)]. Skipping. "
7996 } else {
8097 $TypeAcceleratorsClass::Add($Type.FullName, $Type)
98+ Write-Verbose "Exporting class '$Type'."
8199 }
82100}
83101
102+
84103# Remove type accelerators when the module is removed.
85104$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
86- foreach ($Type in $ExportableTypes ) {
105+ foreach ($Type in ($ExportableEnums + $ExportableClasses) ) {
87106 $TypeAcceleratorsClass::Remove($Type.FullName)
88107 }
89108}.GetNewClosure()
@@ -115,11 +134,11 @@ param()
115134 # endregion - Module header
116135
117136 # 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"
121140
122- ' @
141+ " @
123142 # endregion - Module post-header
124143
125144 # region - Data and variables
@@ -131,9 +150,9 @@ Write-Verbose "[$scriptName] - [data] - Processing folder"
131150$dataFolder = (Join-Path $PSScriptRoot 'data')
132151Write-Verbose "[$scriptName] - [data] - [$dataFolder]"
133152Get-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"
135154 New-Variable -Name $_.BaseName -Value (Import-PowerShellDataFile -Path $_.FullName) -Force
136- Write-Verbose "[$scriptName] - [data] - [$($_.Name )] - Done"
155+ Write-Verbose "[$scriptName] - [data] - [$($_.BaseName )] - Done"
137156}
138157
139158Write-Verbose "[$scriptName] - [data] - Done"
@@ -165,6 +184,7 @@ Write-Verbose "[$scriptName] - [data] - Done"
165184 $files = $ModuleOutputFolder | Get-ChildItem - File - Force - Filter ' *.ps1'
166185 foreach ($file in $files ) {
167186 $relativePath = $file.FullName -Replace $ModuleOutputFolder , ' '
187+ $relativePath = $relativePath -Replace $file.Extension , ' '
168188 $relativePath = $relativePath.TrimStart ($pathSeparator )
169189 $relativePath = $relativePath -Split $pathSeparator | ForEach-Object { " [$_ ]" }
170190 $relativePath = $relativePath -Join ' - '
0 commit comments