-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
43 lines (36 loc) · 1022 Bytes
/
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
42
43
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const meow = require('meow');
const linkReplacer = require('./index.js');
const cli = meow({
help: [
'Usage',
' $ markdown-plain-link-replacer "<markdown>"',
'',
'Example',
' $ markdown-plain-link-replacer " http://starwars.wikia.com/wiki/Bespin "'
]
});
function executeCliLogic() {
if (cli && cli.flags && cli.flags.h) {
return;
}
const templateString = cli.flags.t;
const filePath = cli.flags.i;
function replaceLinksCallback(newMarkdown) {
console.log(newMarkdown);
}
function executeLinkReplace(markdown, template) {
linkReplacer.replacePlainLinks(markdown, replaceLinksCallback, template);
}
function afterFileReadExecuteLinkReplace(secondInputErr, fileText) {
executeLinkReplace(fileText, templateString);
}
if (filePath) {
fs.readFile(filePath, 'utf8', afterFileReadExecuteLinkReplace);
} else {
executeLinkReplace(cli.input[0], templateString);
}
}
executeCliLogic();