Permalink
Browse files

Beautify the CLI output

  • Loading branch information...
1 parent 66344be commit 200fe6a302726c9a45688d5ee747976518ec4169 刘祺 committed Nov 30, 2016
Showing with 29 additions and 21 deletions.
  1. +25 −17 bin/cli.js
  2. +2 −2 lib/params.js
  3. +2 −2 package.json
View
@@ -161,26 +161,34 @@ function isCss (filePath) {
function handleDiff (file, original, formatted) {
+ var diff
+ var chalk = require('chalk')
+
if (original === formatted) {
- return file + '\nThere is no difference with the original file.'
+ diff = 'There is no difference with the original file.'
}
- var chalk = require('chalk')
if (chalk.supportsColor) {
- var JsDiff = require('diff')
- var diff = JsDiff.diffChars(original, formatted).map(function (part) {
- var value = part.value
- if (part.added) {
- value = chalk.bgGreen(part.value)
- } else if(part.removed) {
- value = chalk.bgRed(part.value)
- } else {
- return value
- }
- return value
- }).join('')
- return file + chalk.black.bgWhite('\n' + diff)
- } else {
- return file + '\n' + formatted
+ file = chalk.blue(file)
+ if(diff) {
+ diff = chalk.gray(diff)
+ } else {
+ var JsDiff = require('diff')
+ diff = JsDiff.createPatch(file, original, formatted)
+ diff = diff.split('\n').splice(4).map(function (line) {
+ if (line[0] === '+') {
+ line = chalk.green(line)
+ } else if (line[0] === '-') {
+ line = chalk.red(line)
+ } else if (line.match(/^@@\s+.+?\s+@@/) || '\\ No newline at end of file' === line) {
+ line = ''
+ }
+ return chalk.gray(line)
+ })
+ diff = diff.join('\n').trim()
+ }
+ } else if (!diff) {
+ diff = formatted
}
+ return file + '\n' + diff
}
View
@@ -52,11 +52,11 @@ function getIndentationFromStylelintRules (rules) {
}
function loadConfig (stylelint, file, options) {
- return stylelint.isPathIgnored(file, options.configFile).then(function (isIgnored) {
+ return stylelint.isPathIgnored(file).then(function (isIgnored) {
if (isIgnored) {
return null
}
- return stylelint.getConfigForFile(file, options.configFile).then(function (stylelintrc) {
+ return stylelint.getConfigForFile(file).then(function (stylelintrc) {
return stylelintrc && stylelintrc.config && stylelintrc.config.rules
})
}).catch(function (err) {
View
@@ -32,7 +32,7 @@
"dependencies": {
"chalk": "^1.1.3",
"css-color-list": "0.0.1",
- "diff": "^3.0.1",
+ "diff": "^3.1.0",
"editorconfig": "^0.13.2",
"globby": "^6.1.0",
"minimist": "^1.2.0",
@@ -45,7 +45,7 @@
},
"devDependencies": {
"each-series": "^1.0.0",
- "eslint": "^3.10.1",
+ "eslint": "^3.11.1",
"faucet": "0.0.1",
"klaw": "^1.3.1",
"tape": "^4.6.2"

0 comments on commit 200fe6a

Please sign in to comment.