Allow CLI to read a diagram from stdin and write the result to stdout
See original GitHub issue- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Is your feature request related to a problem? Please describe.
The diagrams.net (Electron-based) CLI is very useful but I would like to read a diagram from stdin and write the output to stdout to avoid file manipulations.
It would be particularly useful when executing the CLI from a program. For instance, let’s say that I want to write a small HTTP service on top of the CLI. I will receive the input diagram as a request body and I want to write the result in the response. In this case, I don’t want to:
- write a temporary input file to the disk,
- execute the command,
- read the generated output file,
- delete both the input and output file
It would be more efficient to execute the command with the input file as stdin and to read the result from stdout. No file manipulation.
Describe the solution you’d like
When exporting a single input file to a single output file, we could allow diagrams.net CLI to read it from stdin and output the result to stdout.
By convention, command-line interfaces usually use -
(dash character), for instance:
cat input.xml | drawio --export --format svg -
The above command will read the diagram from stdin.
It’s also common to output to stdout (by default) when the input is read from stdin.
In other words, the above command will output to stdout by default, but the following command will output to output.svg
:
cat input.xml | drawio --export --format svg --output output.svg -
Similarly, if we want to explicitly output to stdout then we can use the value -
:
drawio --export --format svg --output - input.xml
Please note that the value of the parameter output
is -
.
Describe alternatives you’ve considered
I guess writing my own CLI inspired by electron.js
but that would be a maintenance burden.
For reference, I did try to create a simple CLI based on Puppeteer (instead of Electron)
but I had to make some changes to export.js in order to be able
to call the right functions from Puppeteer (most notably render
and get-svg-data
callback).
If this is something that you would like to support (i.e., providing both an Electron-based CLI and a Puppeteer-based CLI) then I would gladly help. I know that diagrams.net is closed to contributions but let me know if I can be of any help.
Additional context
I’m working on https://kroki.io and I would like to provide an API to convert diagrams.net XML files to PNG, JPEG or SVG images (and potentially PDF and VSDX). As far as I understand, diagrams.net is using the browser (client-side JavaScript) to convert diagrams to images. So, I’m looking for a self-contained and lightweight solution to provide this service server-side.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:16
- Comments:5
Top GitHub Comments
No, that’s the current server-side generation, it’s just we switched to that new architecture in 2018.
It doesn’t rely on anything external, that is the external server. export3.html just happens to be served externally, it could just as well be bundled on that node sever.
Yes, that look like the right list (you’ll soon find out if one is missing 😃 ).