-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·86 lines (69 loc) · 1.74 KB
/
index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
'use strict';
const path = require('path');
const fs = require('fs');
const chalk = require('chalk');
const meow = require('meow');
const Ora = require('ora');
const Promise = require('bluebird');
const MDify = require('./mdify');
Promise.promisifyAll(fs); // eslint-disable-line no-use-extend-native/no-use-extend-native
const cli = meow(
` ${chalk.bold('Usage')}
$ mdify <source> [<destination>] [options]
${chalk.bold('Options')}
--debug When this is set the intermediate HTML will be saved into a file.
--open Open the generated markdown file.
--silent Mute all output.
--images Output images as files
${chalk.bold('Examples')}
$ mdify foo.docx
$ mdify foo.docx foo.md --open
`,
{
alias: {
d: 'debug',
o: 'open',
s: 'silent',
i: 'images'
}
}
);
const silent = cli.flags.silent || false;
const ora = new Ora({
color: 'blue'
});
const failExit = msg => {
ora.fail(msg);
process.exit(1);
};
const source = cli.input[0];
if (!source) {
failExit(`${chalk.dim('<source>')} must be defined`);
}
const destination =
cli.input[1] ||
path.resolve(source.slice(0, source.indexOf('.docx')) + '.md');
const debug = cli.flags.debug ?
destination.slice(0, destination.indexOf('.md')) + '.html' :
false;
const config = {
source: path.resolve(source),
destination,
debug,
open: cli.flags.open || false,
images: cli.flags.images || false,
silent
};
const mdify = new MDify(config);
mdify.makeHTML().then(html => {
const markdown = mdify.makeMD(html, ora);
if (!silent) {
if (debug) {
ora.info(`created HTML ${chalk.blue(debug)}`);
}
Ora.promise(markdown, {
text: `creating markdown ${chalk.blue(destination)}`
});
}
});