markdownlint-cli
Advanced tools
Comparing version 0.7.1 to 0.8.0
@@ -8,2 +8,3 @@ #!/usr/bin/env node | ||
var program = require('commander'); | ||
var getStdin = require('get-stdin'); | ||
var differenceWith = require('lodash.differencewith'); | ||
@@ -66,11 +67,2 @@ var flatten = require('lodash.flatten'); | ||
function lint(lintFiles, config) { | ||
var lintOptions = { | ||
resultVersion: 2, | ||
files: lintFiles, | ||
config: config | ||
}; | ||
return markdownlint.sync(lintOptions); | ||
} | ||
function printResult(lintResult) { | ||
@@ -89,2 +81,3 @@ var results = flatten(Object.keys(lintResult).map(function (file) { | ||
})); | ||
var lintResultString = ''; | ||
if (results.length > 0) { | ||
@@ -95,6 +88,5 @@ results.sort(function (a, b) { | ||
}); | ||
var lintResultString = results.map(function (result) { | ||
lintResultString = results.map(function (result) { | ||
return result.file + ': ' + result.lineNumber + ': ' + result.names + ' ' + result.description; | ||
}).join('\n'); | ||
console.error(lintResultString); | ||
// Note: process.exit(1) will end abruptly, interrupting asynchronous IO | ||
@@ -107,2 +99,12 @@ // streams (e.g., when the output is being piped). Just set the exit code | ||
} | ||
if (program.output) { | ||
try { | ||
fs.writeFileSync(program.output, lintResultString); | ||
} catch (err) { | ||
console.warn('Cannot write to output file ' + program.output + ': ' + err.message); | ||
process.exitCode = 2; | ||
} | ||
} else if (lintResultString) { | ||
console.error(lintResultString); | ||
} | ||
} | ||
@@ -119,2 +121,4 @@ | ||
.usage('[options] <files|directories|globs>') | ||
.option('-s, --stdin', 'read from STDIN (no files)') | ||
.option('-o, --output [outputFile]', 'write issues to file (no console)') | ||
.option('-c, --config [configFile]', 'configuration file') | ||
@@ -133,8 +137,21 @@ .option('-i, --ignore [file|directory|glob]', 'files to ignore/exclude', concatArray, []); | ||
if (files.length > 0) { | ||
function lintAndPrint(stdin, files) { | ||
var config = readConfiguration(program); | ||
var lintResult = lint(diff, config); | ||
var lintOptions = { | ||
config: config, | ||
files: files || [], | ||
strings: { | ||
stdin: stdin || '' | ||
} | ||
}; | ||
var lintResult = markdownlint.sync(lintOptions); | ||
printResult(lintResult); | ||
} | ||
if ((files.length > 0) && !program.stdin) { | ||
lintAndPrint(null, diff); | ||
} else if ((files.length === 0) && program.stdin) { | ||
getStdin().then(lintAndPrint); | ||
} else { | ||
program.help(); | ||
} |
{ | ||
"name": "markdownlint-cli", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"description": "MarkdownLint Command Line Interface", | ||
@@ -41,6 +41,7 @@ "main": "markdownlint.js", | ||
"deep-extend": "~0.4.1", | ||
"get-stdin": "~5.0.1", | ||
"glob": "~7.0.3", | ||
"lodash.differencewith": "~4.5.0", | ||
"lodash.flatten": "~4.4.0", | ||
"markdownlint": "~0.7.0", | ||
"markdownlint": "~0.8.1", | ||
"rc": "~1.1.6" | ||
@@ -47,0 +48,0 @@ }, |
@@ -24,2 +24,4 @@ # markdownlint-cli [![Travis CI Build Status][travis-badge]][travis-url] [![AppVeyor CI Build Status][appveyor-badge]][appveyor-url] | ||
-V, --version output the version number | ||
-s, --stdin read from STDIN (no files) | ||
-o, --output [outputFile] write issues to file (no console) | ||
-c, --config [configFile] configuration file | ||
@@ -26,0 +28,0 @@ -i, --ignore [file|directory|glob] files to ignore/exclude |
10180
138
74
8
+ Addedget-stdin@~5.0.1
+ Addedget-stdin@5.0.1(transitive)
+ Addedmarkdown-it@8.4.1(transitive)
+ Addedmarkdownlint@0.8.1(transitive)
- Removedmarkdown-it@8.4.0(transitive)
- Removedmarkdownlint@0.7.0(transitive)
Updatedmarkdownlint@~0.8.1