Initial commit to new repository
This commit is contained in:
70
scripts/normalize-encoding.ps1
Normal file
70
scripts/normalize-encoding.ps1
Normal file
@@ -0,0 +1,70 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Root = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Root)) {
|
||||
$basePath = if ($PSScriptRoot) {
|
||||
$PSScriptRoot
|
||||
}
|
||||
elseif ($PSCommandPath) {
|
||||
Split-Path -Parent $PSCommandPath
|
||||
}
|
||||
else {
|
||||
(Get-Location).Path
|
||||
}
|
||||
|
||||
$Root = (Resolve-Path (Join-Path $basePath "..")).Path
|
||||
}
|
||||
|
||||
$extensions = @(".cs", ".xaml", ".csproj", ".props", ".targets", ".sln", ".json", ".md", ".txt", ".xml", ".yml", ".yaml", ".ps1")
|
||||
$utf8Bom = New-Object byte[] 3
|
||||
$utf8Bom[0] = 0xEF
|
||||
$utf8Bom[1] = 0xBB
|
||||
$utf8Bom[2] = 0xBF
|
||||
|
||||
$scanRoots = @(
|
||||
(Join-Path $Root "src"),
|
||||
(Join-Path $Root "scripts")
|
||||
) | Where-Object { Test-Path $_ }
|
||||
|
||||
$files = New-Object System.Collections.Generic.List[System.IO.FileInfo]
|
||||
foreach ($scanRoot in $scanRoots) {
|
||||
Get-ChildItem -Path $scanRoot -Recurse -File |
|
||||
Where-Object { $extensions -contains $_.Extension.ToLowerInvariant() } |
|
||||
Where-Object { $_.FullName -notmatch '\\(bin|obj|\.git|\.decompiled|\.decompiledproj|src2|dist|\.tools)\\' } |
|
||||
Where-Object { $_.Name -notlike '*.bak-*' } |
|
||||
Where-Object { $_.Name -notlike '*.broken' } |
|
||||
ForEach-Object { $files.Add($_) }
|
||||
}
|
||||
|
||||
$rootFiles = @(".editorconfig", ".gitattributes", "README.md", "AxCopilot.sln", "CLAUDE.md")
|
||||
foreach ($relativePath in $rootFiles) {
|
||||
$fullPath = Join-Path $Root $relativePath
|
||||
if (Test-Path $fullPath) {
|
||||
$files.Add((Get-Item $fullPath))
|
||||
}
|
||||
}
|
||||
|
||||
$updated = 0
|
||||
foreach ($file in $files | Sort-Object FullName -Unique) {
|
||||
$bytes = [System.IO.File]::ReadAllBytes($file.FullName)
|
||||
$hasBom = $bytes.Length -ge 3 -and
|
||||
$bytes[0] -eq $utf8Bom[0] -and
|
||||
$bytes[1] -eq $utf8Bom[1] -and
|
||||
$bytes[2] -eq $utf8Bom[2]
|
||||
|
||||
if ($hasBom) {
|
||||
continue
|
||||
}
|
||||
|
||||
$content = [System.IO.File]::ReadAllText($file.FullName)
|
||||
$utf8WithBom = New-Object System.Text.UTF8Encoding($true)
|
||||
[System.IO.File]::WriteAllText($file.FullName, $content, $utf8WithBom)
|
||||
$updated++
|
||||
Write-Host "Normalized: $($file.FullName)"
|
||||
}
|
||||
|
||||
Write-Host "Normalization complete. Updated $updated file(s)."
|
||||
Reference in New Issue
Block a user