RohanTalip / node-plantuml

A Node.js module and CLI for running PlantUML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-plantuml

A Node.js module and CLI for running PlantUML.

npm Version Build Status js-standard-style

PlantUML is a popular diagramming tool that uses simple textual descriptions to draw UML diagrams. With the API provided by this module you can easily generate PlantUML diagrams directly from your Node.js application. It can also be used to encode and decode PlantUML source files.

This module also provides an easy to use and flexible command line interface for doing the same kind of operations as enabled by the API.

Install Graphviz to be able to generate all diagram types.

Install

npm install node-plantuml

If you want to use the CLI node-plantuml can be install it globally:

npm install node-plantuml -g

Example

Diagrams can be created from source files.

var plantuml = require('node-plantuml');
var fs = require('fs');

var gen = plantuml.generate("input-file");
gen.out.pipe(fs.createWriteStream("output-file.png"));

If your application will be making multiple PlantUML requests, it might be a good idea to enable the usage of Nailgun.

Following is an example of a simple web server for generating images from encoded PlantUML source.

var express = require('express');
var plantuml = require('node-plantuml');

var app = express();

plantuml.useNailgun(); // Activate the usage of Nailgun

app.get('/png/:uml', function(req, res) {
  res.set('Content-Type', 'image/png');

  var decode = plantuml.decode(req.params.uml);
  var gen = plantuml.generate({format: 'png'});

  decode.out.pipe(gen.in);
  gen.out.pipe(res);
});

app.get('/svg/:uml', function(req, res) {
  res.set('Content-Type', 'image/svg+xml');

  var decode = plantuml.decode(req.params.uml);
  var gen = plantuml.generate({format: 'svg'});

  decode.out.pipe(gen.in);
  gen.out.pipe(res);
});

app.listen(8080);

CLI

The node-plantuml CLI can be accessed with the puml command.

puml generate file.puml -o file.png

It's also possible to use stdin and stdout for input and output.

puml decode UDfpLD2rKt0200GS0Iy0 | puml generate > file.png

Simple textual one-liners can also be used as input.

puml generate --unicode --text "A -> B: Hello"
    ┌─┐          ┌─┐
    │A│          │B│
    └┬┘          └┬┘
     │   Hello    │
     │───────────>│
    ┌┴┐          ┌┴┐
    │A│          │B│
    └─┘          └─┘

There are multiple options for input and for output. And the output can be in multiple different formats.

Usage: puml [options] [command]


Commands:

  generate [options] [file]  Generate an UML diagram from PlantUML source
  encode [options] [file]    Encodes PlantUML source
  decode <url>               Decodes PlantUML source
  testdot                    Test the installation of Graphviz dot

Options:

  -h, --help     output usage information
  -V, --version  output the version number
Usage: generate [options] [file]

Generate an UML diagram from PlantUML source

Options:

  -h, --help            output usage information
  -p, --png             ouput an UML diagram as a PNG image
  -s, --svg             ouput an UML diagram as an SVG image
  -e, --eps             ouput an UML diagram as an EPS image
  -u, --unicode         ouput an UML diagram in unicode text
  -a, --ascii           ouput an UML diagram in ASCII text
  -o --output [file]    the file in which to save the diagram
  -c, --config [file]   config file read before the diagram
  -t, --text [text]     UML text to generate from
  -d, --dot [file]      specify Graphviz dot executable
  -i, --include [path]  specify the path to include from
  -C, --charset [charset]  specify the charset of PlantUML source
Usage: encode [options] [file]

Encodes PlantUML source

Options:

  -h, --help         output usage information
  -t, --text [text]  UML text to encode
Usage: decode [options] <url>

Decodes PlantUML source

Options:

  -h, --help  output usage information

Config templates

With predefined configuration templates the looks of the diagrams can be altered. For a more classic black and white look the classic configuration template can be used. alt tag

Compared to the standard PlantUML look: alt tag

License

MIT

About

A Node.js module and CLI for running PlantUML

License:MIT License


Languages

Language:JavaScript 95.1%Language:Java 4.9%