How to update PlantUML diagram automatically?
Par Jean-Sébastien H. le mercredi, février 24 2021, 16:19 - Lien permanent
PlantUML is a nice tool to generate diagram as code but unlike the visual editors (like diagrams.net) you don't have visual feedbacks.
Easy but manual
The following command will generate an image name mydiagram.png
plantuml mydiagram.puml
watch ?
Let's try to update it every 10s with watch. It's a good start but it refresh the diagram even if it's not saved. It you are not lucky it could take ~10s to display the change. (Ok you can lower the watch duration but...)
watch -n 10 plantuml mydiagram.puml
inotifywait
inotifywatch listen for filesystem events so it will reload the diagram at the right time : when you save it.
while inotifywait -e move_self cd.puml; do plantuml cd.puml; echo ""; done
My editor is vim so I'm listening to the event move_self that is enough but maybe it's not suitable with another editor. You could watch for events with inotifywatch.
vim !
In fact, vim have this feature built in with the autocmd.
autocmd BufWritePost *.puml !plantuml %