CLEANUP TOOLS README

Documentation for Developers

Cleanup Tools for NX Monorepo

This document describes the cleanup tools available for maintaining a clean and optimized NX monorepo.

📋 Available Tools

1. Executor Cleanup Script (tools/executors/cleanup-executors.js)

2. Unused Files Detection Script (tools/cleanup-unused-files.js)

🛠️ Usage Instructions

Unused Files Detection

Safe Analysis (Recommended)

# Analyze project for unused files without removing anything
node tools/cleanup-unused-files.js --dry-run

# Verbose analysis with detailed output
node tools/cleanup-unused-files.js --dry-run --verbose

Actual Cleanup

# Remove unused files (creates backup automatically)
node tools/cleanup-unused-files.js

# Remove unused files without backup (not recommended)
node tools/cleanup-unused-files.js --no-backup

Executor Cleanup (One-time)

# Already completed, but script is available for reference
cd tools/executors
node cleanup-executors.js

📊 Cleanup Results

Executor Cleanup (2025-01-11)

Removed Scripts:

Kept Scripts:

Unused Files Detection

🔧 Configuration

Unused Files Script Configuration

The script can be configured by modifying the config object in tools/cleanup-unused-files.js:

const config = {
  // Directories to analyze
  focusDirectories: [
    'tools/scripts',
    'tools/executors',
    'apps/*/src',
    'libs/*/src',
    'shared'
  ],
  
  // File extensions to analyze
  analyzeExtensions: ['.ts', '.js', '.mjs', '.scss', '.css', '.html'],
  
  // Patterns to exclude from analysis
  excludePatterns: [
    'node_modules/**',
    'dist/**',
    '.nx/**',
    // ... more patterns
  ]
};

🔄 Maintenance Schedule

Monthly Cleanup Checklist

Quarterly Deep Cleanup

🚨 Safety Features

Backup System

Dry Run Mode

Recent File Protection

📈 Impact & Benefits

Performance Improvements

Maintainability

Developer Experience

📝 Report Generation

Each cleanup operation generates detailed reports:

Cleanup Report (cleanup-report.json)

{
  "timestamp": "2025-01-11T...",
  "config": { ... },
  "results": {
    "totalFiles": 37,
    "analyzedFiles": 22,
    "unusedFiles": 0,
    "recentFiles": 5,
    "errors": 0
  }
}

Backup Manifest (backup/manifest.json)

{
  "date": "2025-01-11T...",
  "files": ["file1.js", "file2.ts"],
  "totalFiles": 2
}

🎯 Best Practices

  1. Always Use Dry Run First: Analyze before removing
  2. Review Reports: Check what would be removed
  3. Test After Cleanup: Ensure build system still works
  4. Keep Backups: Don't disable the backup system
  5. Document Changes: Update project documentation
  6. Regular Maintenance: Don't let unused files accumulate

🔗 Related Documentation

📞 Support

If you encounter issues with the cleanup tools:

  1. Check the generated reports for details
  2. Review the backup files if needed
  3. Use dry-run mode to test changes
  4. Update tool configurations as needed

The cleanup tools are designed to be safe and conservative, erring on the side of keeping files rather than removing them unnecessarily.