-
Notifications
You must be signed in to change notification settings - Fork 2
/
h2md.js
56 lines (42 loc) · 1.15 KB
/
h2md.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
const fs = require("fs");
const path = require("path");
const minimist = require('minimist');
const tokenizer = require("./lib/tokenizer.js");
const generator = require("./lib/generator.js");
const args = minimist(process.argv.slice(2), {
boolean: ["help", "line", "file"],
alias: {
"h": "help",
"p": "pattern",
"o": "output",
"l": "line",
"f": "file"
}
});
if (args.help) {
console.log(fs.readFileSync(__dirname + "/help.txt").toString().trim());
return;
}
if (args._.length != 1) {
console.error("No file.");
return;
}
var text = fs.readFileSync(args._[0]).toString();
var tokens = tokenizer.parseCode(text);
var g = new generator.Generator({
addLineNumber: args.line,
addFileHeader: args.file,
file: path.basename(args._[0])
});
if (args.pattern === undefined) {
args.pattern = "cpp"; // default pattern
}
require(`./lib/patterns/${args.pattern}.js`).applyToGenerator(g);
g.generate(tokens);
var md = g.doc.join("\n");
if (args.o) {
fs.writeFileSync(args.o, md);
} else {
console.log(md);
}
//console.log(tokens);