前端转vue
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

update_entity_files_improved.ps1 2.2KB

1 vecka sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # 改进版实体文件更新脚本
  2. # 解决原脚本未完全替换PageData引用和导入的问题
  3. # 1. 配置参数
  4. $directory = "src/views/front/develop/Contract/Function/Entity"
  5. $backupDir = "backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
  6. $logFile = "update_entities_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
  7. # 2. 创建备份目录和日志文件
  8. New-Item -ItemType Directory -Path $backupDir -Force | Out-Null
  9. "Script started at $(Get-Date)" | Out-File -FilePath $logFile -Encoding UTF8
  10. # 3. 获取所有.ts文件(排除demo目录)
  11. $files = Get-ChildItem -Path $directory -Filter "*.ts" -Recurse |
  12. Where-Object { $_.FullName -notmatch "\\demo\\" }
  13. # 4. 处理每个文件
  14. foreach ($file in $files) {
  15. try {
  16. # 记录处理开始
  17. "Processing file: $($file.FullName)" | Out-File -FilePath $logFile -Encoding UTF8 -Append
  18. # 备份原始文件
  19. $backupPath = Join-Path $backupDir $file.Name
  20. Copy-Item -Path $file.FullName -Destination $backupPath
  21. # 读取文件内容
  22. $content = Get-Content -Path $file.FullName -Raw -Encoding UTF8
  23. # 1. 删除PageData导入
  24. $content = $content -replace '(?m)^import\s*{\s*PageData\s*}\s*from\s*[''"].*page-data[''"];?\s*$', ''
  25. # 2. 替换所有PageData引用为this.PageData
  26. $content = $content -replace '(?<!this\.)PageData\.', 'this.PageData.'
  27. # 3. 替换FileData为fileData (如果存在)
  28. $content = $content -replace 'FileData', 'fileData'
  29. # 写入修改后的内容
  30. $content | Set-Content -Path $file.FullName -Encoding UTF8
  31. # 记录处理完成
  32. "File processed successfully: $($file.FullName)" | Out-File -FilePath $logFile -Encoding UTF8 -Append
  33. }
  34. catch {
  35. # 记录错误
  36. "Error processing file $($file.FullName): $_" | Out-File -FilePath $logFile -Encoding UTF8 -Append
  37. }
  38. }
  39. # 5. 完成处理
  40. "Script completed at $(Get-Date)" | Out-File -FilePath $logFile -Encoding UTF8 -Append
  41. "All files processed. Backup saved to: $backupDir" | Out-File -FilePath $logFile -Encoding UTF8 -Append
  42. Write-Host "所有文件处理完成。备份保存在: $backupDir"
  43. Write-Host "详细日志请查看: $logFile"