A lightweight CLI tool for analyzing file and directory sizes. Signals errors via standard exit codes when specified size limits are exceeded
Legend:
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
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.
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:
Directory Size Check in Bytes:
fs-size-checker --path ./dist --max-size 50000 --unit B
File Check:
fs-size-checker --path ./dist/index.js --max-size 1000 --unit B
Checking by specific paterns with a size limit in bytes:
fs-size-checker --path "dist/*.js" --max-size 500 --unit B
fs-size-checker --path "dist/**/*.ts" --max-size 500 --unit B
fs-size-checker --path "dist/**/*.(jpeg|png)" --max-size 500 --unit B
chunk-*.js
: fs-size-checker --path "dist/chunk-*.js" --max-size 200 --unit B
Using the ignore
argument to exclude specific files or directories:
fs-size-checker --path dist --max-size 1 --unit MB --ignore .DS_Store
fs-size-checker --path dist --max-size 1 --unit MB --ignore .DS_Store --ignore node_modules
--path
or -p
: The path to check. Can include directory and file matching patterns. Can be specified multiple times for checking multiple paths.--max-size
or -m
: The maximum allowed size (a positive number). Can be specified multiple times, corresponding to each path.--unit
or -u
: The unit for the size ( B ). If not specified, defaults to B (bytes). Can be specified multiple times, corresponding to each path.--ignore
, -i
Ignore files/directories (can be used multiple times)--help
or -h
: Display the help message.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.
fs-size-checker uses exit codes to communicate the result of the size check:
When a size limit is exceeded, fs-size-checker will:
This approach ensures that:
To set up the project for development:
npm install
npm run build
npm test
Contributions are welcome! Please feel free to submit a Pull Request.
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.