avalonia-rename.ps1 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function Get-NewDirectoryName {
  2. param ([System.IO.DirectoryInfo]$item)
  3. $name = $item.Name.Replace("perspex", "avalonia")
  4. $name = $name.Replace("Perspex", "Avalonia")
  5. Join-Path $item.Parent.FullName $name
  6. }
  7. function Get-NewFileName {
  8. param ([System.IO.FileInfo]$item)
  9. $name = $item.Name.Replace("perspex", "avalonia")
  10. $name = $name.Replace("Perspex", "Avalonia")
  11. Join-Path $item.DirectoryName $name
  12. }
  13. function Rename-Contents {
  14. param ([System.IO.FileInfo] $file)
  15. $extensions = @(".cs",".xaml",".csproj",".sln",".md",".json",".yml",".partial",".ps1",".nuspec",".htm",".html",".gitmodules".".xml",".plist",".targets",".projitems",".shproj",".xib")
  16. if ($extensions.Contains($file.Extension)) {
  17. $text = [IO.File]::ReadAllText($file.FullName)
  18. $text = $text.Replace("github.com/perspex", "github.com/avaloniaui")
  19. $text = $text.Replace("github.com/Perspex", "github.com/AvaloniaUI")
  20. $text = $text.Replace("perspex", "avalonia")
  21. $text = $text.Replace("Perspex", "Avalonia")
  22. $text = $text.Replace("PERSPEX", "AVALONIA")
  23. [IO.File]::WriteAllText($file.FullName, $text)
  24. }
  25. }
  26. function Process-Files {
  27. param ([System.IO.DirectoryInfo] $item)
  28. $dirs = Get-ChildItem -Path $item.FullName -Directory
  29. $files = Get-ChildItem -Path $item.FullName -File
  30. foreach ($dir in $dirs) {
  31. Process-Files $dir.FullName
  32. }
  33. foreach ($file in $files) {
  34. Rename-Contents $file
  35. $renamed = Get-NewFileName $file
  36. if ($file.FullName -ne $renamed) {
  37. Write-Host git mv $file.FullName $renamed
  38. & git mv $file.FullName $renamed
  39. }
  40. }
  41. $renamed = Get-NewDirectoryName $item
  42. if ($item.FullName -ne $renamed) {
  43. Write-Host git mv $item.FullName $renamed
  44. & git mv $item.FullName $renamed
  45. }
  46. }
  47. & git submodule deinit .
  48. & git clean -xdf
  49. Process-Files .