mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Command-line interface for markdownlint
This commit is contained in:
parent
1e23d035ce
commit
4a4ac0d189
2 changed files with 77 additions and 2 deletions
67
bin/markdownlint-cli.js
Normal file
67
bin/markdownlint-cli.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
"use strict";
|
||||
|
||||
/* eslint no-console:0, no-process-exit:0 */
|
||||
|
||||
var pkg = require("../package");
|
||||
var program = require("commander");
|
||||
|
||||
function readConfiguration(args) {
|
||||
var rc = require("rc");
|
||||
var config = rc(pkg.name, {});
|
||||
if (args.config) {
|
||||
var fs = require("fs");
|
||||
try {
|
||||
var userConfig = JSON.parse(fs.readFileSync(args.config));
|
||||
var extend = require("deep-extend");
|
||||
config = extend(config, userConfig);
|
||||
} catch (e) {
|
||||
console.warn("Cannot read or parse config file", args.config);
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
function lint(lintFiles, config) {
|
||||
var markdownlint = require("../" + pkg.main);
|
||||
var lintOptions = {
|
||||
"files": lintFiles,
|
||||
"config": config
|
||||
};
|
||||
return markdownlint.sync(lintOptions);
|
||||
}
|
||||
|
||||
function printResult(lintResult) {
|
||||
// var chalk = require("chalk");
|
||||
console.log(lintResult.toString());
|
||||
}
|
||||
|
||||
function isResultCorrect(lintResult) {
|
||||
var _ = require("lodash");
|
||||
function notEmptyObject(item) {
|
||||
return !_.isEqual(item, {});
|
||||
}
|
||||
return _.values(lintResult).some(notEmptyObject);
|
||||
}
|
||||
|
||||
program
|
||||
.version(pkg.version)
|
||||
.description(pkg.description)
|
||||
.usage("[options] <files>")
|
||||
.option("-c, --config [configFile]", "Configuration file");
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
var files = program.args;
|
||||
|
||||
if (files && files.length > 0) {
|
||||
var config = readConfiguration(program);
|
||||
var lintResult = lint(files, config);
|
||||
printResult(lintResult);
|
||||
if (isResultCorrect(lintResult)) {
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
program.help();
|
||||
}
|
||||
12
package.json
12
package.json
|
|
@ -11,16 +11,24 @@
|
|||
"url": "https://github.com/DavidAnson/markdownlint.git"
|
||||
},
|
||||
"bugs": "https://github.com/DavidAnson/markdownlint/issues",
|
||||
"bin": {
|
||||
"markdownlint": "./bin/markdownlint-cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node ./bin/markdownlint-cli.js",
|
||||
"test": "nodeunit",
|
||||
"test-cover": "istanbul cover node_modules/nodeunit/bin/nodeunit",
|
||||
"debug": "node debug node_modules/nodeunit/bin/nodeunit",
|
||||
"lint": "eslint lib test && eslint --env browser --global markdownit --global markdownlint --rule \"no-unused-vars: 0, no-extend-native: 0, max-statements: 0, no-console: 0\" demo && eslint --rule \"no-console: 0, no-shadow: 0\" example",
|
||||
"lint": "eslint lib test bin && eslint --env browser --global markdownit --global markdownlint --rule \"no-unused-vars: 0, no-extend-native: 0, max-statements: 0, no-console: 0\" demo && eslint --rule \"no-console: 0, no-shadow: 0\" example",
|
||||
"build-demo": "cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && cpy file-header.js . --rename=markdownlint-browser.js && browserify browser-polyfills.js ../lib/markdownlint.js --standalone markdownlint >> markdownlint-browser.js && uglifyjs markdownlint-browser.js --compress --mangle --comments --output markdownlint-browser.min.js",
|
||||
"example": "npm install through2 && cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint"
|
||||
},
|
||||
"dependencies": {
|
||||
"markdown-it": "^5.1.0"
|
||||
"commander": "~2.9.0",
|
||||
"deep-extend": "~0.4.1",
|
||||
"lodash": "~3.10.1",
|
||||
"markdown-it": "^5.1.0",
|
||||
"rc": "~1.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^13.0.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue