$ErrorActionPreference = "Stop"

function Write-NoBomFile {
    param(
        [string]$Path
    )

    if (!(Test-Path $Path)) {
        Write-Host "SKIP: $Path (not found)"
        return
    }

    $fullPath = (Resolve-Path $Path).Path
    Write-Host "PROCESS: $fullPath"

    $content = [System.IO.File]::ReadAllText($fullPath)

    # 去掉开头可能混入的 BOM / 零宽字符
    $content = $content.TrimStart([char]0xFEFF, [char]0x200B, [char]0x0000)

    # 强制写成 UTF-8 without BOM
    $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
    [System.IO.File]::WriteAllText($fullPath, $content, $utf8NoBom)

    Write-Host "  Rewritten as UTF-8 without BOM."
}

Write-NoBomFile ".\miniprogram\miniprogram_npm\tdesign-miniprogram\icon\icon.wxss"
Write-NoBomFile ".\node_modules\tdesign-miniprogram\miniprogram_dist\icon\icon.wxss"

Write-Host ""
Write-Host "DONE"