1.0.2 • Published 4 months ago

cleaninstall-node v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

CleanInstall Node

A utility to clean up Node.js project files like node_modules, lock files, and build artifacts.

Installation

Global Installation

npm install -g cleaninstall-node

Local Installation

npm install --save-dev cleaninstall-node

Usage

Command Line

After installing globally, you can run:

cleaninstall-node

Or if installed locally:

npx cleaninstall-node

Options

Usage: cleaninstall-node [options]

A utility to clean up Node.js project files

Options:
  -V, --version           output the version number
  -d, --dir <directory>   specify the root directory to clean (defaults to current directory)
  -v, --verbose           print verbose output (default: true)
  --no-verbose            disable verbose output
  --depth <number>        how deep to scan for workspaces
  --skip-git              skip .git directories (default: true)
  -h, --help              display help for command

Programmatic Usage

You can also use CleanInstall Node programmatically in your Node.js scripts:

const { cleanup } = require("cleaninstall-node");

// With default options
cleanup()
  .then(() => {
    console.log("Cleanup completed!");
  })
  .catch((err) => {
    console.error("Error during cleanup:", err);
  });

// With custom options
cleanup({
  dir: "/path/to/project",
  dirsToRemove: ["node_modules", "dist", "coverage"],
  filesToRemove: ["package-lock.json"],
  verbose: true,
  scanDepth: 3,
}).then(() => {
  console.log("Custom cleanup completed!");
});

Configuration

You can configure CleanInstall Node using one of these methods:

1. Command Line Options

See the options section above.

2. Package.json Configuration

Add a cleaninstallNode section to your package.json:

{
  "name": "your-project",
  "version": "1.0.0",
  "cleaninstallNode": {
    "dirsToRemove": ["node_modules", "dist", "build"],
    "filesToRemove": ["package-lock.json", "yarn.lock"],
    "scanDepth": 2,
    "skipDirs": [".git", "docs"]
  }
}

3. .cleaninstallnoderc File

Create a .cleaninstallnoderc file in your project root:

{
  "dirsToRemove": ["node_modules", "dist", "build"],
  "filesToRemove": ["package-lock.json", "yarn.lock"],
  "scanDepth": 2,
  "skipDirs": [".git", "docs"]
}

4. Programmatic Options

Pass options directly to the cleanup() function as shown in the Programmatic Usage section.

Configuration Options

OptionTypeDefaultDescription
dirsToRemovestring[]["node_modules", ".next", ".turbo", "dist", "build"]Directories to remove
filesToRemovestring[]["pnpm-lock.yaml", "yarn.lock", "package-lock.json"]Files to remove
scanDepthnumber2How deep to scan for workspaces (1 = only root, 2 = one level of subdirectories)
skipDirsstring[][".git"]Directories to skip
verbosebooleantrueWhether to print verbose output
cleanMonorepobooleantrueWhether to clean monorepo directories (apps/, packages/)

Development

Testing

This project uses Jest for testing. To run the tests:

npm test

The tests use mock-fs to simulate file system operations without actually modifying your file system.

Publishing

To publish this package to npm:

  1. Make sure you have an npm account and are logged in:

    npm login
  2. Update the version in package.json:

    npm version patch  # or minor, or major
  3. Publish the package:

    npm publish

License

MIT

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago