Allow CLI to read a diagram from stdin and write the result to stdout #2543
Replies: 5 comments
-
So, you mean implement a node app instead of the desktop tool? Do you want https://github.com/jgraph/draw-image-export2 ? |
Beta Was this translation helpful? Give feedback.
-
I was under the impression that Also await page.goto((process.env.DRAWIO_SERVER_URL || 'https://viewer.diagrams.net') + '/export3.html', {waitUntil: 'networkidle0'}); |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
👌🏻
So the static resources are available here https://github.com/jgraph/drawio/tree/dev/src/main/webapp right? In theory, I only need to serve the following files:
Is that correct? |
Beta Was this translation helpful? Give feedback.
-
Yes, that look like the right list (you'll soon find out if one is missing :) ). |
Beta Was this translation helpful? Give feedback.
-
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:
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: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
:Similarly, if we want to explicitly output to stdout then we can use the value
-
: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
andget-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.
Beta Was this translation helpful? Give feedback.
All reactions