-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolves #17, Resolves #18, Support --destination-dir --out-file #33
Conversation
lib/converter.js
Outdated
} finally { | ||
if (outputToStdout && await existsFile(outputFile)) { | ||
console.log(await readFile(outputFile, 'utf-8')) | ||
await removeFile(outputFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious: does JavaScript have some kind of try-with-resources (as in Java) / with (as in Python) analogue? As written, there's a theoretical possibility that readFile
throws, and outFile
doesn't get removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it seems like we should close browser in finally as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious: does JavaScript have some kind of try-with-resources (as in Java) / with (as in Python) analogue?
As far as I know no 😞
As written, there's a theoretical possibility that readFile throws, and outFile doesn't get removed.
Yes you're right, I should probably add another try/catch
block.
Also, it seems like we should close browser in finally as well?
I'm using await browser.close()
in the finally
block but since readFile
can throw an exception...
lib/converter.js
Outdated
await removeFile(outputFile) | ||
} | ||
// QUESTION: should we remove the temporary HTML file ? | ||
// It useful when building a new layout but the converter should only output a PDF file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use temp html file for live preview: I open it in browser with autoreload. I think I can use something similar with PDF.
Perhaps we need to delete html by default, but then, for html-preview specifically, have a flag --generate-only-html
?
OTOH, if PDF generation is not significanly slower then html generation, perhaps I can adjust my workflow to preview PDFs direclty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use temp html file for live preview: I open it in browser with autoreload. I think I can use something similar with PDF.
Indeed but the major drawback is that it can be harder to debug/prototype.
I'm using the dev tools a lot when I create a new layout.
Perhaps we need to delete html by default, but then, for html-preview specifically, have a flag --generate-only-html?
Why not...
The HTML page is an intermediate step so maybe --keep-html
?
OTOH, if PDF generation is not significantly slower then html generation, perhaps I can adjust my workflow to preview PDFs directly?
It depends on the size or your document but the PDF generation is relatively fast.
Hm, shoudn't this be |
I need to try, maybe if it's supported by https:/yargs/yargs but if it is then yes we should use |
Thanks for your review @matklad (greatly appreciated). I will update my pull request 👍 |
@matklad It's working with |
I've added two functions |
4e73b26
to
9cd48c5
Compare
9cd48c5
to
b2b9d81
Compare
b2b9d81
to
f991416
Compare
ping @matklad 😉
So the following is supported:
Will create
foo
,bar
andbaz
directories (if they don't exist).Will output the result (pdf content) to the console
Will create
foo
,bar
andbaz
directories (if they don't exist).Will create a file named
book.pdf
Please note that for now we do not remove the temporary HTML file (to ease development/debugging).
Also the temporary HTML file is always created next to the input file. So you don't have to update the relative paths when you want to output the PDF file somewhere else.