Skip to content

Instantly share code, notes, and snippets.

@kribblo
Last active February 27, 2019 12:40
Show Gist options
  • Save kribblo/bd3fb5531acabd01c0b3cffe47306b4d to your computer and use it in GitHub Desktop.
Save kribblo/bd3fb5531acabd01c0b3cffe47306b4d to your computer and use it in GitHub Desktop.
Check minimum size of a file on command line (node) or in npm run scripts
#!/usr/bin/env node
const fs = require('fs');
if(process.argv.length < 4) {
console.error('Usage:', 'node check-size.js file size');
process.exit(1);
}
const file = process.argv[2];
const minSize = process.argv[3];
const stat = fs.statSync(file);
if(stat.size < minSize) {
console.error(file, 'is', stat.size, 'bytes, which is smaller than', minSize);
process.exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment