前端转vue
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

batch_replace_pageData.ps1 2.6KB

6 дні тому
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <#
  2. .SYNOPSIS
  3. Batch replace PageData references in all TypeScript files
  4. .DESCRIPTION
  5. 1. Automatically backup original files
  6. 2. Remove all PageData import statements
  7. 3. Replace all PageData references with this.PageData
  8. 4. Generate detailed execution log
  9. #>
  10. # Configuration parameters
  11. $baseDir = "D:\front_Vue\ant-design-pro-vue3"
  12. $entityDir = "src/views/front/develop/Contract/Function/Entity"
  13. $backupRoot = "$baseDir\backups"
  14. $logFile = "$baseDir\batch_replace_log_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt"
  15. # Create backup directory and log file
  16. $backupDir = "$backupRoot\$(Get-Date -Format 'yyyyMMdd_HHmmss')"
  17. New-Item -ItemType Directory -Path $backupDir -Force | Out-Null
  18. "Batch replace started at $(Get-Date)" | Out-File $logFile -Encoding UTF8
  19. # Get all .ts files (excluding demo directory)
  20. $files = Get-ChildItem -Path "$baseDir\$entityDir" -Filter "*.ts" -Recurse |
  21. Where-Object { $_.FullName -notmatch "\\demo\\" }
  22. # Process each file
  23. foreach ($file in $files) {
  24. try {
  25. $relativePath = $file.FullName.Substring($baseDir.Length + 1)
  26. "Processing: $relativePath" | Out-File $logFile -Encoding UTF8 -Append
  27. # Backup file (maintaining original directory structure)
  28. $backupPath = $file.FullName.Replace($baseDir, $backupDir)
  29. $backupDirPath = Split-Path $backupPath -Parent
  30. if (-not (Test-Path $backupDirPath)) {
  31. New-Item -ItemType Directory -Path $backupDirPath -Force | Out-Null
  32. }
  33. Copy-Item $file.FullName $backupPath
  34. # Read and modify content
  35. $content = Get-Content $file.FullName -Raw -Encoding UTF8
  36. # 1. Remove PageData import
  37. $content = $content -replace '(?m)^import\s*{\s*PageData\s*}\s*from\s*[''"].*page-data[''"];?\s*$', ''
  38. # 2. Replace all PageData references
  39. $content = $content -replace '(?<!this\.)PageData\.', 'this.PageData.'
  40. # Write to file
  41. $content | Set-Content $file.FullName -Encoding UTF8
  42. "Successfully processed: $relativePath" | Out-File $logFile -Encoding UTF8 -Append
  43. }
  44. catch {
  45. "ERROR processing $($file.FullName): $_" | Out-File $logFile -Encoding UTF8 -Append
  46. }
  47. }
  48. # Complete processing
  49. "`nBatch replace completed at $(Get-Date)" | Out-File $logFile -Encoding UTF8 -Append
  50. "Total files processed: $($files.Count)" | Out-File $logFile -Encoding UTF8 -Append
  51. "Backup location: $backupDir" | Out-File $logFile -Encoding UTF8 -Append
  52. Write-Host "Batch replacement completed!"
  53. Write-Host "Files processed: $($files.Count)"
  54. Write-Host "Backup location: $backupDir"
  55. Write-Host "Detailed log: $logFile"