Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to output markdown file that has mermaid in it #81

Open
ckrauterlovescoffee opened this issue Apr 25, 2024 · 2 comments
Open

Comments

@ckrauterlovescoffee
Copy link

It would be neat to be able to specify an output for a markdown file that gets filled with the mermaid diagram.

@ckrauterlovescoffee
Copy link
Author

Here is what I've settled on for now,

# What I run
tsuml2 --outFile ./docs/uml.svg --outMermaidDsl ./docs/mermaid.dsl --glob './src/**/*.ts' --glob './examples/**/*.ts' --memberAssociations && ./scripts/add_mermaid_to_readme.sh
#!/bin/bash
# This script injects the content of 'mermaid.dsl' into the README.md under the 'Diagram' section.

MERMAID_FILE="./docs/mermaid.dsl"
README_FILE="./README.md"
TEMP_FILE="./docs/temp_readme.md"

GREEN="\033[1;32m"
RESET="\033[0m"

cp $README_FILE $TEMP_FILE

if ! grep -q '## Architecture' $TEMP_FILE; then
  echo "\n\n## Architecture" >> $TEMP_FILE
fi

sed -i '' '/## Architecture/,$d' $TEMP_FILE

echo -e '\n\n## Architecture' >> $TEMP_FILE
echo -e '\n\nThis is an auto-generated diagram per the [add_mermaid_to_readme.sh](./scripts/add_mermaid_to_readme.sh) script. The section must be the last section in this file. Any subsequent sections will be destroyed!' >> $TEMP_FILE
echo -e '\n\n```mermaid' >> $TEMP_FILE
cat $MERMAID_FILE >> $TEMP_FILE
echo -e '\n```\n' >> $TEMP_FILE

cp $TEMP_FILE $README_FILE
echo -e "${GREEN}Update complete: README.md has been updated with the contents of $MERMAID_FILE.${RESET}"

rm $TEMP_FILE
rm $MERMAID_FILE

@demike
Copy link
Owner

demike commented May 12, 2024

@ckrauterlovescoffee I think it would be easier with the public parseProject getMermaidDSL functions
You can read the markdown file and replace a specified placeholder with the generated mermaid dsl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants