cleanup-unrelated.ps1 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. $ErrorActionPreference = 'Stop'
  2. $root = Split-Path -Parent $PSScriptRoot
  3. $fe = Join-Path $root 'frontend'
  4. $be = Join-Path $root 'backend'
  5. function Remove-Path([string]$path) {
  6. if (Test-Path -LiteralPath $path) {
  7. Remove-Item -LiteralPath $path -Recurse -Force
  8. Write-Output ("REMOVED " + $path.Substring($root.Length + 1))
  9. }
  10. }
  11. # frontend directories
  12. @(
  13. 'docs',
  14. 'backups',
  15. 'cloud-functions',
  16. 'outputs',
  17. 'test-results',
  18. 'tmp',
  19. 'scripts',
  20. 'rules'
  21. ) | ForEach-Object { Remove-Path (Join-Path $fe $_) }
  22. # frontend softzhu directory if present
  23. Get-ChildItem -LiteralPath $fe -Force -Directory | Where-Object {
  24. $_.Name -like '*软著*' -or $_.Name -eq '软著申报'
  25. } | ForEach-Object { Remove-Path $_.FullName }
  26. # frontend root clutter
  27. $keepExact = @(
  28. 'src',
  29. 'angular.json',
  30. 'package.json',
  31. 'package-lock.json',
  32. 'tsconfig.json',
  33. 'tsconfig.app.json',
  34. 'proxy.conf.json',
  35. 'README.md'
  36. )
  37. Get-ChildItem -LiteralPath $fe -Force | ForEach-Object {
  38. $name = $_.Name
  39. if ($keepExact -contains $name) { return }
  40. $drop = $false
  41. if ($name.StartsWith('_')) { $drop = $true }
  42. elseif ($name -match '\.(md|docx|xlsx|ps1|txt|out|diff|js)$') { $drop = $true }
  43. elseif ($name -like 'echarts_*') { $drop = $true }
  44. elseif ($name -like 'cloud-function-*') { $drop = $true }
  45. elseif ($name -like 'patch-*') { $drop = $true }
  46. elseif ($name -match '^(ec\d+|safe|scan|usage|findec)(\.|$)') { $drop = $true }
  47. if ($drop) { Remove-Path $_.FullName }
  48. }
  49. # backend unrelated
  50. @(
  51. 'docs',
  52. 'scripts',
  53. 'rules',
  54. 'IMPLEMENTATION-SUMMARY.md'
  55. ) | ForEach-Object { Remove-Path (Join-Path $be $_) }
  56. # module docs/tests
  57. Get-ChildItem -Path (Join-Path $be 'modules') -Recurse -Directory -ErrorAction SilentlyContinue |
  58. Where-Object { $_.Name -in @('docs','examples','__tests__','test','tests') } |
  59. ForEach-Object { Remove-Path $_.FullName }
  60. Get-ChildItem -Path (Join-Path $be 'modules') -Recurse -File -Filter '*.md' -ErrorAction SilentlyContinue |
  61. ForEach-Object { Remove-Path $_.FullName }
  62. Write-Output 'CLEANUP_DONE'