Modules/businessdev.ALbuild.Core/Public/Get-ALbuildConfig.ps1
|
function Get-ALbuildConfig { <# .SYNOPSIS Returns the effective ALbuild machine/runtime configuration. .DESCRIPTION Machine-scoped tooling settings (cache folders, retry, telemetry, licensing) stored under the user's application-data folder - NOT the committed, per-workspace project settings (country, artifact type, test runner, ...), which are loaded with Get-ALbuildProjectConfig. Builds a [ALbuildConfig] instance by merging, in increasing precedence: 1. Built-in defaults (the ALbuildConfig constructor) 2. The persisted config file (if present) 3. In-memory overrides set with Set-ALbuildConfig The merged instance is cached for the session; use -Refresh to rebuild it (for example after editing the config file on disk). .PARAMETER Name Optional single setting name to return instead of the whole object. .PARAMETER Refresh Rebuilds the cached configuration from defaults + file + overrides. .EXAMPLE Get-ALbuildConfig .EXAMPLE Get-ALbuildConfig -Name ArtifactCacheFolder .OUTPUTS ALbuildConfig, or the requested setting value. #> [CmdletBinding()] param( [Parameter(Position = 0)] [string] $Name, [switch] $Refresh ) if ($Refresh -or -not $script:ALbuildConfig) { $config = [ALbuildConfig]::new() # Layer 2: persisted file (unknown keys ignored with a warning). $configPath = Get-ALbuildConfigPath if (Test-Path -LiteralPath $configPath) { try { $fileConfig = Get-Content -LiteralPath $configPath -Raw -Encoding UTF8 | ConvertFrom-Json $fileHash = @{} foreach ($property in $fileConfig.PSObject.Properties) { $fileHash[$property.Name] = $property.Value } $config.Apply($fileHash, $true) } catch { Write-Warning "ALbuild: ignoring invalid config file '$configPath': $($_.Exception.Message)" } } # Layer 3: in-memory overrides. if ($script:ALbuildConfigOverrides -and $script:ALbuildConfigOverrides.Count -gt 0) { $config.Apply($script:ALbuildConfigOverrides, $false) } $script:ALbuildConfig = $config } if ($PSBoundParameters.ContainsKey('Name')) { return $script:ALbuildConfig.Get($Name) } return $script:ALbuildConfig } |