forked from danburzo/percollate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
Β·75 lines (57 loc) Β· 1.95 KB
/
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
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
#!/usr/bin/env node
const program = require('commander');
const pkg = require('./package.json');
const { configure, pdf, epub, html } = require('.');
/*
Some setup
----------
*/
configure();
/*
Command-Line Interface definition
---------------------------------
*/
function with_common_options(cmd) {
return cmd
.option('-b, --blueprint [blueprint]', 'Path to the blueprint')
.option('-o, --output [output]', 'Path for the generated bundle')
.option('--template [template]', 'Path to custom HTML template')
.option('--style [stylesheet]', 'Path to custom CSS')
.option('--css [style]', 'Additional CSS style')
.option('--individual', 'Export each web page as an individual file')
.option('--cover', 'Generate Cover')
.option('--toc', 'Generate TOC')
.option('--no-amp', "Don't prefer the AMP version of the web page");
}
program.version(pkg.version);
with_common_options(program.command('pdf [urls...]'))
.option('--no-sandbox', 'Passed to Puppeteer')
.description('Bundle web pages as a PDF file')
.action(pdf);
with_common_options(program.command('epub [urls...]'))
.description('Bundle web pages as an EPUB file')
.action(epub);
with_common_options(program.command('html [urls...]'))
.description('Bundle web pages as a HTML file')
.action(html);
// with_common_options(
// program.command('', 'default command', { isDefault: true })
// ).action(() => {
// program.outputHelp();
// });
program.on('--help', () => {
console.log(`
Examples:
Single web page to PDF:
percollate pdf --output my.pdf https://example.com
Several web pages to a single PDF:
percollate pdf --output my.pdf https://example.com/1 https://example.com/2
Custom page size and font size:
percollate pdf --output my.pdf --css "@page { size: A3 landscape } html { font-size: 18pt }" https://example.com
`);
});
program.parse(process.argv);
// Show help by default when no arguments provided
if (!program.args.length) {
program.outputHelp();
}