79 lines
2.7 KiB
PowerShell
79 lines
2.7 KiB
PowerShell
# 批量转换所有.uvue文件的换行符为LF
|
||
# Convert all .uvue files to use LF line endings
|
||
|
||
Write-Host "开始转换所有.uvue文件的换行符为LF..." -ForegroundColor Green
|
||
|
||
# 获取所有.uvue文件
|
||
$uvueFiles = Get-ChildItem -Path "." -Filter "*.uvue" -Recurse
|
||
|
||
Write-Host "找到 $($uvueFiles.Count) 个.uvue文件" -ForegroundColor Yellow
|
||
|
||
$convertedCount = 0
|
||
$errorCount = 0
|
||
|
||
foreach ($file in $uvueFiles) {
|
||
try {
|
||
Write-Host "处理文件: $($file.FullName)" -ForegroundColor Cyan
|
||
|
||
# 读取文件内容
|
||
$content = Get-Content -Path $file.FullName -Raw
|
||
|
||
if ($content) {
|
||
# 将CRLF转换为LF
|
||
$contentLF = $content -replace "`r`n", "`n"
|
||
# 确保单独的CR也转换为LF
|
||
$contentLF = $contentLF -replace "`r", "`n"
|
||
|
||
# 写回文件,使用UTF8编码且不添加BOM
|
||
[System.IO.File]::WriteAllText($file.FullName, $contentLF, [System.Text.UTF8Encoding]::new($false))
|
||
|
||
$convertedCount++
|
||
Write-Host " ✓ 转换成功" -ForegroundColor Green
|
||
} else {
|
||
Write-Host " ⚠ 文件为空,跳过" -ForegroundColor Yellow
|
||
}
|
||
}
|
||
catch {
|
||
$errorCount++
|
||
Write-Host " ✗ 转换失败: $($_.Exception.Message)" -ForegroundColor Red
|
||
}
|
||
}
|
||
|
||
Write-Host "`n转换完成!" -ForegroundColor Green
|
||
Write-Host "成功转换: $convertedCount 个文件" -ForegroundColor Green
|
||
if ($errorCount -gt 0) {
|
||
Write-Host "转换失败: $errorCount 个文件" -ForegroundColor Red
|
||
}
|
||
|
||
# 同时转换其他相关文件类型
|
||
Write-Host "`n开始转换其他文件类型..." -ForegroundColor Green
|
||
|
||
$otherExtensions = @("*.uts", "*.ts", "*.js", "*.vue", "*.json", "*.md")
|
||
$otherConvertedCount = 0
|
||
|
||
foreach ($extension in $otherExtensions) {
|
||
$files = Get-ChildItem -Path "." -Filter $extension -Recurse | Where-Object {
|
||
$_.Name -notmatch "node_modules|\.git|unpackage|dist"
|
||
}
|
||
|
||
foreach ($file in $files) {
|
||
try {
|
||
$content = Get-Content -Path $file.FullName -Raw
|
||
|
||
if ($content) {
|
||
$contentLF = $content -replace "`r`n", "`n"
|
||
$contentLF = $contentLF -replace "`r", "`n"
|
||
|
||
[System.IO.File]::WriteAllText($file.FullName, $contentLF, [System.Text.UTF8Encoding]::new($false))
|
||
$otherConvertedCount++
|
||
}
|
||
}
|
||
catch {
|
||
Write-Host "转换文件失败: $($file.FullName) - $($_.Exception.Message)" -ForegroundColor Red
|
||
}
|
||
}
|
||
}
|
||
|
||
Write-Host "其他文件转换完成: $otherConvertedCount 个文件" -ForegroundColor Green
|
||
Write-Host "`n所有文件换行符转换完成!" -ForegroundColor Magenta
|