项目作者: prantlf

项目描述 :
Generates images from nomnoml diagram sources in a NodeJS module or on the command line
高级语言: JavaScript
项目地址: git://github.com/prantlf/nomnoml-cli.git
创建时间: 2015-07-30T21:35:58Z
项目社区:https://github.com/prantlf/nomnoml-cli

开源协议:MIT License

下载


nomnoml-cli

Latest version
Dependency status

codecov
Code Climate

Generates images from nomnoml diagram sources
on the command line and provides a library for a programmatic usage from
NodeJS modules

Getting Started

Make sure that you have NodeJS >= 12 installed.

  1. Install pre-requisites
    of the node-canvas module depending
    on your operating system

  2. Install the command-line tool and generate a testing image:

  1. npm install -g nomnoml-cli
  2. echo '[nomnoml]is->[awesome]' | nomnoml > awesome.png

Read the documentation about the nomnoml source format

Command-Line Usage

The nomnoml script generates a png, jpg, svg or pdf image from the nomnoml source text.
Both file names and standard input and output are supported as parameters.
If generating the image fails, exit code 1 is returned to the caller.

  1. $ nomnoml --help
  2. Usage: nomnoml [option]
  3. Options:
  4. -h, --help output usage information
  5. -V, --version output the version number
  6. -i, --input <path> file with nomnoml source to read from
  7. -o, --output <path> file for the image output to write to
  8. -f, --format <format> output format (png, jpg, svg, pdf)
  9. -w, --width <pixels> width of the canvas to draw on
  10. -H, --height <pixels> height of the canvas to draw on
  11. The default output format is png. The default canvas size is 640x480 pixels.
  12. If the input file is omitted, the source is read from the standard input.
  13. If the output file is omitted, the image is written to the standard output.
  14. Examples:
  15. $ echo '[nomnoml]is->[awesome]' | nomnoml > awesome.png
  16. $ nomnoml -i source.nomnoml -f svg -o target.svg

Programmatic Usage

The main module exports a function which generates the image:

  1. const generateDiagram = require('nomnoml-cli');
  2. const diagram = await generateDiagram(...);

The function returns a Promise to wait for a success or a failure.

The function expects a nomnoml source text as a string or an options
object with the following supported properties:

  • input: source to read the nomnoml text from; either a Stream or a
    string with the actual nomnoml text
  • inputFile: source file path to read the nomnoml source from
  • output: target to write the image to; either a Stream or a string
    with the file path (undefined by default)
  • resultType: type of the object to resolve the promise with if the
    output parameter is not provided (‘buffer’ or ‘stream’; the former
    is default)
  • format: output image format (‘png’, ‘jpg’, ‘svg’ or ‘pdf’; the first
    is default)
  • width: canvas width in pixels (640 by default)
  • height: canvas height in pixels (480 by default)

Either input or inputFile has to be provided, otherwise the function
fails. If output is not provided, the function resolves the promise
with a Buffer containing the image. If output is provided, the
function returns a promise resolved when the output has been written.

Code Samples

  1. const generateDiagram = require('nomnoml-cli');
  2. // Get Buffer with the image
  3. const buffer = await generateDiagram('[nomnoml]is->[awesome]');
  4. // Convert the standard input to standard output
  5. await generateDiagram({
  6. input: process.stdin,
  7. output: process.stdout
  8. });
  9. // Create a PNG file from a nomnoml source file
  10. await generateDiagram({
  11. inputFile: 'source.nomnoml',
  12. output: 'target.png'
  13. });

Notes

Contents of other .nomnoml files can be imported to the input file using
the #import directive.
You can use it for sharing style definitions or parts of diagrams among
multiple diagram sources.

  1. #import: /usr/local/share/nomnoml/style.nomnoml
  2. #import: shared/style.nomnoml
  3. #import: ./sub-diagram.nomnoml

If the imported file path is relative and starts with ./ or ../, it will
be appended to the path of the “parent” file, which the specified file is
being imported to. Otherwise the relative path will be appended to the
current (executing) directory.

File import directives are processed recursively. However, a single file can
be imported only once. If imported once more, scond and other occurrences
will be replaced by an empty string.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding
style. Add unit tests for any new or changed functionality. Lint and test
your code using Grunt.

License

Copyright (c) 2015-2022 Ferdinand Prantl

Licensed under the MIT license.