postapl-mermaid-graph
Version:
PostAPL plugin to show AST or components as a Mermaid graph
72 lines (50 loc) • 1.93 kB
Markdown
[![NPM Version][npm-img]][npm-url]
[] is a [PostAPL] plugin that creates graph data for [Mermaid Live Editor] of the Component tree of your APL or of the AST.
The plugin is of type Reporter that does not transform the APL in any way.
You can find example reports [here](https://github.com/postapl/postapl-mermaid-graph/blob/main/example).
**Step 1:** Install plugin:
```sh
npm install --save-dev postapl postapl-mermaid-graph
```
**Step 2:** Use:
```js
'use strict'
const { postapl } = require('postapl');
const graph = require('postapl-mermaid-graph');
const fs = require('fs');
fs.readFile('src/screen.json', (err, apl) => {
postapl([graph({ componentGraphPath: 'report/screen.componentTree.txt' })])
.process(apl, { from: 'src/screen.json', to: 'dest/screen.json' })
.then(result => {
fs.writeFile(result.opts.to, result.apl, () => true)
})
});
```
* `componentGraphPath` - When set, the path to write the graph file for Components. When set to `
```js
{
type: 'output',
id: 'myComponentKey',
plugin: 'postapl-mermaid-graph',
value: string // the graph data
}
```
* `treeGraphPath` - When set, the path to write the graph file for AST. When set to `
```js
{
type: 'output',
id: 'myTreeKey',
plugin: 'postapl-mermaid-graph',
value: string // the graph data
}
```
[]: https://img.shields.io/npm/v/postapl-mermaid-graph.svg
[]: https://www.npmjs.com/package/postapl-mermaid-graph
[]: https://github.com/postapl/postapl
[]: https://github.com/postapl/postapl-mermaid-graph
[]: https://mermaid.live