FredsIronScripter2018.psm1

$script:ModuleRoot = $PSScriptRoot
$script:PSModuleVersion = "1.2.0.10"

function Import-ModuleFile
{
    [CmdletBinding()]
    Param (
        [string]
        $Path
    )
    
    if ($doDotSource) { . $Path }
    else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($Path))), $null, $null) }
}

# Detect whether at some level dotsourcing was enforced
$script:doDotSource = $false
if ($FredsIronScripter2018_dotsourcemodule) { $script:doDotSource = $true }
if ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsPowerShell\FredsIronScripter2018\System" -Name "DoDotSource" -ErrorAction Ignore).DoDotSource) { $script:doDotSource = $true }
if ((Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\WindowsPowerShell\FredsIronScripter2018\System" -Name "DoDotSource" -ErrorAction Ignore).DoDotSource) { $script:doDotSource = $true }

# Execute Preimport actions
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\preimport.ps1"

# Import all internal functions
<#
foreach ($function in (Get-ChildItem "$ModuleRoot\internal\functions\*\*.ps1"))
{
    . Import-ModuleFile -Path $function.FullName
}
#>


# Import all public functions
foreach ($function in (Get-ChildItem "$ModuleRoot\functions\*\*.ps1"))
{
    . Import-ModuleFile -Path $function.FullName
}

# Execute Postimport actions
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\postimport.ps1"