-
Notifications
You must be signed in to change notification settings - Fork 0
Generate mermaid diagrams from JSON definitions #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0409393
Create script to scan .jsonnet files and generate .json files
mahmoud-elmorabea f1bea31
Create script that ensure no .jsonnet files were not compiled into .json
mahmoud-elmorabea 6ab49f9
Handle missing feature directory case
mahmoud-elmorabea 5cad481
Convert scripts to TS
mahmoud-elmorabea e1f430c
Convert scripts to TS
mahmoud-elmorabea e29a9b3
Update readme
mahmoud-elmorabea 4e5c85c
Add log with suggested fix when JSON files validation scripts fails
mahmoud-elmorabea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| node_modules/ | ||
|
|
||
| dist | ||
| dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import { fileURLToPath } from "url"; | ||
| import { walkDir, isJsonFile, getMermaidOutputPath } from "./utils"; | ||
| import logger from "./log-styling"; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
|
|
||
| const INPUT_DIR = path.resolve(__dirname, "../generated/json"); | ||
| const OUTPUT_DIR = path.resolve(__dirname, "../generated/mermaid"); | ||
|
|
||
| type Event = { | ||
| id: string; | ||
| label: string; | ||
| next?: string; | ||
| success?: string; | ||
| error?: string; | ||
| }; | ||
|
|
||
| function toMermaid(events: Event[]): string { | ||
| const lines: string[] = ["graph TD"]; | ||
|
|
||
| for (const event of events) { | ||
| const { id, label, next, success, error } = event; | ||
|
|
||
| lines.push(`${id}["${label}"]`); | ||
| if (next) { | ||
| lines.push(`${id} --> ${next}`); | ||
| } | ||
| if (success) { | ||
| lines.push(`${id} -->|Success| ${success}`); | ||
| } | ||
| if (error) { | ||
| lines.push(`${id} -->|Error| ${error}`); | ||
| } | ||
| } | ||
|
|
||
| return lines.join("\n"); | ||
| } | ||
|
|
||
| function generateDiagram(filePath: string): void { | ||
| const relativePath = path.relative(INPUT_DIR, filePath); | ||
| logger.info(`Generating diagram for: ${relativePath}`); | ||
|
|
||
| const outputFile = getMermaidOutputPath(filePath, INPUT_DIR, OUTPUT_DIR); | ||
| fs.mkdirSync(path.dirname(outputFile), { recursive: true }); | ||
|
|
||
| const events: Event[] = JSON.parse(fs.readFileSync(filePath, "utf-8")); | ||
| const output = toMermaid(events); | ||
|
|
||
| fs.writeFileSync(outputFile, output); | ||
| } | ||
|
|
||
| if (!fs.existsSync(INPUT_DIR)) { | ||
| logger.warn(`Generated directory is missing: ${INPUT_DIR}`); | ||
| logger.info("This likely means you need to run 'npm run buildJson'"); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| logger.heading("Generating Mermaid diagrams from JSON files..."); | ||
| logger.blank(); | ||
|
|
||
| walkDir(INPUT_DIR, (filePath: string) => { | ||
| if (isJsonFile(filePath)) { | ||
| generateDiagram(filePath); | ||
| } else { | ||
| logger.warn( | ||
| `Skipping unsupported file: ${path.relative(INPUT_DIR, filePath)}` | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| logger.blank(); | ||
| logger.success("Mermaid diagrams generated successfully!"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.