Modules/businessdev.ALbuild.Core/businessdev.ALbuild.Core.psm1

#Requires -Version 5.1
Set-StrictMode -Version Latest

# Root loader for businessdev.ALbuild.Core.
# Dot-sources Classes -> Private -> Public (in that dependency order) and exports only the
# public functions. Keeping the loader data-driven means new files are picked up automatically
# while the manifest's FunctionsToExport remains the authoritative public surface.

$ErrorActionPreference = 'Stop'

$script:ModuleRoot = $PSScriptRoot

# Module-scoped state, initialised up front so reads are safe under Set-StrictMode.
$script:ALbuildConfig          = $null
$script:ALbuildConfigOverrides = @{}
$script:ALbuildLicenseCache         = @{}

foreach ($folder in 'Classes', 'Private', 'Public') {
    $path = Join-Path -Path $PSScriptRoot -ChildPath $folder
    if (-not (Test-Path -LiteralPath $path)) { continue }

    $files = Get-ChildItem -LiteralPath $path -Filter '*.ps1' -File -Recurse |
        Where-Object { $_.Name -notlike '*.Tests.ps1' } |
        Sort-Object FullName

    foreach ($file in $files) {
        try {
            . $file.FullName
        }
        catch {
            throw "ALbuild.Core: failed to load '$($file.FullName)': $($_.Exception.Message)"
        }
    }
}

# Export only functions defined under Public/. The manifest pins the same list for Gallery
# analysis; always calling Export-ModuleMember guards against leaking Private helpers.
$publicFunctions = @()
$publicPath = Join-Path -Path $PSScriptRoot -ChildPath 'Public'
if (Test-Path -LiteralPath $publicPath) {
    $publicFunctions = @(Get-ChildItem -LiteralPath $publicPath -Filter '*.ps1' -File -Recurse |
            Where-Object { $_.Name -notlike '*.Tests.ps1' } |
            ForEach-Object { [System.IO.Path]::GetFileNameWithoutExtension($_.Name) })
}
Export-ModuleMember -Function $publicFunctions