Skip to content

Commit 706e262

Browse files
authored
Merge pull request #3 from nextbitlabs/add-in-out-flags
Add flags -i and -o
2 parents d17e4a6 + 7da25af commit 706e262

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

index.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ const cli = meow({
1919
onepunch serve
2020
Open the presentation in the browser.
2121
22-
onepunch print
22+
onepunch print [-i htmlfile] [-o pdffile]
2323
Print the presentation in a PDF file.
2424
2525
OPTIONS
2626
-n or --name directory_name
2727
Specify the name of the directory where the project is initialized. Defaults to onepunch-presentation.
28+
29+
-i or --input htmlfile
30+
Specify the HTML file to print, defaults to "index.html".
31+
32+
-o or --output pdffile
33+
Specify the name of the PDF file in output, defaults to "index.pdf".
2834
2935
--version
3036
Display the version number.
@@ -38,6 +44,16 @@ const cli = meow({
3844
default: 'onepunch-presentation',
3945
alias: 'n',
4046
},
47+
input: {
48+
type: 'string',
49+
default: 'index.html',
50+
alias: 'i',
51+
},
52+
output: {
53+
type: 'string',
54+
default: 'index.pdf',
55+
alias: 'o',
56+
},
4157
},
4258
});
4359

@@ -49,7 +65,7 @@ switch (cli.input[0]) {
4965
serve();
5066
break;
5167
case 'print':
52-
print();
68+
print(cli.flags);
5369
break;
5470
default:
5571
cli.showHelp();
@@ -78,7 +94,9 @@ function init(flags) {
7894
fs.copySync(path.resolve(__dirname, 'template'), presentationPath);
7995
}
8096

81-
function print() {
97+
function print(flags) {
98+
const {input, output} = flags;
99+
82100
liveServer.start({
83101
port: 8181,
84102
root: process.cwd(),
@@ -93,9 +111,9 @@ function print() {
93111
(async () => {
94112
const browser = await puppeteer.launch();
95113
const page = await browser.newPage();
96-
await page.goto('http://127.0.0.1:8181/index.html');
114+
await page.goto(`http://127.0.0.1:8181/${input}`);
97115
await page.pdf({
98-
path: 'index.pdf',
116+
path: output,
99117
width,
100118
height,
101119
printBackground: true,

0 commit comments

Comments
 (0)