-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·41 lines (33 loc) · 1.17 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { program } from 'commander';
import markdownLint from './index.js';
import { prepareExtensions } from './lib/utils.js';
const dirname = path.dirname(fileURLToPath(import.meta.url));
const { version, description } = JSON.parse(await fs.readFile(path.join(dirname, 'package.json')));
program
.option('--fix', 'Automatically fix problems')
.option('--ext <value>', 'Specify file extensions', prepareExtensions, ['md', 'MD'])
.option('-t, --typograph', 'Enable typograph')
.option('-r, --recursive', 'Get files from provided directory and the entire subtree')
.option('-c, --config <file>', 'Use this configuration, overriding default options if present');
program
.usage('[options] <dir> <file ...>')
.version(version, '-v, --version')
.description(description)
.parse(process.argv);
if (program.args.length === 0) {
program.help();
} else {
const options = program.opts();
markdownLint({
paths: program.args,
fix: options.fix,
ext: options.ext,
recursive: options.recursive,
config: options.config,
typograph: options.typograph,
});
}