convert to cli tool

This commit is contained in:
Travis Shears 2026-03-20 10:49:36 +01:00
parent 48040a4f56
commit 5848b471ec
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
4 changed files with 91 additions and 7 deletions

View file

@ -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 <input.mmd> <output.svg>");
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);
}