38 lines
1.3 KiB
PowerShell
38 lines
1.3 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
|
|
if ($assetUrl.Contains('${')) { continue }
|
|
$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 '-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'
|