Skip to content

Commit

Permalink
Add silent option (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnCuppens authored and sindresorhus committed Nov 12, 2019
1 parent dfdba76 commit 0460c78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = (plugins, options) => {

options = {
// TODO: Remove this when Gulp gets a real logger with levels
silent: process.argv.includes('--silent'),
verbose: process.argv.includes('--verbose'),
...options
};
Expand Down Expand Up @@ -102,14 +103,17 @@ module.exports = (plugins, options) => {
}
})();
}, callback => {
const percent = totalBytes > 0 ? (totalSavedBytes / totalBytes) * 100 : 0;
let msg = `Minified ${totalFiles} ${plur('image', totalFiles)}`;
if (!options.silent) {
const percent = totalBytes > 0 ? (totalSavedBytes / totalBytes) * 100 : 0;
let msg = `Minified ${totalFiles} ${plur('image', totalFiles)}`;

if (totalFiles > 0) {
msg += chalk.gray(` (saved ${prettyBytes(totalSavedBytes)} - ${percent.toFixed(1).replace(/\.0$/, '')}%)`);
if (totalFiles > 0) {
msg += chalk.gray(` (saved ${prettyBytes(totalSavedBytes)} - ${percent.toFixed(1).replace(/\.0$/, '')}%)`);
}

log(`${PLUGIN_NAME}:`, msg);
}

log(`${PLUGIN_NAME}:`, msg);
callback();
});
};
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,12 @@ Enabling this will log info on every image passed to `gulp-imagemin`:
gulp-imagemin: ✔ image1.png (already optimized)
gulp-imagemin: ✔ image2.png (saved 91 B - 0.4%)
```

##### silent

Type: `boolean`<br>
Default: `false`

Don't log the number of images that have been minified.

You can also enable this from the command-line with the `--silent` flag if the option is not already specified.

0 comments on commit 0460c78

Please sign in to comment.