mingrammer / diagrams

:art: Diagram as Code for prototyping cloud system architectures
https://diagrams.mingrammer.com
MIT License
36.87k stars 2.39k forks source link

Feature Request: --watch mode - dynamically updating local website on every change, like D2 has #894

Open HariSekhon opened 1 year ago

HariSekhon commented 1 year ago

D2 has an amazing feature where it can run as a foreground process that watches your diagram source code, runs a local webserver which automatically opens in your web browser and dynamically auto-updates the diagram in your browser page for every change (edit+save).

This makes development much easier and more interactive.

It's literally as simple as running this in D2:

d2 --watch input.d2

Perhaps Python diagrams can do something similar to make iterative development more automated like this?

Before this I had a hotkey in my [.vimrc]() to execute the python file with diagrams configured to auto-open the resulting png but that seems a bit slow and poor by comparison now I started using D2's interactive mode...

jr-b commented 10 months ago

Hey @HariSekhon,

I agree, --watch-mode would be great!

What I've been doing on my side to fix this small annoyance is using a small CLI tool called entr that allows to run arbitrary commands when it detects a file change (https://github.com/eradman/entr):

ls diagram.py | entr python diagram.py

You can then work on your diagram, save, and the output file will be generated/updated every time there's a change in the files listed by ls.

With both your code window and your output file opened side by side, you can have an interactive workflow.