Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Pretty print filesize change in terminal #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions tasks/postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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.');
}
Expand Down