From 0a6fb0e9547799617718ea59fcbcf9661d20f8da Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Fri, 20 Mar 2026 12:35:44 +0100 Subject: [PATCH] add readme --- README.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++---- bun.lock | 3 +++ index.ts | 10 +++++++-- package.json | 3 ++- 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fe789fe..212a2a8 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,65 @@ # mermaid-diagram-creator -To install dependencies: +A CLI tool to convert Mermaid diagram files (.mmd) to SVG format. + +## Features + +- Convert Mermaid diagram text files to SVG +- Easy command-line interface +- Fast rendering with `beautiful-mermaid` +- Input validation with Zod + +## Installation + +### 1. Set up the project ```bash bun install ``` -To run: +### 2. Create symlink to your user bin directory ```bash -bun run index.ts +ln -s /Users/my_user_name/project_dir/mermaid-diagram-creator/bin/mmd-to-svg ~/.local/bin/mmd-to-svg ``` -This project was created using `bun init` in bun v1.2.21. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime. +## Usage + +```bash +mmd-to-svg +``` + +### Hot Reloading + +Using [entr](https://github.com/eradman/entr) + +```bash +echo docs/diagrams/create_thing.mmd | entr mmd-to-svg ./docs/diagrams/create_thing.mmd ./docs/diagrams/create.svg +``` + +### Example + +```bash +mmd-to-svg example.mmd diagram.svg +``` + +This will read the Mermaid diagram from `example.mmd` and output the rendered SVG to `diagram.svg`. + +### Example diagram file (example.mmd) + +```mermaid +graph TD + A[Start] --> B{Decision} + B -->|Yes| C[Action] + B -->|No| D[End] +``` + +## Development + +Run directly: + +```bash +bun index.ts example.mmd output.svg +``` + +Built with [Bun](https://bun.com) - a fast all-in-one JavaScript runtime. diff --git a/bun.lock b/bun.lock index 5c01dd5..532678e 100644 --- a/bun.lock +++ b/bun.lock @@ -5,6 +5,7 @@ "name": "mermaid-diagram-creator", "dependencies": { "beautiful-mermaid": "^1.1.3", + "zod": "^4.3.6", }, "devDependencies": { "@types/bun": "latest", @@ -30,5 +31,7 @@ "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], "undici-types": ["undici-types@7.18.2", "", {}, "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w=="], + + "zod": ["zod@4.3.6", "", {}, "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg=="], } } diff --git a/index.ts b/index.ts index 08bbcee..353d19f 100644 --- a/index.ts +++ b/index.ts @@ -1,3 +1,4 @@ +import { z } from "zod"; import { renderMermaidSVG } from "beautiful-mermaid"; const args = process.argv.slice(2); @@ -8,7 +9,10 @@ if (args.length < 2) { process.exit(1); } -const [inputPath, outputPath] = args; +const argsSchema = z.tuple([z.string(), z.string()]); + +const parsed = argsSchema.parse(args); +const [inputPath, outputPath] = parsed; try { // Read the .mmd file @@ -25,7 +29,9 @@ try { 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)}`); + console.error( + `✗ Error: ${error instanceof Error ? error.message : String(error)}`, + ); } process.exit(1); } diff --git a/package.json b/package.json index 67b561b..f381a51 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "typescript": "^5" }, "dependencies": { - "beautiful-mermaid": "^1.1.3" + "beautiful-mermaid": "^1.1.3", + "zod": "^4.3.6" } }