-
Notifications
You must be signed in to change notification settings - Fork 251
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
Support using stdout #725
Support using stdout #725
Conversation
If the user specifies `-` as the output, the code will be written to `stdout` instead of writing to a file. Note that for the sake of making the code more readable, I'm using explicit `'/dev/stdout'`. This is just a personal preference and doesn't have anything to do with platform.
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.
Thanks for implementing this. I've got one minor comment that could potentially slightly simplify the code, but other than this, it looks great to me!
I'm not 100% sure, since it's been a while since I last programmed for Windows, but I think this should even work on Windows too!
Forgot to mention that this feature is blocked by mermaid-js/zenuml-core#169, because the warning is written to |
src/index.js
Outdated
const outputDir = path.dirname(output) | ||
if (!fs.existsSync(outputDir)) { | ||
error(`Output directory "${outputDir}/" doesn't exist`) |
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.
Now that I think about it, maybe we shouldn't check the directory if we're writing to stdout
.
const outputDir = path.dirname(output) | |
if (!fs.existsSync(outputDir)) { | |
error(`Output directory "${outputDir}/" doesn't exist`) | |
if (output !== '/dev/stdout') { | |
const outputDir = path.dirname(output) | |
if (!fs.existsSync(outputDir)) { | |
error(`Output directory "${outputDir}/" doesn't exist`) |
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.
That's a good idea.
Non-Linux operating systems probably won't have a /dev
folder.
If you want to avoid having an extra level of indentation, we could also change the code to the following:
const outputDir = path.dirname(output) | |
if (!fs.existsSync(outputDir)) { | |
error(`Output directory "${outputDir}/" doesn't exist`) | |
const outputDir = path.dirname(output) | |
if (output !== '/dev/stdout' && !fs.existsSync(outputDir)) { | |
error(`Output directory "${outputDir}/" doesn't exist`) |
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.
Noted.
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.
Forgot to mention that this feature is blocked by mermaid-js/zenuml-core#169, because the warning is written to
stdout
notstderr
.
Unfortunately, that's a pretty major issue! As a quick fix, I think we could instead write this message to stderr
instead, by changing the following to use console.warn
instead:
Lines 243 to 245 in 967768c
page.on('console', (msg) => { | |
console.log(msg.text()) | |
}) |
I've also noticed that the recently released Mermaid v11 seems to be logging a lot more information, so it's probably worth having that change anyway!
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.
Awesome! Thanks for making those changes!
It should be released soon with mermaid-cli v11 once #701 is reviewed and merged!
Thanks! |
using mermaid-cli within markdown This feature will be available once mermaid-cli v11 is released ( mermaid-js/mermaid-cli#725 (review) ), so it still fails for now.
Ref: * mermaid-js/mermaid-cli#725 * https://hub.docker.com/r/minlag/mermaid-cli/tags Dropping the whole image building, simply using the upstream pre-built image with options to specify own images and tags. Didn't work on MacOS anyway because `google-chrome-stable` was unavailable on `linux/arm64` platform when building the image. The upstream image supports `linux/arm64` out-of-box, so it *should* work on MacOS.
📑 Summary
Support writing to
stdout
if the user explicitly specifies-
. In case of no output format, it is assumed to besvg
and a warning is displayed.Resolves #683
📏 Design Decisions
For the sake of making the code more readable, I'm using explicit
'/dev/stdout'
. This is just a personal preference and doesn't have anything to do with the platform.I have also disabled writing to
stdout
if the input is markdown.📋 Tasks
Make sure you
master
branch