1- $script :PSModuleRoot = $PSScriptRoot
2- $script :PSModuleVersion = " 0.9.25.107"
3-
4- function Import-ModuleFile
5- {
6- [CmdletBinding ()]
7- Param (
8- [string ]
9- $Path
10- )
11-
12- if ($doDotSource ) { . $Path }
13- else { $ExecutionContext.InvokeCommand.InvokeScript ($false , ([scriptblock ]::Create([io.file ]::ReadAllText($Path ))), $null , $null ) }
14- }
15-
16- # Declare directory separating character for X-Plat compatibility
17- $script :dc = [System.IO.Path ]::DirectorySeparatorChar
1+ $script :ModuleRoot = $PSScriptRoot
2+ $script :ModuleVersion = " 0.10.27.135"
183
194# Detect whether at some level dotsourcing was enforced
205$script :doDotSource = $false
@@ -25,26 +10,84 @@ if (($PSVersionTable.PSVersion.Major -lt 6) -or ($PSVersionTable.OS -like "*Wind
2510 if ((Get-ItemProperty - Path " HKCU:\SOFTWARE\Microsoft\WindowsPowerShell\PSFramework\System" - Name " DoDotSource" - ErrorAction Ignore).DoDotSource) { $script :doDotSource = $true }
2611}
2712
28- # Execute Preimport actions
29- . Import-ModuleFile - Path " $ ( $PSModuleRoot ) $ ( $dc ) internal$ ( $dc ) scripts$ ( $dc ) preimport.ps1"
13+ <#
14+ Note on Resolve-Path:
15+ All paths are sent through Resolve-Path in order to convert them to the correct path separator.
16+ This allows ignoring path separators throughout the import sequence, which could otherwise cause trouble depending on OS.
17+ #>
3018
31- # Import all internal functions
32- foreach ($function in (Get-ChildItem " $ ( $PSModuleRoot ) $ ( $dc ) internal$ ( $dc ) functions$ ( $dc ) *$ ( $dc ) *.ps1" ))
19+ # Detect whether at some level loading individual module files, rather than the compiled module was enforced
20+ $importIndividualFiles = $false
21+ if ($PSFramework_importIndividualFiles ) { $importIndividualFiles = $true }
22+ if (($PSVersionTable.PSVersion.Major -lt 6 ) -or ($PSVersionTable.OS -like " *Windows*" ))
3323{
34- . Import-ModuleFile - Path $function.FullName
24+ if ((Get-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\WindowsPowerShell\PSFramework\System" - Name " ImportIndividualFiles" - ErrorAction Ignore).ImportIndividualFiles) { $script :doDotSource = $true }
25+ if ((Get-ItemProperty - Path " HKCU:\SOFTWARE\Microsoft\WindowsPowerShell\PSFramework\System" - Name " ImportIndividualFiles" - ErrorAction Ignore).ImportIndividualFiles) { $script :doDotSource = $true }
3526}
36-
37- # Import all public functions
38- foreach ($function in (Get-ChildItem " $ ( $PSModuleRoot ) $ ( $dc ) functions$ ( $dc ) *$ ( $dc ) *.ps1" ))
27+ if (Test-Path (Join-Path (Resolve-Path - Path " $ ( $script :ModuleRoot ) \.." ) ' .git' )) { $importIndividualFiles = $true }
28+ if (-not (Test-Path (Join-Path $script :ModuleRoot " commands.ps1" ))) { $importIndividualFiles = $true }
29+
30+ function Import-ModuleFile
3931{
40- . Import-ModuleFile - Path $function.FullName
32+ <#
33+ . SYNOPSIS
34+ Loads files into the module on module import.
35+
36+ . DESCRIPTION
37+ This helper function is used during module initialization.
38+ It should always be dotsourced itself, in order to proper function.
39+
40+ This provides a central location to react to files being imported, if later desired
41+
42+ . PARAMETER Path
43+ The path to the file to load
44+
45+ . EXAMPLE
46+ PS C:\> . Import-ModuleFile -File $function.FullName
47+
48+ Imports the file stored in $function according to import policy
49+ #>
50+ [CmdletBinding ()]
51+ Param (
52+ [string ]
53+ $Path
54+ )
55+
56+ if ($doDotSource ) { . (Resolve-Path $Path ) }
57+ else { $ExecutionContext.InvokeCommand.InvokeScript ($false , ([scriptblock ]::Create([io.file ]::ReadAllText((Resolve-Path $Path )))), $null , $null ) }
4158}
4259
43-
44- # Execute Postimport actions
45- . Import-ModuleFile - Path " $ ( $PSModuleRoot ) $ ( $dc ) internal$ ( $dc ) scripts$ ( $dc ) postimport.ps1"
46-
47- if ($PSCommandPath -like " *psframework.psm1*" )
60+ if ($importIndividualFiles )
4861{
49- Import-Module " $ ( $PSModuleRoot ) $ ( $dc ) bin$ ( $dc ) PSFramework.dll"
62+ # Execute Preimport actions
63+ . Import-ModuleFile - Path " $ ( $script :ModuleRoot ) \internal\scripts\preimport.ps1"
64+
65+ # Import all internal functions
66+ foreach ($function in (Get-ChildItem " $ ( $script :ModuleRoot ) \internal\functions" - Filter " *.ps1" - Recurse - ErrorAction Ignore))
67+ {
68+ . Import-ModuleFile - Path $function.FullName
69+ }
70+
71+ # Import all public functions
72+ foreach ($function in (Get-ChildItem " $ ( $script :ModuleRoot ) \functions" - Filter " *.ps1" - Recurse - ErrorAction Ignore))
73+ {
74+ . Import-ModuleFile - Path $function.FullName
75+ }
76+
77+ # Execute Postimport actions
78+ . Import-ModuleFile - Path " $ ( $script :ModuleRoot ) \internal\scripts\postimport.ps1"
79+ }
80+ else
81+ {
82+ if (Test-Path (Join-Path $script :ModuleRoot " resourcesBefore.ps1" ))
83+ {
84+ . Import-ModuleFile - Path " $ ( $script :ModuleRoot ) \resourcesBefore.ps1"
85+ }
86+
87+ . Import-ModuleFile - Path " $ ( $script :ModuleRoot ) \commands.ps1"
88+
89+ if (Test-Path (Join-Path $script :ModuleRoot " resourcesAfter.ps1" ))
90+ {
91+ . Import-ModuleFile - Path " $ ( $script :ModuleRoot ) \resourcesAfter.ps1"
92+ }
5093}
0 commit comments