[build-script]: strip $schema from config jsons before embedding

This commit is contained in:
psyirius 2024-08-07 06:41:05 -07:00
parent 4d7e6ded11
commit 26256e14f8

View File

@ -69,24 +69,32 @@ Get-ChildItem "$workingdir\config" | Where-Object {$psitem.extension -eq ".json"
# Replace every XML Special Character so it'll render correctly in final build # Replace every XML Special Character so it'll render correctly in final build
# Only do so if json files has content to be displayed (for example the applications, tweaks, features json files) # Only do so if json files has content to be displayed (for example the applications, tweaks, features json files)
# Make an Array List containing every name at first level of Json File # Make an Array List containing every name at first level of Json File
$jsonAsObject = $json | convertfrom-json [PSCustomObject]$jsonAsObject = $json | convertfrom-json
$firstLevelJsonList = [System.Collections.ArrayList]::new()
$jsonAsObject.PSObject.Properties.Name | ForEach-Object {$null = $firstLevelJsonList.Add($_)} # Remove properties like $schema and such from the json object (we don't need it at this point)
# Note: @(
# Avoid using HTML Entity Codes, for example '”' (stands for "Right Double Quotation Mark"), "`$schema"
# Use **HTML decimal/hex codes instead**, as using HTML Entity Codes will result in XML parse Error when running the compiled script. ) | ForEach-Object {
for ($i = 0; $i -lt $firstLevelJsonList.Count; $i += 1) { $jsonAsObject.PSObject.Properties.Remove($_) | Out-Null
$firstLevelName = $firstLevelJsonList[$i] }
if ($jsonAsObject.$firstLevelName.content -ne $null) {
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&','&#38;').replace('“','&#8220;').replace('”','&#8221;').replace("'",'&#39;').replace('<','&#60;').replace('>','&#62;').replace('—','&#8212;') $firstLevelJsonList = [System.Collections.ArrayList]::new()
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&#39;&#39;',"&#39;") # resolves the Double Apostrophe caused by the first replace function in the main loop $jsonAsObject.PSObject.Properties.Name | ForEach-Object {$null = $firstLevelJsonList.Add($_)}
} # Note:
if ($jsonAsObject.$firstLevelName.description -ne $null) { # Avoid using HTML Entity Codes, for example '&rdquo;' (stands for "Right Double Quotation Mark"),
$jsonAsObject.$firstLevelName.description = $jsonAsObject.$firstLevelName.description.replace('&','&#38;').replace('“','&#8220;').replace('”','&#8221;').replace("'",'&#39;').replace('<','&#60;').replace('>','&#62;').replace('—','&#8212;') # Use **HTML decimal/hex codes instead**, as using HTML Entity Codes will result in XML parse Error when running the compiled script.
$jsonAsObject.$firstLevelName.description = $jsonAsObject.$firstLevelName.description.replace('&#39;&#39;',"&#39;") # resolves the Double Apostrophe caused by the first replace function in the main loop for ($i = 0; $i -lt $firstLevelJsonList.Count; $i += 1) {
} $firstLevelName = $firstLevelJsonList[$i]
if ($jsonAsObject.$firstLevelName.content -ne $null) {
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&','&#38;').replace('“','&#8220;').replace('”','&#8221;').replace("'",'&#39;').replace('<','&#60;').replace('>','&#62;').replace('—','&#8212;')
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&#39;&#39;',"&#39;") # resolves the Double Apostrophe caused by the first replace function in the main loop
} }
if ($jsonAsObject.$firstLevelName.description -ne $null) {
$jsonAsObject.$firstLevelName.description = $jsonAsObject.$firstLevelName.description.replace('&','&#38;').replace('“','&#8220;').replace('”','&#8221;').replace("'",'&#39;').replace('<','&#60;').replace('>','&#62;').replace('—','&#8212;')
$jsonAsObject.$firstLevelName.description = $jsonAsObject.$firstLevelName.description.replace('&#39;&#39;',"&#39;") # resolves the Double Apostrophe caused by the first replace function in the main loop
}
}
# Add 'WPFInstall' as a prefix to every entry-name in 'applications.json' file # Add 'WPFInstall' as a prefix to every entry-name in 'applications.json' file
if ($psitem.Name -eq "applications.json") { if ($psitem.Name -eq "applications.json") {