1- # Perform Actions before loading the rest of the content
2- . " $PSScriptRoot \scripts\preload.ps1"
1+ $script :PSModuleDevelopmentModuleRoot = $PSScriptRoot
32
4- # region Load module content
3+ $script :doDotSource = $false
4+ if (Get-PSFConfigValue - Name PSModuleDevelopment.Import.DoDotSource) { $script :doDotSource = $true }
55
6- . " $PSScriptRoot \functions\Get-HelpEx.ps1"
7- . " $PSScriptRoot \functions\Get-ModuleDebug.ps1"
8- . " $PSScriptRoot \functions\Import-ModuleDebug.ps1"
9- . " $PSScriptRoot \functions\Measure-CommandEx.ps1"
10- . " $PSScriptRoot \functions\New-PssModuleProject.ps1"
11- . " $PSScriptRoot \functions\Remove-ModuleDebug.ps1"
12- . " $PSScriptRoot \functions\Restart-Shell.ps1"
13- . " $PSScriptRoot \functions\Set-ModuleDebug.ps1"
6+ # region Helper function
7+ function Import-PSMDFile
8+ {
9+ <#
10+ . SYNOPSIS
11+ Loads files into the module on module import.
12+
13+ . DESCRIPTION
14+ This helper function is used during module initialization.
15+ It should always be dotsourced itself, in order to proper function.
16+
17+ . PARAMETER Path
18+ The path to the file to load
19+
20+ . EXAMPLE
21+ PS C:\> . Import-PSMDFile -File $function.FullName
22+
23+ Imports the file stored in $function according to import policy
24+ #>
25+ [CmdletBinding ()]
26+ Param (
27+ [string ]
28+ $Path
29+ )
30+
31+ if ($script :doDotSource ) { . $Path }
32+ else { $ExecutionContext.InvokeCommand.InvokeScript ($false , ([scriptblock ]::Create([io.file ]::ReadAllText($Path ))), $null , $null ) }
33+ }
34+ # endregion Helper function
1435
15- # endregion Load module content
36+
37+ # Perform Actions before loading the rest of the content
38+ . Import-PSMDFile - Path " $PSModuleDevelopmentModuleRoot \scripts\preload.ps1"
39+
40+ # region Load functions
41+ foreach ($function in (Get-ChildItem " $PSModuleDevelopmentModuleRoot \functions" - Recurse - File - Filter " *.ps1" ))
42+ {
43+ . Import-PSMDFile - Path $function.FullName
44+ }
45+ # endregion Load functions
1646
1747# Perform Actions after loading the module contents
18- . " $PSScriptRoot \scripts\postload.ps1"
48+ . Import-PSMDFile - Path " $PSModuleDevelopmentModuleRoot \scripts\postload.ps1"
0 commit comments