Skip to content

Commit bcccf33

Browse files
committed
Added list-missing-startgame-mapid script
1 parent 8d75277 commit bcccf33

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
param(
2+
[switch]$Changed,
3+
[switch]$IncludeNonMaps,
4+
[string]$OutFile = "scripts/fixes/missing-startgame-mapid-files.txt"
5+
)
6+
7+
Set-StrictMode -Version Latest
8+
$ErrorActionPreference = "Stop"
9+
10+
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
11+
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).Path
12+
13+
function Get-RepoRelativePath {
14+
param(
15+
[Parameter(Mandatory = $true)]
16+
[string]$Path
17+
)
18+
19+
$fullPath = (Resolve-Path $Path).Path
20+
if ($fullPath.StartsWith($repoRoot, [System.StringComparison]::OrdinalIgnoreCase)) {
21+
return $fullPath.Substring($repoRoot.Length).TrimStart('\', '/')
22+
}
23+
24+
return $fullPath
25+
}
26+
27+
function Get-JsonFiles {
28+
param(
29+
[switch]$OnlyChanged
30+
)
31+
32+
Push-Location $repoRoot
33+
try {
34+
if (-not $OnlyChanged) {
35+
return @(Get-ChildItem -Path . -Recurse -File |
36+
Where-Object { $_.Extension -match '^\.(?i:json)$' } |
37+
Select-Object -ExpandProperty FullName)
38+
}
39+
40+
$changed = @()
41+
42+
$diffOutput = @(git diff --name-only --diff-filter=ACMR HEAD -- '*.json' 2>$null)
43+
if ($LASTEXITCODE -eq 0 -and $diffOutput) {
44+
$changed += $diffOutput
45+
}
46+
47+
$untrackedOutput = @(git ls-files --others --exclude-standard -- '*.json' 2>$null)
48+
if ($LASTEXITCODE -eq 0 -and $untrackedOutput) {
49+
$changed += $untrackedOutput
50+
}
51+
52+
return @($changed |
53+
Where-Object { $_ -and (Test-Path $_) } |
54+
Sort-Object -Unique |
55+
ForEach-Object { (Resolve-Path $_).Path })
56+
}
57+
finally {
58+
Pop-Location
59+
}
60+
}
61+
62+
$files = @(Get-JsonFiles -OnlyChanged:$Changed)
63+
if (-not $IncludeNonMaps) {
64+
$files = @($files | Where-Object {
65+
$rel = Get-RepoRelativePath -Path $_
66+
$rel -like "Maps\*" -or $rel -like "Maps/*"
67+
})
68+
}
69+
70+
if ($files.Count -eq 0) {
71+
if ($Changed) {
72+
Write-Host "No changed JSON files found."
73+
}
74+
else {
75+
Write-Host "No JSON files found."
76+
}
77+
exit 0
78+
}
79+
80+
$missing = New-Object System.Collections.Generic.List[string]
81+
$errorCount = 0
82+
83+
foreach ($file in $files) {
84+
$relativePath = Get-RepoRelativePath -Path $file
85+
try {
86+
$json = Get-Content -Path $file -Raw -Encoding UTF8 | ConvertFrom-Json
87+
}
88+
catch {
89+
Write-Host "[ERROR] $relativePath : invalid JSON syntax. $($_.Exception.Message)"
90+
$errorCount++
91+
continue
92+
}
93+
94+
if ($json -isnot [pscustomobject]) {
95+
continue
96+
}
97+
98+
if (-not ($json.PSObject.Properties.Name -contains "StartGameMapId")) {
99+
[void]$missing.Add($relativePath)
100+
}
101+
}
102+
103+
$outputPath = Join-Path $repoRoot $OutFile
104+
$outputDir = Split-Path -Parent $outputPath
105+
if ($outputDir -and -not (Test-Path $outputDir)) {
106+
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
107+
}
108+
109+
$missing | Sort-Object | Set-Content -Path $outputPath -Encoding utf8
110+
111+
Write-Host "Scanned files: $($files.Count)"
112+
Write-Host "Missing StartGameMapId: $($missing.Count)"
113+
Write-Host "Report: $(Get-RepoRelativePath -Path $outputPath)"
114+
Write-Host "Errors: $errorCount"
115+
116+
if ($errorCount -gt 0) {
117+
exit 1
118+
}
119+
120+
exit 0

0 commit comments

Comments
 (0)