43 lines
1.3 KiB
PowerShell
43 lines
1.3 KiB
PowerShell
function Get-ConfigurationDataTemplateMergeFile {
|
|
[CmdletBinding()]
|
|
Param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]
|
|
$Path,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[hashtable]
|
|
$Visited = @{}
|
|
)
|
|
|
|
$ResolvedPath = Resolve-ConfigurationDataTemplatePath -Path $Path
|
|
|
|
if($Visited.ContainsKey($ResolvedPath)){
|
|
$Chain = @($Visited.Keys + $ResolvedPath) -join " -> "
|
|
throw "Circular configuration data template inheritance detected: $Chain"
|
|
}
|
|
|
|
$Visited[$ResolvedPath] = $true
|
|
|
|
$ConfigurationData = Import-PowerShellDataFile -Path $ResolvedPath
|
|
if($ConfigurationData -isnot [System.Collections.IDictionary]){
|
|
throw "Configuration data template [$ResolvedPath] must contain a hashtable."
|
|
}
|
|
|
|
$Files = @()
|
|
$BasePath = Split-Path -Path $ResolvedPath -Parent
|
|
foreach($ParentPath in @(Get-ConfigurationDataTemplateExtends -ConfigurationData $ConfigurationData)){
|
|
if([string]::IsNullOrWhiteSpace([string]$ParentPath)){
|
|
continue
|
|
}
|
|
|
|
$ResolvedParentPath = Resolve-ConfigurationDataTemplatePath -Path ([string]$ParentPath) -BasePath $BasePath
|
|
$Files += @(Get-ConfigurationDataTemplateMergeFile -Path $ResolvedParentPath -Visited $Visited)
|
|
}
|
|
|
|
$Files += $ResolvedPath
|
|
$Visited.Remove($ResolvedPath)
|
|
|
|
return @($Files)
|
|
}
|