@@ -12,34 +12,40 @@ function Build-PSModuleRootModule {
1212
1313 1. Module header from header.ps1 file. Usually to suppress code analysis warnings/errors and to add [CmdletBinding()] to the module.
1414 2. Data files are added from source files. These are also tracked based on visibility/exportability based on folder location:
15- 1. private
16- 2. public
15+ 1. private
16+ 2. public
1717 3. Combines *.ps1 files from the following folders in alphabetical order from each folder:
18- 1. init
19- 2. classes
20- 3. private
21- 4. public
22- 5. Any remaining *.ps1 on module root.
18+ 1. init
19+ 2. classes
20+ 3. private
21+ 4. public
22+ 5. Any remaining *.ps1 on module root.
2323 3. Export-ModuleMember by using the functions, cmdlets, variables and aliases found in the source files.
24- - `Functions` will only contain functions that are from the `public` folder.
25- - `Cmdlets` will only contain cmdlets that are from the `public` folder.
26- - `Variables` will only contain variables that are from the `public` folder.
27- - `Aliases` will only contain aliases that are from the functions from the `public` folder.
24+ - `Functions` will only contain functions that are from the `public` folder.
25+ - `Cmdlets` will only contain cmdlets that are from the `public` folder.
26+ - `Variables` will only contain variables that are from the `public` folder.
27+ - `Aliases` will only contain aliases that are from the functions from the `public` folder.
2828
2929 . EXAMPLE
3030 Build-PSModuleRootModule -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule'
3131 #>
3232 [CmdletBinding ()]
3333 param (
34+ # Name of the module.
35+ [Parameter (Mandatory )]
36+ [string ] $ModuleName ,
37+
3438 # Folder where the built modules are outputted. 'outputs/modules/MyModule'
3539 [Parameter (Mandatory )]
3640 [System.IO.DirectoryInfo ] $ModuleOutputFolder
3741 )
3842
43+ # Get the path separator for the current OS
44+ $pathSeparator = [System.IO.Path ]::DirectorySeparatorChar
45+
3946 # region Build root module
4047 Start-LogGroup ' Build root module'
41- $moduleName = Split-Path - Path $ModuleOutputFolder - Leaf
42- $rootModuleFile = New-Item - Path $ModuleOutputFolder - Name " $moduleName .psm1" - Force
48+ $rootModuleFile = New-Item - Path $ModuleOutputFolder - Name " $ModuleName .psm1" - Force
4349
4450 # region - Analyze source files
4551
@@ -158,16 +164,20 @@ Write-Verbose "[$scriptName] - [data] - Done"
158164 # region - Add content from *.ps1 files on module root
159165 $files = $ModuleOutputFolder | Get-ChildItem - File - Force - Filter ' *.ps1'
160166 foreach ($file in $files ) {
161- $relativePath = $file.FullName.Replace ($ModuleOutputFolder , ' ' ).TrimStart($pathSeparator )
167+ $relativePath = $file.FullName -Replace $ModuleOutputFolder , ' '
168+ $relativePath = $relativePath.TrimStart ($pathSeparator )
169+ $relativePath = $relativePath -Split $pathSeparator | ForEach-Object { " [$_ ]" }
170+ $relativePath = $relativePath -Join ' - '
171+
162172 Add-Content - Path $rootModuleFile - Force - Value @"
163173#region - From $relativePath
164- Write-Verbose "[`$ scriptName] - [ $relativePath ] - Importing"
174+ Write-Verbose "[`$ scriptName] - $relativePath - Importing"
165175
166176"@
167177 Get-Content - Path $file.FullName | Add-Content - Path $rootModuleFile - Force
168178
169179 Add-Content - Path $rootModuleFile - Force - Value @"
170- Write-Verbose "[`$ scriptName] - [ $relativePath ] - Done"
180+ Write-Verbose "[`$ scriptName] - $relativePath - Done"
171181#endregion - From $relativePath
172182
173183"@
@@ -213,7 +223,14 @@ Export-ModuleMember @exports
213223 Stop-LogGroup
214224 # endregion Format root module
215225
216- Start-LogGroup ' Build module - Result - File list'
226+ # region Validate root module
227+ Start-LogGroup ' Build root module - Validate - Import'
228+ Add-PSModulePath - Path (Split-Path - Path $ModuleOutputFolder - Parent)
229+ Import-PSModule - Path $ModuleOutputFolder - ModuleName $ModuleName
230+ Stop-LogGroup
231+
232+ Start-LogGroup ' Build root module - Validate - File list'
217233 (Get-ChildItem - Path $ModuleOutputFolder - Recurse - Force).FullName | Sort-Object
218234 Stop-LogGroup
235+ # endregion Validate root module
219236}
0 commit comments