forked from danburzo/percollate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·134 lines (92 loc) · 2.88 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env node
'use strict';
const pkg = require('./package.json');
const cliopts = require('./src/cli-opts');
const { pdf, epub, html } = require('./index');
const { command, opts, operands } = cliopts(process.argv.slice(2));
if (opts.debug) {
console.log({
command,
operands,
opts
});
}
if (opts.version) {
console.log(pkg.version);
process.exit(0);
}
if (opts.help) {
outputHelp();
}
if (!command || !operands.length) {
outputHelp();
}
switch (command) {
case 'pdf':
pdf(operands, opts);
break;
case 'epub':
epub(operands, opts);
break;
case 'html':
html(operands, opts);
break;
default:
outputHelp();
}
/*
Help & version
--------------
*/
function outputHelp() {
console.log(
`percollate v${pkg.version}
Usage: percollate <command> [options] url [url]...
Commands:
pdf Bundle web pages as a PDF file
epub Bundle web pages as an EPUB file.
html Bundle web pages as a HTML file.
Commmon options:
-h, --help Output usage information.
-V, --version Output program version.
--debug Print more detailed information.
-o <output>, Path for the generated bundle.
--output=<path>
--template=<path> Path to a custom HTML template.
--style=<path> Path to a custom CSS file.
--css=<style> Additional inline CSS style.
-u, --url=<url> Sets the base URL when HTML is provided on stdin.
Multiple URL options can be specified.
-t <title>, The bundle title.
--title=<title>
-a <author>, The bundle author.
--author=<title>
--individual Export each web page as an individual file.
--toc Generate a Table of Contents.
Implicitly enabled when bundling more than one item.
--cover Generate a cover for the PDF / EPUB.
Implicitly enabled when bundling more than one item
or the --title option is provided.
Options to disable features:
--no-amp Don't prefer the AMP version of the web page.
--no-toc Don't generate a table of contents.
--no-cover Don't generate a cover.
PDF options:
--no-sandbox Passed to Puppeteer.
Operands:
percollate accepts one or more URLs.
Use the hyphen character ('-') to specify
that the HTML should be read from stdin.
Examples:
Single web page to PDF:
percollate pdf --output my.pdf https://example.com
Single web page read from stdin to PDF:
curl https://example.com | percollate pdf -o my.pdf -u 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
`
);
process.exit(0);
}