/
stackdb.psm1
42 lines (36 loc) · 1.23 KB
/
stackdb.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
$script:StackDbRoot = $PSScriptRoot
function Import-StackDbFile {
[cmdletbinding()]
param (
[string]$FilePath
)
if ($DoDotSource) {
. $FilePath
}
else {
$ExecutionContext.InvokeCommand.InvokeScript($false,([ScriptBlock]::Create([io.file]::ReadAllText($FilePath))), $null, $null)
}
}
#region DoDotSource
<# Detect if dot sourcing is enforced #>
$script:DoDotSource = $false
if ($stackdb_DotSourceModule) {
$script:DoDotSource = $true
}
if ( (Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\WindowsPowerShell\stackdb\System" -Name "DoDotSource" -ErrorAction Ignore).DoDotSource) {
$script:DoDotSource = $true
}
#endregion DoDotSource
# Execute Preimport actions
# . Import-StackDbFile -FilePath "$StackDbRoot\internal\scripts\preimport.ps1"
# Import all internal functions
# foreach ($function in (Get-ChildItem "$StackDbRoot\internal\functions\*.ps1")) {
# . Import-StackDbFile -FilePath $function.FullName
# }
# Import all public functions
foreach ($function in (Get-ChildItem "$StackDbRoot\functions\*.ps1")) {
$file = $function.FullName
. Import-StackDbFile -FilePath $file
}
# Execute Postimport actions
. Import-StackDbFile -FilePath "$StackDbRoot\internal\scripts\postimport.ps1"