Apprxr.psm1


$debugLogPath = Join-Path $env:TEMP "apprxr_$PID.txt"
$debugLogDir = Split-Path $debugLogPath -Parent
if (-not (Test-Path $debugLogDir)) {
    New-Item -ItemType Directory -Path $debugLogDir -Force | Out-Null
}
Get-Date >> $debugLogPath
$directorySeparator = [System.IO.Path]::DirectorySeparatorChar
$moduleName = $PSScriptRoot.Split($directorySeparator)[-2]
$moduleName >> $debugLogPath
$moduleManifest = $PSScriptRoot + $directorySeparator + $moduleName + '.psd1'
$moduleManifest >> $debugLogPath

$publicFunctionsPath = $PSScriptRoot + $directorySeparator + 'Public' + $directorySeparator + 'ps1'
$publicFunctionsPath >> $debugLogPath
$privateFunctionsPath = $PSScriptRoot + $directorySeparator + 'Private' + $directorySeparator + 'ps1'
$privateFunctionsPath >> $debugLogPath
$classesPath =  $PSScriptRoot + $directorySeparator + 'Classes' + $directorySeparator + 'ps1'
$classesPath >> $debugLogPath
$currentManifest = Test-ModuleManifest $moduleManifest

$currentManifest >> $debugLogPath


$aliases = @()
$publicFunctions = Get-ChildItem -Path $publicFunctionsPath -Recurse| Where-Object {$_.Extension -eq '.ps1'}
$privateFunctions = Get-ChildItem -Path $privateFunctionsPath -Recurse| Where-Object {$_.Extension -eq '.ps1'}


"Public Functions:" >> $debugLogPath
$publicFunctions >> $debugLogPath
"Private Functions:" >> $debugLogPath

$privateFunctions >> $debugLogPath
$publicFunctions | ForEach-Object { . $_.FullName }
$privateFunctions | ForEach-Object { . $_.FullName }
#$classes | ForEach-Object { . $_.FullName }

$publicFunctions | ForEach-Object { # Export all of the public functions from this module

    # The command has already been sourced in above. Query any defined aliases.
    $alias = Get-Alias -Definition $_.BaseName -ErrorAction SilentlyContinue
    if ($alias) {
        $aliases += $alias
        Export-ModuleMember -Function $_.BaseName -Alias $alias
    }
    else {
        Export-ModuleMember -Function $_.BaseName
    }

}


$LogManagement = Install-ApprxrLogging


"Log management installed." >> $debugLogPath
# Notify users about help commands
Write-Host "[INFO] Use Get-ApprxrInstallationHelp for more information and usage instructions." -ForegroundColor Green
Write-Host "[INFO] Use Get-ApprxrHelp <Command-Name> -Full for detailed help on specific commands." -ForegroundColor Green

"Ready to start" >> $debugLogPath