Skip to content

CLI Reference

@yantrix/cli provides the yantrix command-line tool for generating Automata from Mermaid state diagrams without writing any Node.js code. It wraps @yantrix/codegen and exposes the full generation pipeline as a single command.

Installation

bash
# Via NPM
npm install @yantrix/cli @yantrix/codegen

# Via PNPM
pnpm install @yantrix/cli @yantrix/codegen

# Via Yarn
yarn add @yantrix/cli @yantrix/codegen

NOTE

@yantrix/codegen is a required peer dependency. The CLI does not bundle it.

Usage

bash
yantrix codegen [diagramFile] [options]

diagramFile is a path to a .mermaid file. It is optional when --eval is provided.

Options

FlagAliasTypeDefaultRequiredDescription
diagramFilestringyes (or --eval)Path to .mermaid diagram file
--language-lstringyesOutput language (see below)
--outfile-ostringyesOutput file path
--className-cstringGeneratedAutomatanoGenerated class/factory name
--constants-jstringnoJSON string of constants
--constantFile-JstringnoPath to .json constants file; overrides --constants
--functionFile-fstringnoPath to .js/.ts (or .py) file with injectable user-defined functions
--eval-estringnoInline diagram text; skips reading a file
--beautifybooleanfalsenoFormat output via Prettier (JS/TS) or ruff (Python)
--verbosebooleannoLog warnings during generation
--interactive-ibooleannoEnter guided prompt mode; ignores all other flags

Supported languages (--language)

ValueOutput
javascriptClass-based .js
typescriptClass-based .ts
pure-javascriptZero-dep .js + inlined builtins
pure-typescriptZero-dep .js + .d.ts declarations
pythonSingle .py (requires pydash at runtime)
java.java class

Language values are case-insensitive.

Mutual exclusions

  • --eval and diagramFile are mutually exclusive; --eval wins if both are given (a warning is logged in --verbose mode).
  • --constantFile overrides --constants when both are provided.
  • --functionFile is only valid for JS/TS/Python dialects; Java will throw a build-time error.
  • --interactive ignores all other flags.

Output notes

JS/TS dialects (javascript, typescript, pure-javascript, pure-typescript) prepend two disable comments to the output file:

typescript
/* eslint-disable */
// @ts-nocheck

Python output is plain — no header comments.

--beautify runs a postprocessor after generation:

  • JS/TS: Prettier with useTabs: true, printWidth: 100, trailingComma: 'all'
  • Python: ruff format --line-length 100 - via subprocess. Requires ruff in PATH; if not found, output is written unformatted with a warning.

Examples

bash
# Basic TypeScript generation
yantrix codegen ./diagram.mermaid -l typescript -o src/generated/MyAutomata.ts -c MyAutomata

# With a constants file and verbose logging
yantrix codegen ./diagram.mermaid -l typescript -o out/Automata.ts -c Automata \
  -J ./constants.json --verbose

# Inline diagram (no file needed)
yantrix codegen -e "stateDiagram-v2\n  [*] --> Idle\n  Idle --> Active: start" \
  -l python -o automata.py -c MyMachine

# Format output with Prettier / ruff
yantrix codegen ./diagram.mermaid -l typescript -o src/generated/Automata.ts \
  -c Automata --beautify

# Inject custom functions from a TypeScript file
yantrix codegen ./diagram.mermaid -l typescript -o src/generated/Automata.ts \
  -c Automata -f ./src/functions/customFunctions.ts

Interactive mode

Run yantrix codegen -i (or --interactive) to enter a guided prompt that walks through all required inputs without memorizing flags.

Prompts in order:

  1. Uncommitted changes warning (if git repo is dirty)
  2. Path to .mermaid diagram file
  3. Language selection (dropdown)
  4. Output file path
  5. Class name
  6. Format generated code? (beautify confirm, default: No)
  7. Constants: skip / JSON string / .json file path

Differences from non-interactive mode:

FeatureNon-interactiveInteractive
Inline diagram--evalNot available
Verbose logging--verboseNot available
Constants from file--constantFilePrompted
Beautify--beautifyPrompted (yes/no)