mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-24 11:55:31 +00:00
Use here-strings for JSON in Compile.ps1 (#2816)
* 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. * 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()) * Added comment. - Added comment to line 90.
This commit is contained in:
parent
d855b08119
commit
d92284ec83
15
Compile.ps1
15
Compile.ps1
@ -73,8 +73,8 @@ 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)
|
||||
$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 +85,13 @@ 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")
|
||||
# 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)
|
||||
"@
|
||||
|
||||
$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) = @'`n$json`n'@ `| ConvertFrom-Json" ))
|
||||
}
|
||||
|
||||
# Read the entire XAML file as a single string, preserving line breaks
|
||||
|
Loading…
Reference in New Issue
Block a user