CLI Reference
Complete reference for all CLI commands and flags.
grafex init
Scaffold the minimal setup to start writing compositions. Run this in a new project after npm install grafex.
grafex initCreates two files in the current directory:
tsconfig.json— TypeScript config with the correct JSX settings for Grafexcomposition.tsx— A starter composition with a "Hello, Grafex!" example
If either file already exists, it is skipped without error.
Flags
| Flag | Short | Description |
|---|---|---|
--help | -h | Show help text |
grafex export
Render a composition file to an image.
grafex export -f <file> [options]Flags
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--file | -f | string | — | Path to the .tsx composition file (required) |
--out | -o | string | ./output.png | Output file path or directory (for multi-variant output) |
--props | — | string (JSON) | {} | Props to pass to the composition as a JSON object |
--width | — | number | from config | Override composition width in pixels |
--height | — | number | from config | Override composition height in pixels |
--scale | — | number | 1 | Device pixel ratio — 2 for retina/high-DPI output |
--format | — | string | png | Output format: png or jpeg |
--quality | — | number | 90 | JPEG quality 1–100 (only applies when format is jpeg) |
--browser | — | string | webkit | Browser engine: webkit or chromium |
--variant | — | string | (all) | Render a single variant by name. Omit to render all variants. |
--help | -h | — | | Show help text |
Examples
Basic export:
grafex export -f card.tsx -o card.pngPass props to a composition:
grafex export -f card.tsx -o card.png --props '{"title":"Hello World","author":"Jane"}'Override dimensions:
grafex export -f card.tsx -o card.png --width 800 --height 400Export to a specific directory:
grafex export -f card.tsx -o ./images/card.pngExport at 2x resolution (retina):
grafex export -f card.tsx -o card@2x.png --scale 2Export as JPEG:
grafex export -f card.tsx -o card.jpg --format jpegExport as JPEG with custom quality:
grafex export -f card.tsx -o card.jpg --format jpeg --quality 80Export all variants (when config.variants is defined):
grafex export -f card.tsxExport all variants to a directory:
grafex export -f card.tsx -o ./images/Export a single variant:
grafex export -f card.tsx --variant twitter -o twitter.pngExit codes
| Code | Meaning |
|---|---|
0 | Success — image exported |
1 | Error — composition failed to render (check stderr for details) |
grafex dev
Start a live preview server that watches your composition and re-renders on every file change.
grafex dev -f <file> [options]Flags
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--file | -f | string | — | Path to the .tsx composition file (required) |
--port | — | number | 3000 | Preview server port |
--props | — | string (JSON) | {} | Props to pass to the composition as a JSON object |
--variant | — | string | (first) | Show only the named variant (when composition has variants) |
--help | -h | — | | Show help text |
The dev server watches the composition file, all its imports, CSS files from config.css, and local image assets. Changes are debounced and the preview updates within ~100ms. Open http://localhost:3000 to see the live preview. Press Ctrl+C to stop.
Global Flags
grafex --version # Print version and exit
grafex --help # Print help text and exit