Skip to content

Commit

Permalink
Adjust colors and account for unicode when padding
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahmanor committed Aug 4, 2016
1 parent cfc4325 commit 6b6d7ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"promise": "7.1.1",
"recursive-readdir": "^2.0.0",
"rimraf": "2.5.4",
"strip-ansi": "^3.0.1",
"style-loader": "0.13.1",
"url-loader": "0.5.7",
"webpack": "1.13.1",
Expand Down
24 changes: 15 additions & 9 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var webpack = require('webpack');
var config = require('../config/webpack.config.prod');
var paths = require('../config/paths');
var recursive = require('recursive-readdir');
var stripAnsi = require('strip-ansi');

function removeFileNameHash(fileName) {
return fileName.replace(paths.appBuild, '')
Expand All @@ -28,13 +29,17 @@ function removeFileNameHash(fileName) {
}

function sizeDifference(currentSize, previousSize) {
if (previousSize === undefined) { return ''; }
var FIFTY_KILOBYTES = 1024 * 50;
var difference = currentSize - previousSize;
var fileSize = filesize(difference);
if (difference > 0) {
var fileSize = !Number.isNaN(difference) ? filesize(difference) : 0;
if (difference >= FIFTY_KILOBYTES) {
return chalk.red('+' + fileSize);
} else if (difference <= 0){
return chalk.green((difference === 0 ? '+' : '') + fileSize);
} else if (difference < FIFTY_KILOBYTES && difference > 0) {
return chalk.yellow('+' + fileSize);
} else if (difference < 0) {
return chalk.green(fileSize);
} else {
return '';
}
}

Expand Down Expand Up @@ -86,16 +91,17 @@ function build(previousSizeMap) {
assets.sort((a, b) => b.size - a.size);

var longestSizeLabelLength = Math.max.apply(null,
assets.map(a => a.sizeLabel.length)
assets.map(a => stripAnsi(a.sizeLabel).length)
);
assets.forEach(asset => {
var sizeLabel = asset.sizeLabel;
if (sizeLabel.length < longestSizeLabelLength) {
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLabel.length);
var sizeLength = stripAnsi(sizeLabel).length;
if (sizeLength < longestSizeLabelLength) {
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength);
sizeLabel += rightPadding;
}
console.log(
' ' + chalk.yellow(sizeLabel) +
' ' + sizeLabel +
' ' + chalk.dim(asset.folder + path.sep) + chalk.cyan(asset.name)
);
});
Expand Down

0 comments on commit 6b6d7ee

Please sign in to comment.