# Angular 项目缓存清理脚本 # 用法: .\clean-cache.ps1 Write-Host "================================" -ForegroundColor Cyan Write-Host " Angular 项目缓存清理工具" -ForegroundColor Cyan Write-Host "================================" -ForegroundColor Cyan Write-Host "" # 检查当前项目大小 Write-Host "📊 检查当前项目大小..." -ForegroundColor Yellow $beforeSize = (Get-ChildItem -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1GB Write-Host "当前项目总大小: $([math]::Round($beforeSize, 2)) GB" -ForegroundColor White Write-Host "" # 检查各文件夹大小 Write-Host "📁 各文件夹大小:" -ForegroundColor Yellow $folders = @('.angular', 'node_modules', 'dist', 'coverage') foreach ($folder in $folders) { if (Test-Path $folder) { $size = (Get-ChildItem $folder -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1GB $sizeStr = [math]::Round($size, 2) if ($size -gt 5) { Write-Host " $folder : $sizeStr GB" -ForegroundColor Red } elseif ($size -gt 1) { Write-Host " $folder : $sizeStr GB" -ForegroundColor Yellow } else { Write-Host " $folder : $sizeStr GB" -ForegroundColor Green } } else { Write-Host " $folder : 不存在" -ForegroundColor Gray } } Write-Host "" # 询问用户要清理什么 Write-Host "🧹 请选择要清理的内容:" -ForegroundColor Cyan Write-Host " 1. 仅清理 .angular 缓存 (推荐)" -ForegroundColor White Write-Host " 2. 清理 .angular 和 dist" -ForegroundColor White Write-Host " 3. 清理 .angular, dist 和 coverage" -ForegroundColor White Write-Host " 4. 清理所有 (包括 node_modules)" -ForegroundColor Red Write-Host " 5. 取消" -ForegroundColor Gray Write-Host "" $choice = Read-Host "请输入选项 (1-5)" switch ($choice) { "1" { Write-Host "" Write-Host "🗑️ 正在清理 .angular 缓存..." -ForegroundColor Yellow if (Test-Path ".angular") { Remove-Item -Path ".angular" -Recurse -Force -ErrorAction SilentlyContinue Write-Host "✅ .angular 已删除" -ForegroundColor Green } else { Write-Host "ℹ️ .angular 不存在" -ForegroundColor Gray } } "2" { Write-Host "" Write-Host "🗑️ 正在清理 .angular 和 dist..." -ForegroundColor Yellow if (Test-Path ".angular") { Remove-Item -Path ".angular" -Recurse -Force -ErrorAction SilentlyContinue Write-Host "✅ .angular 已删除" -ForegroundColor Green } if (Test-Path "dist") { Remove-Item -Path "dist" -Recurse -Force -ErrorAction SilentlyContinue Write-Host "✅ dist 已删除" -ForegroundColor Green } } "3" { Write-Host "" Write-Host "🗑️ 正在清理 .angular, dist 和 coverage..." -ForegroundColor Yellow if (Test-Path ".angular") { Remove-Item -Path ".angular" -Recurse -Force -ErrorAction SilentlyContinue Write-Host "✅ .angular 已删除" -ForegroundColor Green } if (Test-Path "dist") { Remove-Item -Path "dist" -Recurse -Force -ErrorAction SilentlyContinue Write-Host "✅ dist 已删除" -ForegroundColor Green } if (Test-Path "coverage") { Remove-Item -Path "coverage" -Recurse -Force -ErrorAction SilentlyContinue Write-Host "✅ coverage 已删除" -ForegroundColor Green } } "4" { Write-Host "" Write-Host "⚠️ 警告: 这将删除所有缓存和依赖!" -ForegroundColor Red $confirm = Read-Host "确认删除? (yes/no)" if ($confirm -eq "yes") { Write-Host "🗑️ 正在清理所有文件..." -ForegroundColor Yellow Remove-Item -Path ".angular" -Recurse -Force -ErrorAction SilentlyContinue Remove-Item -Path "dist" -Recurse -Force -ErrorAction SilentlyContinue Remove-Item -Path "coverage" -Recurse -Force -ErrorAction SilentlyContinue Remove-Item -Path "node_modules" -Recurse -Force -ErrorAction SilentlyContinue Write-Host "✅ 所有文件已删除" -ForegroundColor Green Write-Host "💡 请运行 'npm install' 重新安装依赖" -ForegroundColor Cyan } else { Write-Host "❌ 已取消" -ForegroundColor Gray exit } } "5" { Write-Host "❌ 已取消" -ForegroundColor Gray exit } default { Write-Host "❌ 无效选项" -ForegroundColor Red exit } } # 显示清理后的大小 Write-Host "" Write-Host "📊 清理后的项目大小..." -ForegroundColor Yellow $afterSize = (Get-ChildItem -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1GB $saved = $beforeSize - $afterSize Write-Host "清理后项目大小: $([math]::Round($afterSize, 2)) GB" -ForegroundColor Green Write-Host "节省空间: $([math]::Round($saved, 2)) GB" -ForegroundColor Green Write-Host "" Write-Host "✅ 清理完成!" -ForegroundColor Green Write-Host ""