From 3cfac5d65a977fdf06d1326f06ca3e0fb83e3411 Mon Sep 17 00:00:00 2001 From: axten Date: Sat, 4 Nov 2017 21:28:13 +0100 Subject: [PATCH 1/2] Pretty print filesize compression in terminal using minmax, according to #66 --- tasks/postcss.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tasks/postcss.js b/tasks/postcss.js index b660874..99e2f1b 100644 --- a/tasks/postcss.js +++ b/tasks/postcss.js @@ -4,6 +4,7 @@ var path = require('path'); var postcss = require('postcss'); var diff = require('diff'); var chalk = require('chalk'); +var maxmin = require('maxmin'); module.exports = function(grunt) { var options; @@ -93,7 +94,9 @@ module.exports = function(grunt) { sheets: 0, maps: 0, diffs: 0, - issues: 0 + issues: 0, + sizeBefore: 0, + sizeAfter: 0, }; if (typeof options.processors === 'function') { @@ -125,6 +128,7 @@ module.exports = function(grunt) { Array.prototype.push.apply(tasks, src.map(function(filepath) { var dest = f.dest || filepath; var input = grunt.file.read(filepath); + tally.sizeBefore += input.length; return process(input, filepath, dest).then(function(result) { var warnings = result.warnings(); @@ -136,8 +140,9 @@ module.exports = function(grunt) { }); if (options.writeDest) { + tally.sizeAfter += result.css.length; grunt.file.write(dest, result.css); - log('File ' + chalk.cyan(dest) + ' created.'); + log('File ' + chalk.cyan(dest) + ' created.' + chalk.dim(maxmin(input.length, result.css.length))); } tally.sheets += 1; @@ -170,7 +175,8 @@ module.exports = function(grunt) { Promise.all(tasks).then(function() { if (tally.sheets) { if (options.writeDest) { - grunt.log.ok(tally.sheets + ' processed ' + grunt.util.pluralize(tally.sheets, 'stylesheet/stylesheets') + ' created.'); + var size = chalk.dim(maxmin(tally.sizeBefore, tally.sizeAfter)); + grunt.log.ok(tally.sheets + ' processed ' + grunt.util.pluralize(tally.sheets, 'stylesheet/stylesheets') + ' created. ' + size); } else { grunt.log.ok(tally.sheets + ' ' + grunt.util.pluralize(tally.sheets, 'stylesheet/stylesheets') + ' processed, no files written.'); } From fb4f970e3b8cdfa91ae28ce0079a9a5812d03d9f Mon Sep 17 00:00:00 2001 From: axten Date: Sat, 4 Nov 2017 21:34:53 +0100 Subject: [PATCH 2/2] added minmax dependency --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b2d05ce..219fbd5 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "dependencies": { "chalk": "^2.1.0", "diff": "^3.0.0", - "postcss": "^6.0.11" + "postcss": "^6.0.11", + "maxmin": "^2.1.0" }, "devDependencies": { "cssnano": "^3.3.1",