diff --git a/bin/mmd-to-svg b/bin/mmd-to-svg new file mode 100755 index 0000000..6cb1cb1 --- /dev/null +++ b/bin/mmd-to-svg @@ -0,0 +1,2 @@ +#!/bin/bash +bun /Users/she0001t/joyn/mermaid-diagram-creator/index.ts "$@" diff --git a/example.mmd b/example.mmd new file mode 100644 index 0000000..d2f34a1 --- /dev/null +++ b/example.mmd @@ -0,0 +1,4 @@ +graph TD + A[Start] --> B{Decision} + B -->|Yes| C[Action] + B -->|No| D[End] diff --git a/index.ts b/index.ts index 9a75729..08bbcee 100644 --- a/index.ts +++ b/index.ts @@ -1,9 +1,31 @@ import { renderMermaidSVG } from "beautiful-mermaid"; -const svg = renderMermaidSVG(` - graph TD - A[Start] --> B{Decision} - B -->|Yes| C[Action] - B -->|No| D[End] -`); -console.log(svg); +const args = process.argv.slice(2); + +if (args.length < 2) { + console.error("Usage: bun index.ts "); + console.error("Example: bun index.ts diagram.mmd output.svg"); + process.exit(1); +} + +const [inputPath, outputPath] = args; + +try { + // Read the .mmd file + const diagramText = await Bun.file(inputPath).text(); + + // Render to SVG + const svg = renderMermaidSVG(diagramText); + + // Write to output file + await Bun.write(outputPath, svg); + + console.log(`✓ Generated SVG: ${outputPath}`); +} catch (error) { + if (error instanceof Error && "code" in error && error.code === "ENOENT") { + console.error(`✗ Input file not found: ${inputPath}`); + } else { + console.error(`✗ Error: ${error instanceof Error ? error.message : String(error)}`); + } + process.exit(1); +} diff --git a/output.svg b/output.svg new file mode 100644 index 0000000..73aa917 --- /dev/null +++ b/output.svg @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + Yes + + + + No + + + + Start + + + + Decision + + + + Action + + + + End + + \ No newline at end of file