Files
jiapuapp/tests/foundation-asset-audit.ps1
T
2026-07-13 17:31:11 +08:00

37 lines
1.2 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
$errors = [System.Collections.Generic.List[string]]::new()
$sourceFiles = Get-ChildItem -LiteralPath (Join-Path $root 'pages'), (Join-Path $root 'components') -Recurse -File |
Where-Object { $_.Extension -in '.vue', '.js', '.scss' }
foreach ($sourceFile in $sourceFiles) {
$content = Get-Content -Raw -Encoding UTF8 $sourceFile.FullName
$matches = [regex]::Matches($content, '/static/assets/[^"''\s<]+')
foreach ($match in $matches) {
$assetUrl = $match.Value
$assetPath = Join-Path $root $assetUrl.TrimStart('/')
$relativeSource = $sourceFile.FullName.Substring($root.Length + 1)
if (-not (Test-Path -LiteralPath $assetPath)) {
$errors.Add("Missing asset $assetUrl referenced by $relativeSource")
continue
}
if ($assetUrl -notmatch '^/static/assets/(foundation|modules)/') {
$errors.Add("Legacy asset path $assetUrl referenced by $relativeSource")
}
if ($assetUrl -match '(-v[0-9]+|-source)\.') {
$errors.Add("Temporary asset name $assetUrl referenced by $relativeSource")
}
}
}
if ($errors.Count -gt 0) {
throw "Foundation asset audit failed:`n$($errors -join "`n")"
}
Write-Output 'PASS foundation asset audit'