Simple utility to transform your TS code to MermaidJS syntax for flowcharts.
New file *.mmd is generated next to each TS file which fulfilled condition.
Install utility as dev dependency: npm install --dev @stechy1/ast-to-mmd
.
Run it with npx @stechy1/ast-to-mmd
.
- -p, --path <path>: Defines path where to find (one) source file,
- -d, --directory <path>: Defines path to directory where to find source files,
- -ts, --tsConfig <tsConfigPath>: Defines path to project ts-config.json file,
- -g, --idGenerator <type>: Defines type of ID generator ('uuid' | 'incremental'), default='incremental',
- -f, --fileFilter <fileFilterPath>: Defines path to file with filter rules,
- -e, --experimental Enables experimental mode - when unknown kind is found, empty block is generated instead of throwing exception.
- function call
- conditions
- return
- break
- throw
- for cycles
- continue
- return
- break
- throw
- try-catch-finaly
- return
- break
- throw
- switch-case
- return
- break
- throw
source code
function fun() {
foo();
for (let i = 0; i < 10; i++) {
bar();
baz();
}
fooBar();
}
transformed to mmd syntax
flowchart TD
subgraph 600 ["Functions"]
direction TB
subgraph 580 ["fun"]
direction TB
581[["foo()"]]
subgraph 595_16 ["CYCLE_16"]
direction TB
595[/"i = 0; i < 10; i++"/]
582[["bar()"]]
583[["baz()"]]
595 ---> 582
583 -. "loop_16" .-> 595
582 ---> 583
end
596[["fooBar()"]]
581 ---> 595
583 ---> 596
end
end
subgraph 601 ["Classes"]
direction TB
end
Supported logical condition constructs:
- and: all conditions must be fulfilled
- or: some of the conditions must be fulfilled
- not: negate condition Supported functional condition constructs:
- contains: tested file path must contain defined string
- endsWith: tested file path must ends with defined string
Example of simmple JSON conditions:
{
"and": [
{
"endsWith": "handler.ts",
"contains": "event",
"not": {
"contains": "entity"
}
}
]
}