-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbin.js
executable file
·66 lines (55 loc) · 1.16 KB
/
bin.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
'use strict';
const execa = require('execa');
const meow = require('meow');
const path = require('path');
const help = `
Usage
kramer [options] [path|glob...]
By default, runs on all Markdown files in cwd.
Options
-f, --format Format files instead of linting them.
Examples
kramer
kramer docs/*.md
kramer --format "docs/**/*.md"
`;
const cli = meow(help, {
description: 'Lint or format Markdown files.',
flags: {
format: {
type: 'boolean',
alias: 'f',
},
},
});
let files = cli.input;
if (files.length === 0) {
files = [process.cwd()];
}
const command = process.env.LOCAL_TEST
? path.join(__dirname, 'node_modules/.bin/remark')
: 'remark';
const result = execa.sync(
command,
files.concat(
'--use',
path.join(__dirname, 'index.js'),
[
`--no-stdout`,
cli.flags.format ? '--output' : '',
cli.flags.format ? '--silent' : '--quiet',
].filter(Boolean),
),
);
if (result.stderr) {
console.error(result.stderr);
process.exit(1);
}
if (result.error) {
console.error(result.error);
process.exit(1);
}
if (result.stdout) {
console.log(result.stdout);
}