aboutsummaryrefslogtreecommitdiff
path: root/ci/compile.ps1
blob: 459f304918f63c64b7b08d847e5450577b9aa0e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
param([String] $inputDir, [String] $outputDir)

$templateFiles = Get-ChildItem -Path $inputDir -Filter "*-template.json" -File

foreach ($file in $templateFiles) {
    $baseFilename = $file.BaseName + '.json'
    $templateFilePath = $file.FullName
    
    #remove the -template.json suffix 
    $outputFilePath = Join-Path -Path $outputDir -ChildPath $baseFilename.replace("-template","")
    
    #substitute environment variables for file variables
    Get-Content $templateFilePath | ForEach-Object { 
        if ($_ -match "\$\{(\w+)(:-([^\}]+))?\}")
        {
            $varName = $Matches[1]
            $defaultValue = if ($Matches[3]) { $Matches[3] } else { '' }
            $envValue = [Environment]::GetEnvironmentVariable($varName)
            if (!$envValue) { $envValue = $defaultValue }
            $_ -replace "\$\{(\w+)(:-([^\}]+))?\}", $envValue
        }
        else
        {
            $_
        }
    } | Set-Content $outputFilePath
}