Skip to content

Transforms TS AST to MMD format for generating graphs using mermaid-js

Notifications You must be signed in to change notification settings

stechy1/ast-to-mmd

Repository files navigation

AST-to-MMD

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.

Usage

Install utility as dev dependency: npm install --dev @stechy1/ast-to-mmd. Run it with npx @stechy1/ast-to-mmd.

Options

  • -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.

Supported constructs

Example of rendered code

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

rendered result Diagram result

Filter conditions

JSON conditions

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"
      }
    }
  ]
}

About

Transforms TS AST to MMD format for generating graphs using mermaid-js

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published