-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcmd.js
More file actions
53 lines (46 loc) · 1.24 KB
/
cmd.js
File metadata and controls
53 lines (46 loc) · 1.24 KB
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
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const pify = require('pify');
const minimist = require('minimist');
const globby = require('globby');
const getStdin = require('get-stdin');
const ghmd = require('.');
const fsP = pify(fs);
const argv = minimist(process.argv.slice(2), {
alias: {
d: 'dest',
t: 'template',
h: 'help',
v: 'version'
}
});
if (argv.v || argv.version) {
process.stdout.write(require('./package').version + '\n');
process.exit();
} else if (argv.h || argv.help) {
process.stdout.write(fs.readFileSync('./usage.txt'));
process.exit();
}
if (argv.stdin) {
getStdin().then(string => {
process.stdout.write(ghmd(string, {
template: argv.template
}));
});
} else {
globby(argv._).then(inputs => {
const dest = argv.dest ? path.dirname(argv.dest) : process.cwd();
for (const input of inputs) {
const output = path.resolve(dest, `${path.basename(input, '.md')}.html`);
convert(input, argv.template, output);
}
});
}
function convert(input, template, output) {
return fsP.readFile(input)
.then(buffer => buffer.toString())
.then(markdown => ghmd(markdown, {template}))
.then(html => fsP.writeFile(output, html));
}