Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions Compile.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
param (
[switch]$Run,
[string]$Excluded,
[string]$Arguments
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" ))
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions tools/Compose-Config.ps1
Original file line number Diff line number Diff line change
@@ -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
}
Loading