Git Product home page Git Product logo

node-plantuml's Introduction

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

node-plantuml's People

Contributors

markushedvall avatar dashersw avatar pierre3 avatar

Watchers

Vitaliy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.