Skip to content

Instantly share code, notes, and snippets.

@hydrosquall
Last active May 19, 2024 22:17
Show Gist options
  • Save hydrosquall/40ece3c6c618fe834a28885986eaa3cd to your computer and use it in GitHub Desktop.
Save hydrosquall/40ece3c6c618fe834a28885986eaa3cd to your computer and use it in GitHub Desktop.
Dependency graph of the vega repo

Process

  1. Run yarn lerna ls --graph to generate a topologically sorted diagram for all the projects in the repo
  2. For each edge, you may generate a mermaid diagram. (See attached python script)

End to end combo

yarn --silent run lerna ls --graph --loglevel=silent | python lerna-graph-to-mermaid.py | pbcopy

(Paste the result into a .mmd file on github gist or github main )

Editing demo

import sys
import json
# Convert JSON data from lerna ls --graph to Mermaid format
# Usage:
# yarn --silent run lerna ls --graph --loglevel=silent | python dep-to-mermaid.py
def json_to_mermaid(json_data):
mermaid_str = "graph LR\n"
for package, dependencies in json_data.items():
if dependencies:
for dependency in dependencies:
if dependency.startswith("vega-"):
# remove @ sign from types as they break syntax
# for wordier diagrams, see https://mermaid.js.org/syntax/flowchart.html#special-characters-that-break-syntax
dependency = dependency.replace("@", "")
mermaid_str += f" {package} --> {dependency}\n"
else:
mermaid_str += f" {package}\n"
return mermaid_str
if __name__ == "__main__":
# Read JSON input from stdin
input_data = sys.stdin.read()
try:
data = json.loads(input_data)
except json.JSONDecodeError as e:
print(f"Invalid JSON input: {e}")
sys.exit(1)
mermaid_output = json_to_mermaid(data)
print(mermaid_output)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment