@mermaid-js/mermaid-cli 11.4.2 → 11.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -11
- package/dist/assets/index-DQukWeul.js +38 -0
- package/dist/index.html +1 -1
- package/dist-types/src/index.d.ts +10 -3
- package/dist-types/src/index.d.ts.map +1 -1
- package/dist-types/src/version.d.ts +1 -1
- package/package.json +3 -2
- package/src/index.js +40 -11
- package/src/version.js +1 -1
- package/dist/assets/index-BgzLmH-2.js +0 -38
package/dist/index.html
CHANGED
|
@@ -26,10 +26,14 @@ export type ParseMDDOptions = {
|
|
|
26
26
|
* - The id attribute for the SVG element to be rendered.
|
|
27
27
|
*/
|
|
28
28
|
svgId?: string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* - Icon packages to use.
|
|
31
|
+
*/
|
|
32
|
+
iconPacks?: string[] | undefined;
|
|
29
33
|
};
|
|
30
34
|
/**
|
|
31
35
|
* Markdown image properties
|
|
32
|
-
* Used to create
|
|
36
|
+
* Used to create a markdown image that looks like ``
|
|
33
37
|
*/
|
|
34
38
|
export type MarkdownImageProps = {
|
|
35
39
|
/**
|
|
@@ -57,13 +61,15 @@ export type MarkdownImageProps = {
|
|
|
57
61
|
* @param {import("puppeteer").LaunchOptions} [opts.puppeteerConfig] - Puppeteer launch options.
|
|
58
62
|
* @param {boolean} [opts.quiet] - If set, suppress log output.
|
|
59
63
|
* @param {"svg" | "png" | "pdf"} [opts.outputFormat] - Mermaid output format.
|
|
64
|
+
* @param {string} [opts.artefacts] - Path to the artefacts directory.
|
|
60
65
|
* Defaults to `output` extension. Overrides `output` extension if set.
|
|
61
66
|
* @param {ParseMDDOptions} [opts.parseMMDOptions] - Options to pass to {@link parseMMDOptions}.
|
|
62
67
|
*/
|
|
63
|
-
export function run(input: `${string}.${"md" | "markdown"}` | string | undefined, output: `${string}.${"md" | "markdown" | "svg" | "png" | "pdf"}` | "/dev/stdout", { puppeteerConfig, quiet, outputFormat, parseMMDOptions }?: {
|
|
68
|
+
export function run(input: `${string}.${"md" | "markdown"}` | string | undefined, output: `${string}.${"md" | "markdown" | "svg" | "png" | "pdf"}` | "/dev/stdout", { puppeteerConfig, quiet, outputFormat, parseMMDOptions, artefacts }?: {
|
|
64
69
|
puppeteerConfig?: puppeteer.LaunchOptions | undefined;
|
|
65
70
|
quiet?: boolean | undefined;
|
|
66
71
|
outputFormat?: "svg" | "png" | "pdf" | undefined;
|
|
72
|
+
artefacts?: string | undefined;
|
|
67
73
|
parseMMDOptions?: ParseMDDOptions | undefined;
|
|
68
74
|
}): Promise<void>;
|
|
69
75
|
/**
|
|
@@ -74,6 +80,7 @@ export function run(input: `${string}.${"md" | "markdown"}` | string | undefined
|
|
|
74
80
|
* @property {CSSStyleDeclaration["cssText"]} [myCSS] - Optional CSS text.
|
|
75
81
|
* @property {boolean} [pdfFit] - If set, scale PDF to fit chart.
|
|
76
82
|
* @property {string} [svgId] - The id attribute for the SVG element to be rendered.
|
|
83
|
+
* @property {string[]} [iconPacks] - Icon packages to use.
|
|
77
84
|
*/
|
|
78
85
|
/**
|
|
79
86
|
* Render a mermaid diagram.
|
|
@@ -85,7 +92,7 @@ export function run(input: `${string}.${"md" | "markdown"}` | string | undefined
|
|
|
85
92
|
* @returns {Promise<{title: string | null, desc: string | null, data: Uint8Array}>} The output file in bytes,
|
|
86
93
|
* with optional metadata.
|
|
87
94
|
*/
|
|
88
|
-
export function renderMermaid(browser: import("puppeteer").Browser | import("puppeteer").BrowserContext, definition: string, outputFormat: "svg" | "png" | "pdf", { viewport, backgroundColor, mermaidConfig, myCSS, pdfFit, svgId }?: ParseMDDOptions): Promise<{
|
|
95
|
+
export function renderMermaid(browser: import("puppeteer").Browser | import("puppeteer").BrowserContext, definition: string, outputFormat: "svg" | "png" | "pdf", { viewport, backgroundColor, mermaidConfig, myCSS, pdfFit, svgId, iconPacks }?: ParseMDDOptions): Promise<{
|
|
89
96
|
title: string | null;
|
|
90
97
|
desc: string | null;
|
|
91
98
|
data: Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAgYc,MAAM;;;;SACN,MAAM;;;;;;AAqBpB;;;;;;;;;;;;;;;GAeG;AACH,2BAbW,GAAG,MAAM,IAAI,IAAI,GAAG,UAAU,EAAE,GAAG,MAAM,GAAG,SAAS,UAIrD,GAAG,MAAM,IAAI,IAAI,GAAG,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,EAAE,GAAG,aAAa,yEAEhF;IAAiD,eAAe;IACzC,KAAK;IACS,YAAY;IAC3B,SAAS;IAEA,eAAe;CAChD,iBAoHA;AAxTD;;;;;;;;;GASG;AAEH;;;;;;;;;GASG;AACH,uCAPW,OAAO,WAAW,EAAE,OAAO,GAAG,OAAO,WAAW,EAAE,cAAc,cAChE,MAAM,gBACN,KAAK,GAAG,KAAK,GAAG,KAAK,kFACrB,eAAe,GACb,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAC,CAAC,CAwIlF;AAnRD,qCAuHC;AA3MD;;;;;GAKG;AACH,+BAHW,MAAM,GACJ,KAAK,CAKjB;sBAxBqB,WAAW"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version: "11.
|
|
1
|
+
export const version: "11.6.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mermaid-js/mermaid-cli",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.6.0",
|
|
4
4
|
"description": "Command-line interface for mermaid",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "git@github.com:mermaid-js/mermaid-cli.git",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"prepare": "tsc && vite build",
|
|
26
26
|
"prepack": "tsc && vite build",
|
|
27
27
|
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
|
|
28
|
+
"test:cli": "bash run-tests.sh test-positive",
|
|
28
29
|
"version": "node scripts/version.js",
|
|
29
30
|
"lint": "standard",
|
|
30
31
|
"lint-fix": "standard --fix"
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"@mermaid-js/mermaid-zenuml": "^0.2.0",
|
|
34
35
|
"chalk": "^5.0.1",
|
|
35
|
-
"commander": "^
|
|
36
|
+
"commander": "^14.0.0",
|
|
36
37
|
"import-meta-resolve": "^4.1.0",
|
|
37
38
|
"mermaid": "^11.0.2"
|
|
38
39
|
},
|
package/src/index.js
CHANGED
|
@@ -97,7 +97,7 @@ async function getInputData (inputFile) {
|
|
|
97
97
|
function parseCommanderInt (value, _unused) {
|
|
98
98
|
const parsedValue = parseInt(value, 10)
|
|
99
99
|
if (isNaN(parsedValue) || parsedValue < 1) {
|
|
100
|
-
throw new InvalidArgumentError('Not
|
|
100
|
+
throw new InvalidArgumentError('Not a positive integer.')
|
|
101
101
|
}
|
|
102
102
|
return parsedValue
|
|
103
103
|
}
|
|
@@ -111,6 +111,7 @@ async function cli () {
|
|
|
111
111
|
.addOption(new Option('-H, --height [height]', 'Height of the page').argParser(parseCommanderInt).default(600))
|
|
112
112
|
.option('-i, --input <input>', 'Input mermaid file. Files ending in .md will be treated as Markdown and all charts (e.g. ```mermaid (...)``` or :::mermaid (...):::) will be extracted and generated. Use `-` to read from stdin.')
|
|
113
113
|
.option('-o, --output [output]', 'Output file. It should be either md, svg, png, pdf or use `-` to output to stdout. Optional. Default: input + ".svg"')
|
|
114
|
+
.option('-a, --artefacts [artefacts]', 'Output artefacts path. Only used with Markdown input file. Optional. Default: output directory')
|
|
114
115
|
.addOption(new Option('-e, --outputFormat [format]', 'Output format for the generated image.').choices(['svg', 'png', 'pdf']).default(null, 'Loaded from the output file extension'))
|
|
115
116
|
.addOption(new Option('-b, --backgroundColor [backgroundColor]', 'Background color for pngs/svgs (not pdfs). Example: transparent, red, \'#F0F0F0\'.').default('white'))
|
|
116
117
|
.option('-c, --configFile [configFile]', 'JSON configuration file for mermaid.')
|
|
@@ -120,11 +121,12 @@ async function cli () {
|
|
|
120
121
|
.option('-f, --pdfFit', 'Scale PDF to fit chart')
|
|
121
122
|
.option('-q, --quiet', 'Suppress log output')
|
|
122
123
|
.option('-p --puppeteerConfigFile [puppeteerConfigFile]', 'JSON configuration file for puppeteer.')
|
|
124
|
+
.option('--iconPacks <icons...>', 'Icon packs to use, e.g. @iconify-json/logos. These should be Iconify NPM packages that expose a icons.json file, see https://iconify.design/docs/icons/json.html. These will be downloaded from https://unkpg.com when needed.', [])
|
|
123
125
|
.parse(process.argv)
|
|
124
126
|
|
|
125
127
|
const options = commander.opts()
|
|
126
128
|
|
|
127
|
-
let { theme, width, height, input, output, outputFormat, backgroundColor, configFile, cssFile, svgId, puppeteerConfigFile, scale, pdfFit, quiet } = options
|
|
129
|
+
let { theme, width, height, input, output, outputFormat, backgroundColor, configFile, cssFile, svgId, puppeteerConfigFile, scale, pdfFit, quiet, iconPacks, artefacts } = options
|
|
128
130
|
|
|
129
131
|
// check input file
|
|
130
132
|
if (!input) {
|
|
@@ -157,7 +159,7 @@ async function cli () {
|
|
|
157
159
|
if (!outputFormat) {
|
|
158
160
|
outputFormat = 'svg'
|
|
159
161
|
warn('No output format specified, using svg. ' +
|
|
160
|
-
'If you want to specify an output format and
|
|
162
|
+
'If you want to specify an output format and suppress this warning, ' +
|
|
161
163
|
'please use `-e <format>.` '
|
|
162
164
|
)
|
|
163
165
|
}
|
|
@@ -165,6 +167,15 @@ async function cli () {
|
|
|
165
167
|
error('Output file must end with ".md"/".markdown", ".svg", ".png" or ".pdf"')
|
|
166
168
|
}
|
|
167
169
|
|
|
170
|
+
if (artefacts) {
|
|
171
|
+
if (!input || !/\.(?:md|markdown)$/.test(input)) {
|
|
172
|
+
error('Artefacts [-a|--artefacts] path can only be used with Markdown input file')
|
|
173
|
+
}
|
|
174
|
+
if (!fs.existsSync(artefacts)) {
|
|
175
|
+
fs.mkdirSync(artefacts, { recursive: true })
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
168
179
|
const outputDir = path.dirname(output)
|
|
169
180
|
if (output !== '/dev/stdout' && !fs.existsSync(outputDir)) {
|
|
170
181
|
error(`Output directory "${outputDir}/" doesn't exist`)
|
|
@@ -205,8 +216,9 @@ async function cli () {
|
|
|
205
216
|
quiet,
|
|
206
217
|
outputFormat,
|
|
207
218
|
parseMMDOptions: {
|
|
208
|
-
mermaidConfig, backgroundColor, myCSS, pdfFit, viewport: { width, height, deviceScaleFactor: scale }, svgId
|
|
209
|
-
}
|
|
219
|
+
mermaidConfig, backgroundColor, myCSS, pdfFit, viewport: { width, height, deviceScaleFactor: scale }, svgId, iconPacks
|
|
220
|
+
},
|
|
221
|
+
artefacts
|
|
210
222
|
}
|
|
211
223
|
)
|
|
212
224
|
}
|
|
@@ -219,6 +231,7 @@ async function cli () {
|
|
|
219
231
|
* @property {CSSStyleDeclaration["cssText"]} [myCSS] - Optional CSS text.
|
|
220
232
|
* @property {boolean} [pdfFit] - If set, scale PDF to fit chart.
|
|
221
233
|
* @property {string} [svgId] - The id attribute for the SVG element to be rendered.
|
|
234
|
+
* @property {string[]} [iconPacks] - Icon packages to use.
|
|
222
235
|
*/
|
|
223
236
|
|
|
224
237
|
/**
|
|
@@ -231,7 +244,7 @@ async function cli () {
|
|
|
231
244
|
* @returns {Promise<{title: string | null, desc: string | null, data: Uint8Array}>} The output file in bytes,
|
|
232
245
|
* with optional metadata.
|
|
233
246
|
*/
|
|
234
|
-
async function renderMermaid (browser, definition, outputFormat, { viewport, backgroundColor = 'white', mermaidConfig = {}, myCSS, pdfFit, svgId } = {}) {
|
|
247
|
+
async function renderMermaid (browser, definition, outputFormat, { viewport, backgroundColor = 'white', mermaidConfig = {}, myCSS, pdfFit, svgId, iconPacks = [] } = {}) {
|
|
235
248
|
const page = await browser.newPage()
|
|
236
249
|
page.on('console', (msg) => {
|
|
237
250
|
console.warn(msg.text())
|
|
@@ -249,7 +262,7 @@ async function renderMermaid (browser, definition, outputFormat, { viewport, bac
|
|
|
249
262
|
page.addScriptTag({ path: mermaidIIFEPath }),
|
|
250
263
|
page.addScriptTag({ path: zenumlIIFEPath })
|
|
251
264
|
])
|
|
252
|
-
const metadata = await page.$eval('#container', async (container, definition, mermaidConfig, myCSS, backgroundColor, svgId) => {
|
|
265
|
+
const metadata = await page.$eval('#container', async (container, definition, mermaidConfig, myCSS, backgroundColor, svgId, iconPacks) => {
|
|
253
266
|
await Promise.all(Array.from(document.fonts, (font) => font.load()))
|
|
254
267
|
|
|
255
268
|
/**
|
|
@@ -264,6 +277,16 @@ async function renderMermaid (browser, definition, outputFormat, { viewport, bac
|
|
|
264
277
|
|
|
265
278
|
await mermaid.registerExternalDiagrams([zenuml])
|
|
266
279
|
mermaid.registerLayoutLoaders(elkLayouts)
|
|
280
|
+
// lazy load icon packs
|
|
281
|
+
mermaid.registerIconPacks(
|
|
282
|
+
iconPacks.map((icon) => ({
|
|
283
|
+
name: icon.split('/')[1],
|
|
284
|
+
loader: () =>
|
|
285
|
+
fetch(`https://unpkg.com/${icon}/icons.json`)
|
|
286
|
+
.then((res) => res.json())
|
|
287
|
+
.catch(() => error(`Failed to fetch icon: ${icon}`))
|
|
288
|
+
}))
|
|
289
|
+
)
|
|
267
290
|
mermaid.initialize({ startOnLoad: false, ...mermaidConfig })
|
|
268
291
|
// should throw an error if mmd diagram is invalid
|
|
269
292
|
const { svg: svgText } = await mermaid.render(svgId || 'my-svg', definition, container)
|
|
@@ -302,7 +325,7 @@ async function renderMermaid (browser, definition, outputFormat, { viewport, bac
|
|
|
302
325
|
return {
|
|
303
326
|
title, desc
|
|
304
327
|
}
|
|
305
|
-
}, definition, mermaidConfig, myCSS, backgroundColor, svgId)
|
|
328
|
+
}, definition, mermaidConfig, myCSS, backgroundColor, svgId, iconPacks)
|
|
306
329
|
|
|
307
330
|
if (outputFormat === 'svg') {
|
|
308
331
|
const svgXML = await page.$eval('svg', (svg) => {
|
|
@@ -358,7 +381,7 @@ async function renderMermaid (browser, definition, outputFormat, { viewport, bac
|
|
|
358
381
|
|
|
359
382
|
/**
|
|
360
383
|
* @typedef {object} MarkdownImageProps Markdown image properties
|
|
361
|
-
* Used to create
|
|
384
|
+
* Used to create a markdown image that looks like ``
|
|
362
385
|
* @property {string} url - Path to image.
|
|
363
386
|
* @property {string} alt - Image alt text, required.
|
|
364
387
|
* @property {string | null} [title] - Optional image title text.
|
|
@@ -393,10 +416,11 @@ function markdownImage ({ url, title, alt }) {
|
|
|
393
416
|
* @param {import("puppeteer").LaunchOptions} [opts.puppeteerConfig] - Puppeteer launch options.
|
|
394
417
|
* @param {boolean} [opts.quiet] - If set, suppress log output.
|
|
395
418
|
* @param {"svg" | "png" | "pdf"} [opts.outputFormat] - Mermaid output format.
|
|
419
|
+
* @param {string} [opts.artefacts] - Path to the artefacts directory.
|
|
396
420
|
* Defaults to `output` extension. Overrides `output` extension if set.
|
|
397
421
|
* @param {ParseMDDOptions} [opts.parseMMDOptions] - Options to pass to {@link parseMMDOptions}.
|
|
398
422
|
*/
|
|
399
|
-
async function run (input, output, { puppeteerConfig = {}, quiet = false, outputFormat, parseMMDOptions } = {}) {
|
|
423
|
+
async function run (input, output, { puppeteerConfig = {}, quiet = false, outputFormat, parseMMDOptions, artefacts } = {}) {
|
|
400
424
|
/**
|
|
401
425
|
* Logs the given message to stdout, unless `quiet` is set to `true`.
|
|
402
426
|
*
|
|
@@ -453,10 +477,15 @@ async function run (input, output, { puppeteerConfig = {}, quiet = false, output
|
|
|
453
477
|
* I.e. if "out.md". use "out-1.svg", "out-2.svg", etc
|
|
454
478
|
* @type {string}
|
|
455
479
|
*/
|
|
456
|
-
|
|
480
|
+
let outputFile = output.replace(
|
|
457
481
|
/(\.(md|markdown|png|svg|pdf))$/,
|
|
458
482
|
`-${imagePromises.length + 1}$1`
|
|
459
483
|
).replace(/\.(md|markdown)$/, `.${outputFormat}`)
|
|
484
|
+
|
|
485
|
+
if (artefacts) {
|
|
486
|
+
outputFile = path.resolve(artefacts, path.basename(outputFile))
|
|
487
|
+
}
|
|
488
|
+
|
|
460
489
|
const outputFileRelative = `./${path.relative(path.dirname(path.resolve(output)), path.resolve(outputFile))}`
|
|
461
490
|
|
|
462
491
|
const imagePromise = (async () => {
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '11.
|
|
1
|
+
export const version = '11.6.0'
|