convert to cli tool
This commit is contained in:
parent
48040a4f56
commit
5848b471ec
4 changed files with 91 additions and 7 deletions
36
index.ts
36
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 <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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue