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)
- Purpose: Remove deprecated migration scripts from the executors directory
- Status: ✅ COMPLETED - Successfully removed 7 deprecated scripts
- Backup: All removed scripts are backed up in
tools/executors/backup/
2. Unused Files Detection Script (tools/cleanup-unused-files.js)
- Purpose: Detect and optionally remove unused files across the project
- Status: ✅ ACTIVE - Ready for ongoing use
- Features:
- Intelligent file reference analysis
- Dry-run mode for safe analysis
- Automatic backup creation
- Detailed reporting
🛠️ 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: 7 deprecated migration scripts
- Kept: 3 potentially useful scripts
- Backup:
tools/executors/backup/
Removed Scripts:
move-core-models.shmove-remaining-models.shmove-state-models.shmove-utility-types.shremove-core-models.shupdate-core-model-imports.shupdate-theme-imports.sh
Kept Scripts:
patch-ux-test-build.shspace-images.shtheme-assets.sh
Unused Files Detection
- Initial Analysis: Detected 2 potentially unused files
- Verification: Files were determined to be in use upon deeper analysis
- Result: No files removed (system working correctly)
🔧 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
- Run unused file detection analysis
- Review and remove any truly unused files
- Update documentation after structural changes
- Test build system after cleanup
Quarterly Deep Cleanup
- Review all tools and scripts for necessity
- Update cleanup tool configurations
- Analyze dependencies and remove unused libraries
- Update project structure documentation
🚨 Safety Features
Backup System
- Automatic Backups: All removed files are backed up automatically
- Timestamped Backups: Backups are organized by date
- Manifest Files: Each backup includes a manifest with file details
Dry Run Mode
- No Changes: Analyze without making any modifications
- Safe Testing: Test cleanup logic before actual removal
- Detailed Reporting: See exactly what would be removed
Recent File Protection
- 30-Day Protection: Files modified within 30 days are preserved
- Smart Analysis: Recently modified files are skipped automatically
- Development Safety: Protects files you're actively working on
📈 Impact & Benefits
Performance Improvements
- Reduced Build Time: Fewer files to process
- Smaller Bundle Size: Removed unused dependencies
- Faster Analysis: Cleaner codebase for static analysis
Maintainability
- Clear Structure: Easier to understand project organization
- Reduced Complexity: Fewer files to maintain
- Better Documentation: Up-to-date project structure docs
Developer Experience
- Faster Navigation: Less clutter in file explorer
- Clearer Dependencies: Removed obsolete migration scripts
- Better Onboarding: New developers see clean, current codebase
📝 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
- Always Use Dry Run First: Analyze before removing
- Review Reports: Check what would be removed
- Test After Cleanup: Ensure build system still works
- Keep Backups: Don't disable the backup system
- Document Changes: Update project documentation
- Regular Maintenance: Don't let unused files accumulate
🔗 Related Documentation
📞 Support
If you encounter issues with the cleanup tools:
- Check the generated reports for details
- Review the backup files if needed
- Use dry-run mode to test changes
- 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.