diff --git a/Compile.ps1 b/Compile.ps1 index ba23652a04..62851e59fc 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -1,5 +1,6 @@ param ( [switch]$Run, + [string]$Excluded, [string]$Arguments ) @@ -37,6 +38,11 @@ Update-Progress "Pre-req: Running Preprocessor..." 0 $preprocessingFilePath = ".\tools\Invoke-Preprocessing.ps1" . $preprocessingFilePath +$composingFilePath = ".\tools\Compose-Config.ps1" +. $composingFilePath + +$excludedCompileFiles = $Excluded -split "," + $excludedFiles = @() # Add directories only if they exist @@ -69,24 +75,8 @@ Get-ChildItem "functions" -Recurse -File | ForEach-Object { $script_content.Add($(Get-Content $psitem.FullName)) } Update-Progress "Adding: Config *.json" 40 -Get-ChildItem "config" | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object { - $json = (Get-Content $psitem.FullName -Raw) - $jsonAsObject = $json | ConvertFrom-Json - - # Add 'WPFInstall' as a prefix to every entry-name in 'applications.json' file - if ($psitem.Name -eq "applications.json") { - foreach ($appEntryName in $jsonAsObject.PSObject.Properties.Name) { - $appEntryContent = $jsonAsObject.$appEntryName - $jsonAsObject.PSObject.Properties.Remove($appEntryName) - $jsonAsObject | Add-Member -MemberType NoteProperty -Name "WPFInstall$appEntryName" -Value $appEntryContent - } - } - - # Line 90 requires no whitespace inside the here-strings, to keep formatting of the JSON in the final script. - $json = @" -$($jsonAsObject | ConvertTo-Json -Depth 3) -"@ - +Get-ChildItem "config" -Directory | ForEach-Object { + $json = Compose-Config -Directory "config\$psitem" -ExcludedFiles $excludedCompileFiles $sync.configs.$($psitem.BaseName) = $json | ConvertFrom-Json $script_content.Add($(Write-Output "`$sync.configs.$($psitem.BaseName) = @'`r`n$json`r`n'@ `| ConvertFrom-Json" )) } diff --git a/config/applications.json b/config/applications/applications.json similarity index 100% rename from config/applications.json rename to config/applications/applications.json diff --git a/config/appnavigation.json b/config/appnavigation/appnavigation.json similarity index 100% rename from config/appnavigation.json rename to config/appnavigation/appnavigation.json diff --git a/config/dns.json b/config/dns/dns.json similarity index 100% rename from config/dns.json rename to config/dns/dns.json diff --git a/config/feature.json b/config/feature/feature.json similarity index 100% rename from config/feature.json rename to config/feature/feature.json diff --git a/config/preset.json b/config/preset/preset.json similarity index 100% rename from config/preset.json rename to config/preset/preset.json diff --git a/config/themes.json b/config/themes/themes.json similarity index 100% rename from config/themes.json rename to config/themes/themes.json diff --git a/config/tweaks.json b/config/tweaks/tweaks.json similarity index 100% rename from config/tweaks.json rename to config/tweaks/tweaks.json diff --git a/tools/Compose-Config.ps1 b/tools/Compose-Config.ps1 new file mode 100644 index 0000000000..54e22bbe6b --- /dev/null +++ b/tools/Compose-Config.ps1 @@ -0,0 +1,43 @@ +function Compose-Config { + <# + .SYNOPSIS + A function that combines multiple .json files into a single object. Intended to join many seperate config files. + + .Parameter Directory + Directory to find the .json files in + + .PARAMETER Excluded + A list of files/folders to not add to combined object. + #> + + param ( + [string]$Directory, + [array]$ExcludedFiles + ) + + $fullJsonAsObject = [PSCustomObject]@{} + + Get-ChildItem $Directory -Recurse -Exclude $ExcludedFiles | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object { + $json = (Get-Content $psitem.FullName -Raw) + $jsonAsObject = $json | ConvertFrom-Json + + # Add 'WPFInstall' as a prefix to every entry-name in 'applications' folder + if ($Directory -eq "config\applications") { + foreach ($appEntryName in $jsonAsObject.PSObject.Properties.Name) { + $appEntryContent = $jsonAsObject.$appEntryName + $jsonAsObject.PSObject.Properties.Remove($appEntryName) + $jsonAsObject | Add-Member -MemberType NoteProperty -Name "WPFInstall$appEntryName" -Value $appEntryContent + } + } + + foreach ($item in $jsonAsObject.PSObject.Properties) { + $fullJsonAsObject | Add-Member -Name $item.Name -Value $item.Value -MemberType $item.MemberType + } + } + + # Lines below require no whitespace inside the here-strings, to keep formatting of the JSON in the final script. + $finalJson = @" +$($fullJsonAsObject | ConvertTo-Json -Depth 3) +"@ + return $finalJson +}