View on GitHub

fs-size-checker

A lightweight CLI tool for analyzing file and directory sizes. Signals errors via standard exit codes when specified size limits are exceeded

FS size checker logo

FS size checker

npm version GitHub stars npm downloads


A lightweight CLI tool for analyzing file and directory sizes. Signals errors via standard exit codes when specified size limits are exceeded


⭐ Support This Project

If you find this project useful, please consider giving it a star on GitHub! 🌟

Your support helps others discover this project and keeps me motivated to improve it further. Thank you! 😊


Features

Legend:

Installation

Use via npx (No Installation Required)

You can use fs-size-checker directly with npx without installing it globally:

npx fs-size-checker <path> <max_size> <unit> <ignore>

You can install fs-size-checker globally using npm:

npm install -g fs-size-checker

Or, if you prefer to use it as a development dependency in your project:

npm install --save-dev fs-size-checker

Usage

Basic Usage

Run fs-size-checker from the command line:

fs-size-checker <path> <max_size> <unit> <ignore>

Example:

fs-size-checker ./dist 50000 B

This command checks if the ./dist directory exceeds 50000 B.

As an npm Script

Add fs-size-checker to your package.json for automated checks:

{
  "scripts": {
    "check-size": "fs-size-checker ./dist 50000 B"
  }
}

Run it with:

npm run check-size

Examples:

  1. Directory Size Check in Bytes:

      fs-size-checker --path ./dist --max-size 50000 --unit B
    
  2. File Check:

      fs-size-checker --path ./dist/index.js --max-size 1000 --unit B
    
  3. Checking by specific paterns with a size limit in bytes:

    1. Check all JavaScript files in the ‘dist’ directory:
      fs-size-checker --path "dist/*.js" --max-size 500 --unit B
    
    1. Check all TypeScript files in the ‘dist’ directory and its subdirectories:
      fs-size-checker --path "dist/**/*.ts" --max-size 500 --unit B
    
    1. Check all JPEG and PNG images in the ‘dist’ directory and its subdirectories:
      fs-size-checker --path "dist/**/*.(jpeg|png)" --max-size 500 --unit B
    
    1. Check all chunked JavaScript files in the ‘dist’ directory that follow the pattern chunk-*.js:
      fs-size-checker --path "dist/chunk-*.js" --max-size 200 --unit B
    
  4. Using the ignore argument to exclude specific files or directories:

    1. Ignore a specific files (e.g., .DS_Store) while checking JavaScript files:
      fs-size-checker --path dist --max-size 1 --unit MB --ignore .DS_Store
    
    1. Ignore multiple specific files and directories:
      fs-size-checker --path dist --max-size 1 --unit MB --ignore .DS_Store --ignore node_modules
    

Options

Cross-Platform Path Support

fs-size-checker supports cross-platform paths, so you can use it on Windows, macOS, and Linux without worrying about path separators:

# On Windows
fs-size-checker --path C:\Users\YourName\Documents --max-size 10000 --unit B

# On macOS or Linux
fs-size-checker --path /home/yourname/documents --max-size 10000 --unit B

Both of these commands will work correctly on their respective platforms.

Key Characteristics

Security

Exit Codes and Error Handling

fs-size-checker uses exit codes to communicate the result of the size check:

When a size limit is exceeded, fs-size-checker will:

  1. Print a warning message to the console for each path that exceeds its limit.
  2. Continue checking all specified paths.
  3. Exit with code 1 after all checks are complete, if any limits were exceeded.

This approach ensures that:

Development

To set up the project for development:

  1. Clone the repository
  2. Install dependencies: npm install
  3. Build the project: npm run build
  4. Run tests: npm test

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file in the project root for the full license text.

The MIT License is a permissive license that allows for reuse with few restrictions. It permits use, modification, distribution, sublicense, and private use, provided that the license and copyright notice are included in all copies or substantial portions of the software.