kiwix-js-pwa/scripts/Add-Remove-BOM.ps1
Jaifroid 8dfb94e6e5 Update Add-Remove-BOM.ps1
Former-commit-id: 2da443b9e89fa446bc2ef4535a117727da84ab54 [formerly dc543763283af6879e0be1d97a6ef1929a99f05c [formerly 07ec84d2a5fa2e488791997009980855d76aa8f1]]
Former-commit-id: 8314aad2f670bb3d19036a996e900628d4176999
Former-commit-id: e9fcabf193434fd1b64d3acdad2eece23873b28f
2021-06-07 13:06:45 +01:00

36 lines
1.1 KiB
PowerShell

param (
[string]$filename = "",
[switch]$nobom = $false,
[switch]$addbom = $false
)
# Deal with cases where no directory is entered
if ($filename -eq "") {
$filename = Read-Host "Enter the directory for processing: "
}
" "
ls -r -name $filename -Include @('*.js','*.css','*.html')
if ($nobom) {
$input = Read-Host "`nAll the above files will have the BOM (if any) removed!`nProceed? (Y/N)"
} else {
$input = Read-Host "`nAll the above files will have a BOM added (if necessary)!`nProceed? (Y/N)"
}
if ($input -eq "Y") {
if ($nobom) {
"Removing Byte Order Mark ..."
ls -r $filename -Include @('*.js','*.css','*.html') | % { [System.IO.File]::WriteAllLines($_.FullName, ((Get-Content $_.FullName) -replace "^\xEF\xBB\xBF", ""))}
} else {
"Adding Byte Order Mark ..."
ls -r $filename -Include @('*.js','*.css','*.html') | % {
$document = Get-Content -encoding "UTF8" $_.FullName
if ($document -match "^(?!\xEF\xBB\xBF)") {
$document | Set-Content -encoding "utf8BOM" $_.FullName
}
}
}
"Done."
} else {
"Operation cancelled!"
}