Tuesday, May 7, 2019

Node-PlantUML package to automate generation of mind map diagrams

Recently I was doing some experiments with PlantUML. PlantUML is awesome. Write code and get diagrams. It is especially great tool for engineers like me who are not that good at art. One of the main trend now a days is to automate anything and obviously we can automate diagram generation from puml file. The technology to do is obviously NodeJS.

Package to generate images from .puml files

As normal in Node world, NodeJS has a package to convert puml files into images and much more. Below is the link to the NPN package.
https://www.npmjs.com/package/node-plantuml

From here, this post assumes the reader has knowledge about NodeJS and its NPM package ecosystem.

A simple problem

If there is no problem this post is not needed. The node-plantuml package generated the diagrams for most for the puml files. But not for the mind map pumls. ie which are starting with @startmindmap.

@startmindmap
* root
** 1
**_ 3
@endmindmap

Root cause

The node-plantuml uses plantuml.jar file to bundle with it is not the latest. That jar file don't have the capability to understand @startmindmap. So it fails.

Solution

node-platuml package to include the latest plantuml.jar file. As a responsible developer, who make use of other's open source work, I should give them a PR which I will be doing soon.

Workarounds

Set the path of plantuml.jar

As any other developer, the developers of this package also left option for configuring the path to jar file. They selected the environment variable mechanism to set the path. The name of environment variable is PLANTUML_HOME. If the environment variable is not there, it will take jar file from vendor folder. Below line is from the node-plant package source code.

The code to set the environment variable to a different .jar file is as follows. If we obtain the latest plantuml.jar file, we can place it somewhere and point to the same.

process.env.PLANTUML_HOME = "node_modules/node-plantuml/vendor/plantuml_new.jar";

If there are any troubles setting the path, try the below approach.

Replace old file with new

Get the latest plantuml.jar file from VS code extension called PlantUML. The location of the platuml.jar file is below.

%userprofile%\.vscode\extensions\jebbs.plantuml-2.10.9

Put the file into the node-plantuml modules folder. Location below.

..\node_modules\node-plantuml\vendor

No comments: