Skip to content

Commit 0460c78

Browse files
MartijnCuppenssindresorhus
authored andcommittedNov 12, 2019
Add silent option (#331)
1 parent dfdba76 commit 0460c78

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed
 

‎index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = (plugins, options) => {
3939

4040
options = {
4141
// TODO: Remove this when Gulp gets a real logger with levels
42+
silent: process.argv.includes('--silent'),
4243
verbose: process.argv.includes('--verbose'),
4344
...options
4445
};
@@ -102,14 +103,17 @@ module.exports = (plugins, options) => {
102103
}
103104
})();
104105
}, callback => {
105-
const percent = totalBytes > 0 ? (totalSavedBytes / totalBytes) * 100 : 0;
106-
let msg = `Minified ${totalFiles} ${plur('image', totalFiles)}`;
106+
if (!options.silent) {
107+
const percent = totalBytes > 0 ? (totalSavedBytes / totalBytes) * 100 : 0;
108+
let msg = `Minified ${totalFiles} ${plur('image', totalFiles)}`;
107109

108-
if (totalFiles > 0) {
109-
msg += chalk.gray(` (saved ${prettyBytes(totalSavedBytes)} - ${percent.toFixed(1).replace(/\.0$/, '')}%)`);
110+
if (totalFiles > 0) {
111+
msg += chalk.gray(` (saved ${prettyBytes(totalSavedBytes)} - ${percent.toFixed(1).replace(/\.0$/, '')}%)`);
112+
}
113+
114+
log(`${PLUGIN_NAME}:`, msg);
110115
}
111116

112-
log(`${PLUGIN_NAME}:`, msg);
113117
callback();
114118
});
115119
};

‎readme.md

+9
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,12 @@ Enabling this will log info on every image passed to `gulp-imagemin`:
118118
gulp-imagemin: ✔ image1.png (already optimized)
119119
gulp-imagemin: ✔ image2.png (saved 91 B - 0.4%)
120120
```
121+
122+
##### silent
123+
124+
Type: `boolean`<br>
125+
Default: `false`
126+
127+
Don't log the number of images that have been minified.
128+
129+
You can also enable this from the command-line with the `--silent` flag if the option is not already specified.

0 commit comments

Comments
 (0)
Please sign in to comment.