From 08c8d2f8e46e5a5077da61d2036e47551702ab4d Mon Sep 17 00:00:00 2001 From: Underscore Date: Tue, 24 Sep 2024 14:01:38 -0700 Subject: [PATCH 1/3] Use here-strings for JSON in Compile.ps1 - Change Compile.ps1 to use here-strings with JSON, similar to my changes to Xaml being ingested using here-strings. --- Compile.ps1 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Compile.ps1 b/Compile.ps1 index 83be24067f..88f66fcdc5 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -73,8 +73,10 @@ Get-ChildItem "functions" -Recurse -File | ForEach-Object { } Update-Progress "Adding: Config *.json" 40 Get-ChildItem "config" | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object { - $json = (Get-Content $psitem.FullName).replace("'","''") - $jsonAsObject = $json | convertfrom-json + $json = @" + $((Get-Content $psitem.FullName -Raw).replace("'","''")) +"@ + $jsonAsObject = $json | ConvertFrom-Json # Add 'WPFInstall' as a prefix to every entry-name in 'applications.json' file if ($psitem.Name -eq "applications.json") { @@ -85,12 +87,12 @@ Get-ChildItem "config" | Where-Object {$psitem.extension -eq ".json"} | ForEach- } } - # The replace at the end is required, as without it the output of 'converto-json' will be somewhat weird for Multiline Strings - # Most Notably is the scripts in some json files, making it harder for users who want to review these scripts, which're found in the compiled script - $json = ($jsonAsObject | convertto-json -Depth 3).replace('\r\n',"`r`n") + $json = @" + $($jsonAsObject | ConvertTo-Json -Depth 3) +"@ - $sync.configs.$($psitem.BaseName) = $json | convertfrom-json - $script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$json' `| convertfrom-json" )) + $sync.configs.$($psitem.BaseName) = $json | ConvertFrom-Json + $script_content.Add($(Write-Output "`$sync.configs.$($psitem.BaseName) = '$json' `| ConvertFrom-Json" )) } # Read the entire XAML file as a single string, preserving line breaks From ff0795f0b88c6e1934e3204e516560b4c4ae76b1 Mon Sep 17 00:00:00 2001 From: Underscore Date: Tue, 24 Sep 2024 14:54:58 -0700 Subject: [PATCH 2/3] Slight changes. - Modifications, allowing for the removal of all .replace() functions in JSON handler. - Changed formatting of here-string on line 91 -> 89 to prevent accidental double in winutil.ps1 (Doesn't cause an issue, but looks better.) - Added here-string to 95 -> 93 (This allowed the removal of the final .replace()) --- Compile.ps1 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Compile.ps1 b/Compile.ps1 index 88f66fcdc5..34eca4696f 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -73,9 +73,7 @@ Get-ChildItem "functions" -Recurse -File | ForEach-Object { } Update-Progress "Adding: Config *.json" 40 Get-ChildItem "config" | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object { - $json = @" - $((Get-Content $psitem.FullName -Raw).replace("'","''")) -"@ + $json = (Get-Content $psitem.FullName -Raw) $jsonAsObject = $json | ConvertFrom-Json # Add 'WPFInstall' as a prefix to every entry-name in 'applications.json' file @@ -88,11 +86,11 @@ Get-ChildItem "config" | Where-Object {$psitem.extension -eq ".json"} | ForEach- } $json = @" - $($jsonAsObject | ConvertTo-Json -Depth 3) +$($jsonAsObject | ConvertTo-Json -Depth 3) "@ $sync.configs.$($psitem.BaseName) = $json | ConvertFrom-Json - $script_content.Add($(Write-Output "`$sync.configs.$($psitem.BaseName) = '$json' `| ConvertFrom-Json" )) + $script_content.Add($(Write-Output "`$sync.configs.$($psitem.BaseName) = @'`n$json`n'@ `| ConvertFrom-Json" )) } # Read the entire XAML file as a single string, preserving line breaks From 12a83eac9bd6467601b7f02b8177fd93072be617 Mon Sep 17 00:00:00 2001 From: Underscore Date: Tue, 24 Sep 2024 14:58:22 -0700 Subject: [PATCH 3/3] Added comment. - Added comment to line 90. --- Compile.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Compile.ps1 b/Compile.ps1 index 34eca4696f..f427e3551c 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -85,6 +85,7 @@ Get-ChildItem "config" | Where-Object {$psitem.extension -eq ".json"} | ForEach- } } + # 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) "@