deeconsole
v1.0.2
Published
CLI to strip or comment console statements from project files
Readme
deeconsole
Its a CLI utility for removing or commenting out console.* statements across JavaScript and TypeScript codebases. Designed to be published as an npm package, it supports glob-based file targeting, dry runs, backups, and optional comment-based preservation of log statements.
Installation
You can consume the package globally, as a dev dependency, or via npx:
# Global install (recommended for recurring use)
npm install --global deeconsole
# Project-level dev dependency
npm install --save-dev deeconsole
# On-demand without install
npx deeconsole --helpWhen installed globally or locally, the CLI executable is named deeconsole.
Usage
Run the command from the project root you want to scan. By default it searches for JavaScript and TypeScript files and removes all console statements.
deeconsoleCore Options
-c, --comment– Comment out matching statements instead of deleting them. Each line in the original statement receives a leading//while preserving indentation.-b, --backup– Create a.bakcopy alongside every file that is modified.--dry-run– Traverse and report on matches without writing any files. Useful to preview the impact of the run.-p, --pattern <glob...>– One or more glob patterns (via fast-glob) to include. Defaults to**/*.{js,jsx,ts,tsx,cjs,mjs,cts,mts}.-i, --ignore <glob...>– Glob patterns to exclude (defaults includenode_modules, build outputs, git metadata, etc.).--cwd <dir>– Base directory for glob resolution (defaults to the current working directory).--verbose– Emit a line for every file that changes, showing the number of statements handled.
Provide multiple patterns by repeating the flag or supplying several values, e.g. deeconsole --pattern "src/**/*.ts" "tests/**/*.ts".
Display the full help with:
deeconsole --helpExamples
Remove console statements from the default set of source files:
deeconsoleComment out every console.* call in a specific folder while keeping backups:
deeconsole --comment --backup --pattern "src/**/*.ts"Preview changes without touching files:
deeconsole --dry-run --verboseTarget only tests and ignore snapshot folders:
deeconsole \
--pattern "tests/**/*.{ts,tsx}" \
--ignore "**/__snapshots__/**"For a ready-made Playwright example, run the CLI against samples/playwright-sample.spec.ts.
Behavior
- Handles all member calls on the global
consoleobject (console.log,console.error, etc.). - Ensures only standalone expression statements are removed or commented. Calls embedded in larger expressions are reported as skipped to avoid breaking logic.
- Preserves original line endings and indentation when commenting out statements.
- Supports modern syntax via Babel parser plugins (JSX, TypeScript, decorators, optional chaining, top-level await, etc.).
Development
pnpm install
pnpm build
pnpm dev # Watch mode using ts-node-devAfter building, the compiled CLI lives in dist/index.js with the execute bit set by the shebang.
Sample Workflow
- Install the package globally:
npm install --global deeconsole. - Run
deeconsole --dry-runin your project root to see how many statements will be touched. - Execute
deeconsole --commentto convert logs into comments for later review, or omit the flag to remove them outright. - Inspect
.bakfiles if you enabled backups, then delete them when satisfied.
License
ISC — feel free to adapt the tool to your workflow.
