From fbd811273b0536eefc7d8f9abf01376514584b4c Mon Sep 17 00:00:00 2001 From: Rem0o Date: Thu, 10 Oct 2024 11:35:13 -0400 Subject: [PATCH] Update format-json.ps1 --- format-json.ps1 | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/format-json.ps1 b/format-json.ps1 index 805122a..9bfdec1 100644 --- a/format-json.ps1 +++ b/format-json.ps1 @@ -112,11 +112,12 @@ function ConvertTo-OrderedDictionaryFromArray { $fullPath = $Path | Resolve-Path Write-Output "Scanning $fullPath" -Write-Output "" +Write-Output "${[Environment]::NewLine}" $baseFiles = Get-ChildItem -Path $Path -Filter "*.json" -Recurse | Where-Object { $_.Name -notmatch "\.[a-z]{2}(-[a-z]{2})?\.json$" } $exitCode = 0 +$problem = "" foreach ($baseFile in $baseFiles) { $baseJson = Get-Content -Path $baseFile.FullName -Raw; @@ -155,8 +156,9 @@ foreach ($baseFile in $baseFiles) { $formattedTranslationJson = ConvertTo-OrderedDictionaryFromArray($translation.GetEnumerator() | Sort-Object -Property Name) | ConvertTo-Json -Depth 100 | Format-Json -Indentation 2 if ($formattedTranslationJson -ne $translationJson) { $exitCode = -1 + $problem = "Formatting for [$translationFile] is wrong" if ($Fix) { - Write-Output "Formatting $translationFile" + Write-Output "Formatting [$translationFile]" Set-Content -Path $translationFile.FullName -Value $formattedTranslationJson -NoNewLine } } @@ -166,20 +168,27 @@ foreach ($baseFile in $baseFiles) { $formattedBaseJson = ConvertTo-OrderedDictionaryFromArray( $baseDictionary.GetEnumerator() | Sort-Object -Property Name) | ConvertTo-Json -Depth 100 | Format-Json -Indentation 2 if ($formattedBaseJson -ne $baseJson) { $exitCode = -1; + $problem = "Formatting for [$baseFile] is wrong" if ($Fix) { - Write-Output "Formatting $baseFile" + Write-Output "Formatting [$baseFile]" Set-Content -Path $baseFile.FullName -Value $formattedBaseJson -NoNewLine } } - } -if ($exitCode -eq 0) { - Write-Output "No problem found!" +Write-Output "${[Environment]::NewLine}" +if ( $Fix -and ($exitCode -eq -1) ) { + $exitCode = 0 } -else { - Write-Output "" +elseif ( $exitCode -eq -1) { Write-Output "Problems found!" + if ( -Not [String]::IsNullOrEmpty($problem) ) { + Write-Output $problem + } +} +# Success (0) +else { + Write-Output "No problem found!" } exit $exitCode \ No newline at end of file