code-cleanup-cli
v1.1.2
Published
A production-ready CLI tool to remove comments, console statements, and emojis from your codebase with checkpoint/restore functionality
Downloads
59
Maintainers
Readme
code-cleanup-cli
A production-ready CLI tool to remove comments, console statements, and emojis from your JavaScript/TypeScript codebase with checkpoint/restore functionality.
Features
✨ Remove Comments - Strip single-line, multi-line, and JSDoc comments
🔇 Remove Console Statements - Selectively remove console.log, console.error, etc.
😊 Remove Emojis - Remove ALL Unicode emojis (not just faces)
🎨 Prettier Integration - Automatically formats code after cleanup
💾 Checkpoint System - Create backups before modifications
⏮️ Restore Functionality - Rollback to any previous checkpoint
🎯 Selective Processing - Choose what to remove
👀 Dry Run Mode - Preview changes without modifying files
⚙️ Configuration Files - Use .cleanuprc for project settings
🚀 Production Ready - AST-based processing for safe transformations
Installation
Global Installation (Recommended)
npm install -g code-cleanup-cliLocal Installation
npm install --save-dev code-cleanup-cliQuick Start
Interactive Mode
Simply run the command and follow the prompts:
cleanupRemove Everything
cleanup --allRemove Only Comments
cleanup --commentsRemove Specific Console Methods
cleanup --console log,debugRemove All Emojis
cleanup --emojisDry Run (Preview Changes)
cleanup --all --dry-runUsage
Commands
cleanup clean (default)
Clean your codebase by removing comments, console statements, and/or emojis.
Options:
-p, --path <path>- Path to directory (default: current directory)-c, --comments- Remove comments--console <type>- Remove console statementsall- Remove all console methodsnone- Don't remove anylog,debug,warn- Comma-separated list of methods
--console-exclude <methods>- Exclude specific console methods-e, --emojis- Remove emojis-a, --all- Remove everything--dry-run- Preview changes without modifying files--no-checkpoint- Skip creating checkpoint--no-prettier- Disable Prettier formatting-y, --yes- Skip confirmation prompts
Examples:
# Interactive mode
cleanup
# Remove comments and console.log only
cleanup --comments --console log
# Remove all console except error and warn
cleanup --console all --console-exclude error,warn
# Remove everything with dry run
cleanup --all --dry-run
# Process specific directory
cleanup --path ./src --all
# Skip checkpoint creation
cleanup --all --no-checkpoint
# Auto-confirm (useful for CI/CD)
cleanup --all -ycleanup restore [checkpointId]
Restore files from a checkpoint.
# Interactive selection
cleanup restore
# Restore specific checkpoint
cleanup restore checkpoint-1234567890-abc123cleanup list
List all available checkpoints.
cleanup listcleanup delete <checkpointId>
Delete a specific checkpoint.
cleanup delete checkpoint-1234567890-abc123Configuration File
Create a .cleanuprc, .cleanuprc.json, or cleanup.config.js file in your project root:
JSON Configuration
{
"comments": true,
"console": {
"remove": "all",
"exclude": ["error", "warn"]
},
"emojis": true,
"fileTypes": ["js", "jsx", "ts", "tsx", "vue"],
"ignore": [
"node_modules/**",
"dist/**",
"build/**"
],
"checkpoint": {
"enabled": true,
"retention": 10
}
}JavaScript Configuration
// cleanup.config.js
module.exports = {
comments: true,
console: {
remove: ['log', 'debug'],
exclude: []
},
emojis: true,
fileTypes: ['js', 'jsx', 'ts', 'tsx'],
ignore: ['**/vendor/**'],
checkpoint: {
enabled: true,
retention: 5
}
};Configuration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| comments | boolean | false | Remove comments |
| console.remove | string/array | 'none' | Console methods to remove ('all', 'none', or array like ['log', 'debug']) |
| console.exclude | array | [] | Console methods to exclude from removal |
| emojis | boolean | false | Remove emojis |
| fileTypes | array | ['js', 'jsx', 'ts', 'tsx', 'vue', 'mjs', 'cjs'] | File extensions to process |
| ignore | array | [] | Glob patterns to ignore |
| checkpoint.enabled | boolean | true | Enable checkpoint creation |
| checkpoint.retention | number | 10 | Number of checkpoints to keep |
| prettier | boolean | true | Enable Prettier formatting |
Checkpoint System
The checkpoint system creates backups of your files before making changes, allowing you to restore them if needed.
How It Works
- Before processing files, a checkpoint is created in
.cleanup-checkpoints/ - Each checkpoint has a unique ID and timestamp
- You can restore from any checkpoint
- Old checkpoints are automatically cleaned based on retention policy
Checkpoint Directory
Checkpoints are stored in .cleanup-checkpoints/ in your project root. Add this to your .gitignore:
.cleanup-checkpoints/Managing Checkpoints
# List all checkpoints
cleanup list
# Restore from checkpoint
cleanup restore checkpoint-1234567890-abc123
# Delete checkpoint
cleanup delete checkpoint-1234567890-abc123Programmatic Usage
You can also use this package programmatically in your Node.js scripts:
const { cleanup } = require('code-cleanup-cli');
async function cleanMyCode() {
const results = await cleanup('./src', {
comments: true,
console: { remove: 'all' },
emojis: true,
checkpoint: { enabled: true }
});
console.log(`Processed ${results.filesProcessed} files`);
console.log(`Modified ${results.filesModified} files`);
console.log(`Checkpoint: ${results.checkpointId}`);
}
cleanMyCode();Examples
Remove Comments from Entire Project
cleanup --comments --path ./Remove console.log and console.debug
cleanup --console log,debugRemove All Console Except Errors
cleanup --console all --console-exclude error,warnRemove Emojis from Source Files
cleanup --emojis --path ./srcComplete Cleanup with Preview
cleanup --all --dry-runCI/CD Integration
# In your build script
cleanup --comments --console all -y --no-checkpointSupported File Types
By default, the following file types are processed:
.js- JavaScript.jsx- React JSX.ts- TypeScript.tsx- TypeScript JSX.vue- Vue.js.mjs- ES Modules.cjs- CommonJS
You can customize this in your configuration file.
Ignored Directories
The following directories are automatically ignored:
node_modules/dist/build/.git/.cleanup-checkpoints/coverage/.next/out/
Add custom ignore patterns in your configuration file.
How It Works
AST-Based Processing
The tool uses Babel's parser to create an Abstract Syntax Tree (AST) of your code, ensuring safe and accurate transformations without breaking your code structure.
Comment Removal
- Removes single-line comments (
//) - Removes multi-line comments (
/* */) - Optionally preserves JSDoc comments
- Preserves license comments by default
Console Removal
- Detects all console method calls
- Safely removes console statements
- Handles edge cases (console in expressions)
- Preserves code functionality
Emoji Removal
- Uses
emoji-regexfor comprehensive Unicode emoji detection - Removes ALL emoji types (faces, objects, symbols, flags, etc.)
- Handles emoji modifiers and variations
Testing
Test the Package Locally
- Link the package globally:
npm link- Test commands:
cleanup --help
cleanup --version
cleanup list- Create a test directory:
mkdir test-project
cd test-project
echo "console.log('Hello 👋'); // This is a comment" > test.js- Run cleanup:
cleanup --all- Verify changes:
cat test.js- Test restore:
cleanup list
cleanup restoreRun Unit Tests
npm testRun with Coverage
npm run test:coverageTroubleshooting
"Command not found: cleanup"
Make sure you've installed the package globally:
npm install -g code-cleanup-cli"No checkpoints found"
Checkpoints are only created when processing files. Run a cleanup first:
cleanup --allFiles not being processed
Check your ignore patterns in the configuration file. Also ensure the file extensions are included in fileTypes.
Parsing errors
Some files may fail to parse (e.g., invalid syntax). The tool will skip these files and continue processing others.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT © Praise Olaoye
Support
Changelog
See CHANGELOG.md for version history.
Made with ❤️ by developers, for developers
