Skip to content
pgear-wd edited this page Dec 14, 2021 · 2 revisions

ModClean can be installed globally, which will provide access to the CLI Utility. The provided CLI allows you to run ModClean without needing to write any code. Most of the configuration options from the programmatic API are available as options/flags.

Install

npm install -g modclean

Usage

modclean [-tsPevfrkml] [-p, --path=string] [-D, --modules-dir=string] [-n, --patterns=list] [-a, --additional-patterns=list] [-I, --ignore=list]

Options

-p [path], --path [string]

Provide a different path to run ModClean in. By default, it uses process.cwd(). The path must be in a directory that contains a node_modules directory.

-D, --modules-dir [string]

Change the default modules directory name. Default is node_modules.

-n, --patterns [list]

Specify which pattern plugins/rules to use. Separate multiple groups by a single comma (no spaces). Default is default:safe. Example: modclean -n default:safe,default:caution

-a, --additional-patterns [list]

Specify custom glob patterns to be included in the search.
Example: modclean --additional-patterns="*history,*.html,.config"

-I, --ignore [list]

Comma-separated list of glob patterns to ignore during cleaning. Useful when a pattern matches a module name you do not want removed.
Example: modclean --ignore="validate-npm-package-license,*history*"

Flags

-t, --test

Run in test mode which will do everything ModClean does except delete the files. It's good practice to run this first to analyze the files that will be deleted.

-s, --case-sensitive

When files are searched, they are searched using case sensitive matching. (ex. README.md pattern would not match readme.md files)

-P, --no-progress

Turns off the progress bar when files are being deleted.

--no-dirs

Do not delete directories, only files.

--no-dotfiles

Exclude dot files from being deleted.

-k, --keep-empty

Exclude empty directories from being deleted.

-e, --error-halt

Whether to halt the process when an error is encountered. The process is only halted when there is an issue deleting a file due to permissions or some other catastrophic issue.

-v, --verbose

Runs in verbose mode. This will display much more information during the process.

-f, --follow-symlink

Clean symlinked packages as well.

-m, --modules

Force deletion of modules that are matched by the patterns.

-r, --run

Run the utility immediately without displaying the warning.

-h, --help

Show help/usage screen.

-V, --version

Display the version of ModClean that is installed.

Examples

Run with default options:

$ modclean

Run with custom patterns and ignore lists:

$ modclean --patterns="default:safe,default:caution" --additional-patterns="*.xls?(x),*.ppt?(x),*.rtf" --ignore="validate-npm-license,readme*"

Run in a different cwd:

$ modclean -p /path/to/app

Run with different modules folder name (ex. Bower):

$ modclean -D components

Run all patterns in test mode:

$ modclean -t --patterns="default:*"

Run with various options:

$ modclean -kem --no-dotfiles