This project is deprecated. Use StarUML CLI from version 5.x
A command line tool for template-based code generation from metadata encoded in JSON format based on metadata-json files (.mdj
) typically created by StarUML.
This tool depends on Node.js so you need to install it first. Install globally using npm
command so as to use mdgen
in any directory.
$ npm install -g mdgen
IMPORTANT
This
mdgen
uses node-canvas module in order to generate diagram image files (PNG and SVG). If you need to export diagram images, you have to install Cairo first before installing this module (To installing Cairo on various platforms, please refer to https://github.com/Automattic/node-canvas). If you don't need to export images, ignore installation errors fromnode-canvas
.
- Generate codes using EJS templates.
- Generate a PDF document from diagrams.
$ mdgen [command] [options]
To generate codes with EJS template, use render
command with following options:
-m, --model <file>
: a model file to load (defaultmodel.mdj
)-t, --template <file>
: template file (defaulttemplate.ejs
)-o, --output <file>
: output file (defaultmdgen-out
)-s, --select <selector>
: selector expression to select a set of elements (default@Project
).
To see the help, type mdgen render -h
or mdgen render --help
in shell.
Here is an example to generate a set Java source files. Loads model.mdj
file and renders all of UML Classes with java-template.ejs
template, then save to files of its name and .java
file extension in out
folder.
$ mdgen render -m model.mdj -t java-template.ejs -o "out/<%=element.name%>.java" -s @UMLClass
To export diagram images, use image
command with following options:
-m, --model <file>
: a model file to load (defaultmodel.mdj
)-o, --output <file>
: output image file name (default<%=diagram.name%>.png
)-f, --format <format>
, image format "png" or "svg" (defaultpng
)-s, --select <selector>
: selector expression to select a set of diagrams (default@Diagram
).
To see the help, type mdgen image -h
or mdgen image --help
in shell.
Here is an example to export diagram images. Loads model.mdj
file and export all of diagrams as SVG format in images
folder.
$ mdgen image -m model.mdj -o "images/<%=diagram.name%>.svg" -f "svg" -s @Diagram
To generate a PDF document of diagrams, use pdf
command with following options:
-m, --model <file>
: model file to load (defaultmodel.mdj
)-o, --output <file>
: output file (defaultmdgen-out.pdf
)-s, --select <selector>
: selector expression to select a set of elements (default@Diagram
). This means all diagrams.-z, --size <size>
: page size (defaultA4
). Full list of page size can be found here.-l, --layout <layout>
: page layout (defaultlandscape
). Or useportrait
.-n, --showname <yesno>
: show diagram name on page top (defaultyes
). Or useno
.
Here is an example generating all diagrams in a PDF document.
$ mdgen pdf -m model.mdj -o document.pdf
To generate HTML docs, use html
command with following options:
-m, --model <file>
: model file to load (defaultmodel.mdj
)-o, --output <file>
: output folder name (defaulthtml-out
)-d, --diagram <yesno>
: export diagram images (defaultyes
). Or useno
.
Here is an example generating HTML docs. `
$ mdgen html -m model.mdj -o html-out