npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

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

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.

npm version npm downloads license

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-cli

Local Installation

npm install --save-dev code-cleanup-cli

Quick Start

Interactive Mode

Simply run the command and follow the prompts:

cleanup

Remove Everything

cleanup --all

Remove Only Comments

cleanup --comments

Remove Specific Console Methods

cleanup --console log,debug

Remove All Emojis

cleanup --emojis

Dry Run (Preview Changes)

cleanup --all --dry-run

Usage

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 statements
    • all - Remove all console methods
    • none - Don't remove any
    • log,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 -y

cleanup restore [checkpointId]

Restore files from a checkpoint.

# Interactive selection
cleanup restore

# Restore specific checkpoint
cleanup restore checkpoint-1234567890-abc123

cleanup list

List all available checkpoints.

cleanup list

cleanup delete <checkpointId>

Delete a specific checkpoint.

cleanup delete checkpoint-1234567890-abc123

Configuration 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

  1. Before processing files, a checkpoint is created in .cleanup-checkpoints/
  2. Each checkpoint has a unique ID and timestamp
  3. You can restore from any checkpoint
  4. 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-abc123

Programmatic 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,debug

Remove All Console Except Errors

cleanup --console all --console-exclude error,warn

Remove Emojis from Source Files

cleanup --emojis --path ./src

Complete Cleanup with Preview

cleanup --all --dry-run

CI/CD Integration

# In your build script
cleanup --comments --console all -y --no-checkpoint

Supported 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-regex for comprehensive Unicode emoji detection
  • Removes ALL emoji types (faces, objects, symbols, flags, etc.)
  • Handles emoji modifiers and variations

Testing

Test the Package Locally

  1. Link the package globally:
npm link
  1. Test commands:
cleanup --help
cleanup --version
cleanup list
  1. Create a test directory:
mkdir test-project
cd test-project
echo "console.log('Hello 👋'); // This is a comment" > test.js
  1. Run cleanup:
cleanup --all
  1. Verify changes:
cat test.js
  1. Test restore:
cleanup list
cleanup restore

Run Unit Tests

npm test

Run with Coverage

npm run test:coverage

Troubleshooting

"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 --all

Files 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