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/codegenNOTE
@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
| Flag | Alias | Type | Default | Required | Description |
|---|---|---|---|---|---|
diagramFile | — | string | — | yes (or --eval) | Path to .mermaid diagram file |
--language | -l | string | — | yes | Output language (see below) |
--outfile | -o | string | — | yes | Output file path |
--className | -c | string | GeneratedAutomata | no | Generated class/factory name |
--constants | -j | string | — | no | JSON string of constants |
--constantFile | -J | string | — | no | Path to .json constants file; overrides --constants |
--functionFile | -f | string | — | no | Path to .js/.ts (or .py) file with injectable user-defined functions |
--eval | -e | string | — | no | Inline diagram text; skips reading a file |
--beautify | — | boolean | false | no | Format output via Prettier (JS/TS) or ruff (Python) |
--verbose | — | boolean | — | no | Log warnings during generation |
--interactive | -i | boolean | — | no | Enter guided prompt mode; ignores all other flags |
Supported languages (--language)
| Value | Output |
|---|---|
javascript | Class-based .js |
typescript | Class-based .ts |
pure-javascript | Zero-dep .js + inlined builtins |
pure-typescript | Zero-dep .js + .d.ts declarations |
python | Single .py (requires pydash at runtime) |
java | .java class |
Language values are case-insensitive.
Mutual exclusions
--evalanddiagramFileare mutually exclusive;--evalwins if both are given (a warning is logged in--verbosemode).--constantFileoverrides--constantswhen both are provided.--functionFileis only valid for JS/TS/Python dialects; Java will throw a build-time error.--interactiveignores 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-nocheckPython 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. RequiresruffinPATH; 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.tsInteractive mode
Run yantrix codegen -i (or --interactive) to enter a guided prompt that walks through all required inputs without memorizing flags.
Prompts in order:
- Uncommitted changes warning (if git repo is dirty)
- Path to
.mermaiddiagram file - Language selection (dropdown)
- Output file path
- Class name
- Format generated code? (beautify confirm, default: No)
- Constants: skip / JSON string /
.jsonfile path
Differences from non-interactive mode:
| Feature | Non-interactive | Interactive |
|---|---|---|
| Inline diagram | --eval | Not available |
| Verbose logging | --verbose | Not available |
| Constants from file | --constantFile | Prompted |
| Beautify | --beautify | Prompted (yes/no) |