@eraserlabs/diagrams-cli (英语)
导言
@eraserlabs/diagrams-cli 是命令行接口 擦除图它使图表 JSON 变成 PNG 或 HTML ,并在没有浏览器的情况下验证文档,使用 @eraserlabs/diagrams。 。 。 .
使用量
npm install -D @eraserlabs/diagrams-cli
npx eraser-diagrams render diagram.json -o diagram.png
需要Node.js 22.23.4+, 24.22.1+, 或 26.12.1+, 以及机器上的铬-家族浏览器(不捆绑).
eraser-diagrams render <input...> Render diagram JSON to PNG or HTML (needs Chromium)
eraser-diagrams validate <input...> Validate diagram JSON without a browser
eraser-diagrams registry Print the tag registry as JSON
eraser-diagrams schema <tag> Print the JSON Schema of one tag
eraser-diagrams init Write eraser-diagrams.config.json in the current directory
<input> 是文件路径或 - 为斯丁。 一些投入共享了一台暖气浏览器. 接受的文件为: { "elements": [...] } 或拆分 { "entities": [...], "connections": [...] }空 JSON 阵列失败 E_ENVELOPEA级 { "definition": { "elements": [...] } } 包装被抬起,上面有条纸条.
提供选项
| 旗帜 | 默认 | 效果 |
|---|---|---|
-o, --out <path> | <input>.<format> 在输出目录中(diagram.<format> 用于 stdin) | 单个输入输出文件 . -o - 将字节写入 stdout . |
--out-dir <dir> | 当前目录 | 输出去处; 缺失时创建 . |
-f, --format png|html | png | 输出格式。 HTML 引用每个字体的来源(inline: true 嵌入文件面孔). |
--scale <n> | 1 | PNG 像素密度 (% 1)deviceScaleFactor· ; 2 视网膜。 为 HTML 忽略 . |
--transparent | 关 | 保持PNG背景透明. 忽略 HTML; 作者填充仍然可见 . |
--pages <n> | 1 | 温暖的 Chromium 页面池; 更多的页面同时提供更多的输入 . |
--chromium-path <path> | 见下文 | 铬可执行文件. |
--fonts <path> | 库存字体 | 字体配置 JSON 文件 . |
--icon-base-url <url> | Eraser 的公共目录 | 图标主机 : <url>/<name>.svg。 。 。 . |
--icon-cache-dir <dir> | 无 | 上盘图标缓存 . |
--unknown-icon placeholder|error | placeholder | 未知图标名称:占位符 glyph + 警告,或硬错误. |
--json | 关 | 机器可读的 stdout上的报告(没有其他的去 stdout). |
--fail-on-warning | 关 | 在报告任何警告(包括已退化的字体)时退出 1 . |
-q, --quiet | 关 | 没有输入状态行; 失败仍在打印 . |
--debug | 关 | 阶段计时和Stderr上的配置/铬出处. |
对于具有透明背景的巴布亚新几内亚:
eraser-diagrams render diagram.json --transparent --scale 2 -o diagram.png
validate 接受 --json, (中文(简体) ), --fail-on-warning, (中文(简体) ), --quiet, (中文(简体) ), --debug。 。 。 .
全球备选方案
| 旗帜 | 效果 |
|---|---|
-c, --config <path> | 要使用的配置文件 . |
--no-config | 忽略配置文件 . |
--print-config | 打印有效配置(合并后)并退出. |
-h, --help, (中文(简体) ), -v, --version | 帮助/ 版本. |
铬
优先发言: --chromium-path > 翻译: CHROMIUM_PATH > 翻译: chromiumPath 在配置文件 > 自动检测中。 自动探测探测器 通常的Chrome和Chromium 安装位置 并报告它选择的. eraser-diagrams init 将检测到的路径写入配置文件, 使其保持被绑定 .
配置文件
eraser-diagrams.config.json 是通过从当前目录上走来找到的(在包含 .git)),或给予 --config 或者说 ERASER_DIAGRAMS_CONFIG优先是 旗帜 > 环境 > 配置文件 > 默认。相对于文件本身的目录,文件解析中的相对路径。 未知密钥被拒绝 .
{
"chromiumPath": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"format": "png",
"outDir": "./diagrams",
"deviceScaleFactor": 2,
"pages": 2,
"icons": {
"baseUrl": "https://storage.googleapis.com/eraser-public-assets/canvas-icons/",
"cacheDir": "./.eraser/icons",
"timeoutMs": 5000,
"cacheTtlMs": 86400000,
"onUnknown": "placeholder"
},
"fonts": "./fonts.json",
"library": "./my-library.mjs",
"overrides": "./my-overrides.mjs",
"failOnWarning": false
}
| 密钥 | 类型 | 含义 |
|---|---|---|
chromiumPath | 字符串 | 铬可执行文件. |
format | "png" | "html" | 默认 --format。 。 。 . |
outDir | 字符串 | 默认 --out-dir。 。 。 . |
deviceScaleFactor | 编号 | 默认 --scale。 。 。 . |
transparent | 布尔 | 默认 --transparent (虚也. |
pages | 编号 | 默认 --pages。 。 。 . |
icons.baseUrl, (中文(简体) ), icons.cacheDir, (中文(简体) ), icons.timeoutMs, (中文(简体) ), icons.cacheTtlMs | 图标加载器设置( E)createEraserIconLoader) (中文(简体) ). | |
icons.onUnknown | "placeholder" | "error" | 未知图标策略 . |
fonts | 对象或字符串 | A 类 FontsConfig 对象,或 JSON 文件的路径. path 编号 : cachePath 里面有与申报他们的档案相对立的意志. |
library | 字符串 | ES 模块路径导出 library (单位:千美元) AuthoredLibrary)和可选 normalizers。替换股票库;见 计算机化.md。 。 。 . |
overrides | 字符串 | ES 模块路径导出 overrides (单位:千美元){ templates: TemplateFile[] }: 组件按名称合并到库上. |
failOnWarning | 布尔 | 默认 --fail-on-warning。 。 。 . |
除了别的事 --format 而输出路径在浏览器靴子时被固定,因此适用于整批.
输出和退出代码
状态到 stderr,每输入一行,然后是问题:
ok diagram.json → out/diagram.png 412 ms 1 warning
warning W_UNKNOWN_ICON /elements/1/icon (Icon#api) — Unknown icon "nodejs"; using a placeholder glyph.
FAIL other.json E_UNKNOWN_TAG
error E_UNKNOWN_TAG /elements/0 (Shpe) — Unknown tag "Shpe". Did you mean "Shape"?
--json 在 stdout 上打印一个报表:
{
"ok": false,
"degradedFonts": [],
"results": [
{
"input": "diagram.json",
"out": "out/diagram.png",
"ok": true,
"errors": [],
"warnings": [],
"ms": 412
},
{
"input": "other.json",
"ok": false,
"errors": [
{
"code": "E_UNKNOWN_TAG",
"severity": "error",
"path": "/elements/0",
"message": "Unknown tag \"Shpe\".",
"suggestion": "Shape"
}
],
"warnings": []
}
]
}
| 退出代码 | 含义 |
|---|---|
0 | 每次输入都成功(允许警告,除非 --fail-on-warning) (中文(简体) ). |
1 | 至少一个输入失败:无法读取的文件,无效的JSON,验证错误,或失败的渲染. |
2 | 引用本身失败:旗子不好,配置文件不好,没有Chromium,自定义库被拒绝. |
Ctrl-C 退出前关闭铬.