Operating system: Windows 10 1809
PowerShell version: v5.7.180
32 or 64 bit OS: 64-bit
As I start working with Pester, I am trying to adopt a new module structure where:
- Each function resides in an individual .ps1 file in .\Functions\Public or .\Functions\Private.
- The .psm1 file has a generic process that dot sources each of the public and private functions and exports the public functions (see below).
- The Pester tests will either reside at .\Tests or .\Functions\Public\Tests or .\Functions\Private\Tests (I haven’t decided yet). They will also likely be broken into Unit and Integration folders, but again, that's not decided yet.
Code: Select all
$PublicFunctions = @(Get-ChildItem -Path $PSScriptRoot\Functions\Public\*.ps1 -ErrorAction SilentlyContinue)
$PrivateFunctions = @(Get-ChildItem -Path $PSScriptRoot\Functions\Private\*.ps1 -ErrorAction SilentlyContinue)
foreach ($ScriptGroup in @($PublicFunctions, $PrivateFunctions)) {
foreach ($ScriptFile in $ScriptGroup) {
Try {
Write-Debug "Importing $($ScriptFile.FullName)"
. $ScriptFile.FullName
}
Catch {
Write-Error -Message "Failed to import function $($_.ScriptFile.FullName)"
}
}
}
Export-ModuleMember -Function $PublicFunctions.Basename