Skip to content

Commit fabe793

Browse files
committed
Merge pull request #126 from bem/use-chalk
Use chalk
2 parents dbb15f0 + 3b40c8d commit fabe793

42 files changed

Lines changed: 59 additions & 45 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/cli.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
var path = require('path'),
22
vow = require('vow'),
33
vfs = require('vow-fs'),
4-
colors = require('colors'),
4+
chalk = require('chalk'),
5+
boldGreen = chalk.green.bold,
6+
boldRed = chalk.red.bold,
57
HtmlDiffer = require('./index').HtmlDiffer,
68
diffLogger = require('./logger'),
79
defaults = require('./utils/defaults');
@@ -33,8 +35,8 @@ module.exports = require('coa').Cmd()
3335
.long('bem')
3436
.flag()
3537
.act(function (opts) {
36-
console.error('Option ' + '--bem'.bold.red + ' is deprecated, use ' +
37-
'--preset=bem'.bold.green + ' option instead.');
38+
console.error('Option ' + boldRed('--bem') + ' is deprecated, use ' +
39+
boldGreen('--preset=bem') + ' option instead.');
3840
// support legacy
3941
opts.preset = 'bem';
4042
delete opts.bem;
@@ -46,8 +48,10 @@ module.exports = require('coa').Cmd()
4648
.short('p').long('preset')
4749
.val(function (val) {
4850
if (!defaults.presets.hasOwnProperty(val)) {
49-
console.log(val.bold.red + ' is an invalid preset name. Available presets are: ' +
50-
Object.keys(defaults.presets).map(colors.green).map(colors.bold).join(', ') + '.');
51+
console.log(boldRed(val) + ' is an invalid preset name. Available presets are: ' +
52+
Object.keys(defaults.presets).map(function (preset) {
53+
return boldGreen(preset);
54+
}).join(', ') + '.');
5155
process.exit(1);
5256
}
5357
return val;

lib/logger.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
require('colors');
1+
var chalk = require('chalk'),
2+
inverseGreen = chalk.green.inverse,
3+
inverseRed = chalk.red.inverse,
4+
grey = chalk.grey;
25

36
/**
47
* @typedef {Object} Diff
@@ -31,24 +34,24 @@ function getDiffText(diff, options) {
3134
diff.forEach(function (part) {
3235
var index = diff.indexOf(part),
3336
partValue = part.value,
34-
color = 'grey';
37+
diffColor;
3538

36-
if (part.added) color = 'green';
37-
if (part.removed) color = 'red';
39+
if (part.added) diffColor = inverseGreen;
40+
if (part.removed) diffColor = inverseRed;
3841

39-
if (color !== 'grey') {
40-
output += (!index ? '\n' : '') + partValue.inverse[color];
42+
if (diffColor) {
43+
output += (index === 0 ? '\n' : '') + diffColor(partValue);
4144

4245
return;
4346
}
4447

4548
if (partValue.length < charsAroundDiff * 2) {
46-
output += (index ? '' : '\n') + partValue.grey;
49+
output += (index !== 0 ? '' : '\n') + grey(partValue);
4750
} else {
48-
index && (output += partValue.substr(0, charsAroundDiff).grey);
51+
index !== 0 && (output += grey(partValue.substr(0, charsAroundDiff)));
4952

5053
if (index < diff.length - 1) {
51-
output += '\n...\n' + partValue.substr(partValue.length - charsAroundDiff, charsAroundDiff).grey;
54+
output += '\n...\n' + grey(partValue.substr(partValue.length - charsAroundDiff));
5255
}
5356
}
5457
});
@@ -57,7 +60,7 @@ function getDiffText(diff, options) {
5760
}
5861

5962
/**
60-
* Logs diff of the given HTML docs to the console
63+
* Logs the diff of the given HTML docs to the console
6164
* @param {Object[]} diff
6265
* @param {Object} [options]
6366
* @param {Number} [options.charsAroundDiff=40]
@@ -66,7 +69,7 @@ function logDiffText(diff, options) {
6669
var diffText = getDiffText(diff, options);
6770

6871
if (diffText) {
69-
console.log('+ expected'.inverse.green, '- actual'.inverse.red, '\n', diffText);
72+
console.log(inverseGreen('+ expected'), inverseRed('- actual'), '\n', diffText);
7073
}
7174
}
7275

lib/utils/utils.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
var _ = require('lodash');
22

3-
require('colors');
4-
53
/**
64
* Gets the attribute's indexes in the array of the attributes
75
* @param {Array} attrs

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
"url": "git://github.com/bem/html-differ.git"
2828
},
2929
"dependencies": {
30-
"vow": "0.4.3",
31-
"vow-fs": "0.3.1",
30+
"chalk": "1.0.0",
3231
"coa": "0.4.0",
33-
"parse5": "1.1.3",
3432
"diff": "1.0.8",
35-
"colors": "0.6.2",
36-
"lodash": "2.4.1"
33+
"lodash": "2.4.1",
34+
"parse5": "1.1.3",
35+
"vow": "0.4.3",
36+
"vow-fs": "0.3.1"
3737
},
3838
"devDependencies": {
3939
"mocha": "1.18.2",
@@ -43,11 +43,12 @@
4343
"jscs": "1.11.3"
4444
},
4545
"scripts": {
46-
"test": "npm run lint && npm run unit-test && npm run func-test && npm run cover",
46+
"test": "npm run lint && npm run unit-test && npm run func-test && npm run logger-test && npm run cover",
4747
"lint": "jshint . && jscs -c .jscs.js .",
48-
"func-test": "mocha test/diff",
4948
"unit-test": "mocha test/unit",
50-
"cover": "istanbul cover _mocha -- test/unit test/diff"
49+
"func-test": "mocha test/differ",
50+
"logger-test": "mocha test/logger",
51+
"cover": "istanbul cover _mocha -- test/unit test/differ test/logger"
5152
},
5253
"engines": {
5354
"node": ">=0.8.0",
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)