-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
75 lines (70 loc) · 1.68 KB
/
index.ts
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
import { setupHtml, renderToPDF, renderToHTML } from './lib';
import path from 'path';
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
interface Arguments {
[x: string]: unknown;
_: unknown;
data: string;
template: string;
output: string;
position: string | undefined;
}
const options = {
data: {
alias: 'd',
demandOption: true,
describe: 'your data',
type: 'string',
nargs: 1,
},
template: {
alias: 't',
demandOption: true,
describe: 'template to use',
type: 'string',
nargs: 1,
},
output: {
alias: 'o',
demandOption: true,
describe: 'output file (.pdf, .html)',
type: 'string',
nargs: 1,
},
position: {
alias: 'p',
describe: 'position to filter for',
type: 'string',
nargs: 1,
},
};
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/28061
const argv: Arguments = yargs(hideBin(process.argv))
.usage('Usage: $0 -d DATA -t TEMPLATE -o OUTPUT')
.example(
'$0 -d content.yml -t templates/aeolyus -o output.pdf',
'fill out template/aeolyus with content.yml and output a PDF to output.pdf'
)
.example(
'$0 -d content.yml -t templates/aeolyus -o output.html',
'fill out template/aeolyus with content.yml and output HTML to output.html'
)
// @ts-ignore
.options(options)
.help('h')
.alias('h', 'help')
.version('v')
.alias('v', 'version')
.parseSync() as unknown as Arguments;
setupHtml(argv).then((html) => {
switch (path.extname(argv.output)) {
case '.pdf':
return renderToPDF(html, argv);
case '.html':
return renderToHTML(html, argv);
default:
return renderToHTML(html, argv);
}
});
export { Arguments };