前端转vue
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

fix_duplicate_this.ps1 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <#
  2. .SYNOPSIS
  3. Fix duplicate 'this.' references in TypeScript files
  4. .DESCRIPTION
  5. This script fixes the issue where 'this.PageData' was incorrectly replaced to 'this.this.PageData'
  6. by replacing all instances of 'this.this.PageData' with 'this.PageData'
  7. #>
  8. # Configuration parameters
  9. $baseDir = "D:\front_Vue\ant-design-pro-vue3"
  10. $entityDir = "src/views/front/develop/Contract/Function/Entity"
  11. $backupRoot = "$baseDir\backups"
  12. $logFile = "$baseDir\fix_duplicate_this_log_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt"
  13. # Create backup directory and log file
  14. $backupDir = "$backupRoot\$(Get-Date -Format 'yyyyMMdd_HHmmss')"
  15. New-Item -ItemType Directory -Path $backupDir -Force | Out-Null
  16. "Fix duplicate 'this.' started at $(Get-Date)" | Out-File $logFile -Encoding UTF8
  17. # Get all .ts files (excluding demo directory)
  18. $files = Get-ChildItem -Path "$baseDir\$entityDir" -Filter "*.ts" -Recurse |
  19. Where-Object { $_.FullName -notmatch "\\demo\\" }
  20. # Process each file
  21. foreach ($file in $files) {
  22. try {
  23. $relativePath = $file.FullName.Substring($baseDir.Length + 1)
  24. "Processing: $relativePath" | Out-File $logFile -Encoding UTF8 -Append
  25. # Backup file (maintaining original directory structure)
  26. $backupPath = $file.FullName.Replace($baseDir, $backupDir)
  27. $backupDirPath = Split-Path $backupPath -Parent
  28. if (-not (Test-Path $backupDirPath)) {
  29. New-Item -ItemType Directory -Path $backupDirPath -Force | Out-Null
  30. }
  31. Copy-Item $file.FullName $backupPath
  32. # Read and modify content
  33. $content = Get-Content $file.FullName -Raw -Encoding UTF8
  34. # Fix duplicate 'this.'
  35. $originalContent = $content
  36. $content = $content -replace 'this\.this\.PageData\.', 'this.PageData.'
  37. # Only write if changes were made
  38. if ($content -ne $originalContent) {
  39. $content | Set-Content $file.FullName -Encoding UTF8
  40. "Fixed duplicate 'this.' in: $relativePath" | Out-File $logFile -Encoding UTF8 -Append
  41. } else {
  42. "No duplicate 'this.' found in: $relativePath" | Out-File $logFile -Encoding UTF8 -Append
  43. }
  44. }
  45. catch {
  46. "ERROR processing $($file.FullName): $_" | Out-File $logFile -Encoding UTF8 -Append
  47. }
  48. }
  49. # Complete processing
  50. "`nFix completed at $(Get-Date)" | Out-File $logFile -Encoding UTF8 -Append
  51. "Total files processed: $($files.Count)" | Out-File $logFile -Encoding UTF8 -Append
  52. "Backup location: $backupDir" | Out-File $logFile -Encoding UTF8 -Append
  53. Write-Host "Fix completed!"
  54. Write-Host "Files processed: $($files.Count)"
  55. Write-Host "Backup location: $backupDir"
  56. Write-Host "Detailed log: $logFile"