UNPKG

1.31 kBJavaScriptView Raw
1const documentation = require('../');
2const fs = require('fs');
3const path = require('path');
4const sharedOptions = require('./shared_options');
5
6/* eslint no-console: 0 */
7
8module.exports.command = 'lint [input..]';
9module.exports.description = 'check for common style and uniformity mistakes';
10module.exports.builder = {
11 shallow: sharedOptions.sharedInputOptions.shallow
12};
13
14/**
15 * Wrap around the documentation.lint method and add the additional
16 * behavior of printing to stdout and setting an exit status.
17 *
18 * @param {Object} argv cli arguments
19 * @returns {undefined} has side-effects
20 * @private
21 */
22module.exports.handler = function(argv) {
23 argv._handled = true;
24 if (!argv.input.length) {
25 try {
26 argv.input = [
27 JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'))
28 .main || 'index.js'
29 ];
30 } catch (e) {
31 throw new Error(
32 'documentation was given no files and was not run in a module directory'
33 );
34 }
35 }
36 documentation
37 .lint(argv.input, argv)
38 .then(lintOutput => {
39 if (lintOutput) {
40 console.log(lintOutput);
41 process.exit(1);
42 } else {
43 process.exit(0);
44 }
45 })
46 .catch(err => {
47 /* eslint no-console: 0 */
48 console.error(err);
49 process.exit(1);
50 });
51};