Created
April 17, 2025 15:32
-
-
Save smith/d83ca300c82debfcf6e201230a5c5751 to your computer and use it in GitHub Desktop.
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
const fs = require("fs"); | |
const path = require("path"); | |
const yaml = require("js-yaml"); | |
function extractEntitiesAndRelationships(baseDir) { | |
const entities = []; | |
function processFile(filePath) { | |
const fileContent = fs.readFileSync(filePath, "utf8"); | |
const data = yaml.load(fileContent); | |
if (data.groups) { | |
data.groups.forEach((group) => { | |
if (group.type === "entity") { | |
entities.push(group); | |
} | |
}); | |
} | |
} | |
function walkDirectory(dir) { | |
const files = fs.readdirSync(dir); | |
files.forEach((file) => { | |
const fullPath = path.join(dir, file); | |
if (fs.statSync(fullPath).isDirectory()) { | |
walkDirectory(fullPath); | |
} else if (file === "resources.yaml") { | |
processFile(fullPath); | |
} | |
}); | |
} | |
walkDirectory(baseDir); | |
return entities; | |
} | |
function generateMermaidDiagram(entities) { | |
console.log("classDiagram"); | |
for (const entity of entities) { | |
for (const attr of entity.attributes) { | |
console.log(` ${entity.name} : attribute ${attr.ref}`); | |
} | |
for (const attr of entity.descriptive_attributes ?? []) { | |
console.log(` ${entity.name} : descriptive_attribute ${attr.ref}`); | |
} | |
for (const relationship of entity.relationships ?? []) { | |
for ([relationshipType, relatedEntityType] of Object.entries( | |
relationship, | |
)) { | |
console.log( | |
` ${entity.name} --> ${relatedEntityType}: ${relationshipType}`, | |
); | |
} | |
} | |
} | |
} | |
generateMermaidDiagram( | |
extractEntitiesAndRelationships(path.join(__dirname, "model")), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment