@yantrix/cli v0.0.2 • Docs
Yantrix API / @yantrix/cli
@yantrix/cli
Command-line interface for Yantrix framework. This package is a console wrapper for certain Yantrix tooling, most notably code generation.
It's not encouraged to use this package individually, as it's main function is to enable the users to easily generate Yantrix automatas with the help of other packages like automata
and functions
.
How to install
1. Part of the @yantrix/core
package
We recommend simply installing the core
package that includes everything required to easily start creating finite state machines (including the CLI).
2. Using the CLI package separately
In case you want to use the @yantrix/cli
separately from the core package, just remember that CLI by itself is not enough, and installing extra packages is necessary.
Here is what you need to do:
Install both @yantrix/cli
and @yantrix/codegen
using your preferred package manager. All the secondary dependencies will be installed automatically.
bash
# Via NPM
$ npm install @yantrix/codegen @yantrix/cli
# Via Yarn
$ yarn add @yantrix/codegen @yantrix/cli
# Via PNPM
$ pnpm install @yantrix/codegen @yantrix/cli
# ✨ Auto-detection
$ npx nypm install @yantrix/codegen @yantrix/cli
We suggest using
pnpm
Usage
To get help on the codegen
command, run:
bash
yantrix codegen -h
It will print the following:
bash
yantrix codegen [diagramFile]
Generates Automata from given mermaid state diagram
Positionals:
diagramFile Diagram file to be parsed. It should have .mermaid extension
[string]
Options:
-l, --language Output file language. Currently supported: javascript, typ
escript, python, java [string]
-o, --outfile Output Automata file path [string]
-c, --className Name of the generated Automata class [string]
-j, --constants Stringified JSON with constants to be used in generated Au
tomata [string]
-J, --constantFile Path to JSON file with constants to be used in generated A
utomata [string]
-e, --eval Evaluate the given state diagram [string]
--verbose Verbose mode [boolean]
-i, --interactive Enter interactive mode [boolean]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
For quick start, let's generate a simple Automata from a diagram saved in a file diagram.mermaid
:
Just run:
bash
$ yantrix codegen ./diagram.mermaid -o ./automata.ts -c MyAutomata -l typescript'
This will generate a file automata.ts
. But that's not all - since we generated in Typescript, we should also install a couple of dependencies, that Automata depends on:
bash
# Via NPM
$ npm install @yantrix/automata @yantrix/functions
# Via Yarn
$ yarn add @yantrix/automata @yantrix/functions
# Via PNPM
$ pnpm install @yantrix/automata @yantrix/functions
# ✨ Auto-detection
$ npx nypm install @yantrix/automata @yantrix/functions
In any case, this will be reported during the generation process, like this:
bash
Since you have chosen the *-script language, you need to install additional packages to work with the generated Automata:
- @yantrix/automata
- @yantrix/functions