bpmn-io / bpmn-to-image

Convert BPMN 2.0 diagrams to PDF documents or PNG files.
62 stars 38 forks source link

Provide an option to use stdout/stdin instead of files #15

Open Morozzzko opened 4 years ago

Morozzzko commented 4 years ago

Is your feature request related to a problem? Please describe

I'm building a simple integration for BPMN and Jekyll. Here's my use-case:

  1. I write an article, which uses BPMN diagrams
  2. I design said diagrams and export them as .bpmn files
  3. I convert the .bpmn files to .svg and .png and embed them in the article

Since I'm using it from Ruby, I've decided to just call the CLI program and use its output.

However, there's something complicated: I have to perform it in-memory. See how I tackled it:

  1. I create a tempfile and write the original content. It's an XML file with the BPMN diagram
  2. I create another tempfile – I'll use it as a buffer for the CLI
  3. I call bpmn-to-image ${tmpFileWithSource.path}:${tmpFileWithSVG.path}.svg
  4. I read from tmpFileWithSVG

CLI docs haven't given me any other ideas how to proceed

Describe the solution you'd like

I would love to have an option to use standard OS streams for input an output.

Let's see how it might look like:

echo "...some_xml_with_bpmn" | bpmn-to-image --source=stdin --target=stdout

There's a lot of ways to design it, anything will work as long as it lets me use standard stream

Describe alternatives you've considered

Thought about writing a different javascript utility, which doesn't really work as a CLI, but it won't be that good.

Additional context

Since I'm the one who needs this feature, I can code it if you give me a green light

Please keep in mind that right now the CLI looks like it can generate multiple files in a single run. It will be tricky to keep this behavior using the new interface. Alternatively, we could keep those two interfaces, but make them mutually exclusive.

nikku commented 4 years ago

Happy to take a PR that implements this feature.

Morozzzko commented 4 years ago

I think I'll try and introduce a breaking change, then.

I'm thinking it would be reasonable to pick this approach:

I want to change the CLI interface to something like this bpmn-to-image --destination=current_destination_list_format.png,some_other_value.svg source_file

It introduces a breaking change, but empowers us to do lots of things:

  1. It decouples input and output param, so we can extend and evolve each of them separately. The users will need to adjust a little, but it's not going to be too painful
  2. Conventionally, we can omit the last argument (source_file) and pipe something to STDIN. It's pretty idiomatic in unix. Virtually, <file.bpmn | bpmn-to-image --destination=foo.png and bpmn-to-image --destination=foo.png file.bpmn are going to be identical. It's good
  3. We can say that if --destination is not set, it will print to STDOUT. Pretty neat, I think

What do you think about it? I think a breaking change is a bold move, but it's still a zero-version, so why not

nikku commented 4 years ago

The goal of the current CLI is to be able to batch migrate several diagrams.

Is that something that can be kept as a feature with your proposal?

Morozzzko commented 4 years ago

I think we can keep the behavior by using subcommands for different scenarios

$ bpmn-to-image convert --destination=foo.png,svg,somethingelse.pdf single_source.bpmn
$ bpmn-to-image batch diagram.bpmn:svg vertical.bpmn:svg,something.pdf,somethingelse.png

It's going to be a bit tricky to implement using meow, but I think I can manage it.

Alternatively, we could provide different cli commands for each use-case, how they do with a lot linux utilities. Not sure about that, though.

What do you think about that?