@mermaid-js/mermaid-cli 9.3.0 → 10.0.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 +10 -2
- package/dist/index.html +926 -643
- package/package.json +3 -3
- package/src/index.js +27 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mermaid-js/mermaid-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "Command-line interface for mermaid",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "git@github.com:mermaid-js/mermaid-cli.git",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"chalk": "^5.0.1",
|
|
25
|
-
"commander": "^
|
|
25
|
+
"commander": "^10.0.0",
|
|
26
26
|
"puppeteer": "^19.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@fortawesome/fontawesome-free-webfonts": "^1.0.9",
|
|
30
30
|
"@mermaid-js/mermaid-mindmap": "^9.2.2",
|
|
31
|
-
"mermaid": "^
|
|
31
|
+
"mermaid": "^10.0.0",
|
|
32
32
|
"jest": "^29.0.1",
|
|
33
33
|
"standard": "^17.0.0",
|
|
34
34
|
"vite": "^4.0.3",
|
package/src/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const error = message => {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const warn = message => {
|
|
21
|
-
console.
|
|
21
|
+
console.warn(chalk.yellow(`\n${message}\n`))
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const checkConfigFile = file => {
|
|
@@ -27,8 +27,6 @@ const checkConfigFile = file => {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const inputPipedFromStdin = () => fs.fstatSync(0).isFIFO()
|
|
31
|
-
|
|
32
30
|
const getInputData = async inputFile => new Promise((resolve, reject) => {
|
|
33
31
|
// if an input file has been specified using '-i', it takes precedence over
|
|
34
32
|
// piping from stdin
|
|
@@ -84,7 +82,7 @@ async function cli () {
|
|
|
84
82
|
.addOption(new Option('-t, --theme [theme]', 'Theme of the chart').choices(['default', 'forest', 'dark', 'neutral']).default('default'))
|
|
85
83
|
.addOption(new Option('-w, --width [width]', 'Width of the page').argParser(parseCommanderInt).default(800))
|
|
86
84
|
.addOption(new Option('-H, --height [height]', 'Height of the page').argParser(parseCommanderInt).default(600))
|
|
87
|
-
.option('-i, --input <input>', 'Input mermaid file. Files ending in .md will be treated as Markdown and all charts (e.g. ```mermaid (...)```) will be extracted and generated.
|
|
85
|
+
.option('-i, --input <input>', 'Input mermaid file. Files ending in .md will be treated as Markdown and all charts (e.g. ```mermaid (...)```) will be extracted and generated. Use `-` to read from stdin.')
|
|
88
86
|
.option('-o, --output [output]', 'Output file. It should be either md, svg, png or pdf. Optional. Default: input + ".svg"')
|
|
89
87
|
.addOption(new Option('-e, --outputFormat [format]', 'Output format for the generated image.').choices(['svg', 'png', 'pdf']).default(null, 'Loaded from the output file extension'))
|
|
90
88
|
.addOption(new Option('-b, --backgroundColor [backgroundColor]', 'Background color for pngs/svgs (not pdfs). Example: transparent, red, \'#F0F0F0\'.').default('white'))
|
|
@@ -101,12 +99,15 @@ async function cli () {
|
|
|
101
99
|
let { theme, width, height, input, output, outputFormat, backgroundColor, configFile, cssFile, puppeteerConfigFile, scale, pdfFit, quiet } = options
|
|
102
100
|
|
|
103
101
|
// check input file
|
|
104
|
-
if (!
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (input
|
|
102
|
+
if (!input) {
|
|
103
|
+
warn('No input file specfied, reading from stdin. ' +
|
|
104
|
+
'If you want to specify an input file, please use `-i <input>.` ' +
|
|
105
|
+
'You can use `-i -` to read from stdin and to suppress this warning.'
|
|
106
|
+
)
|
|
107
|
+
} else if (input === '-') {
|
|
108
|
+
// `--input -` means read from stdin, but suppress the above warning
|
|
109
|
+
input = undefined
|
|
110
|
+
} else if (!fs.existsSync(input)) {
|
|
110
111
|
error(`Input file "${input}" doesn't exist`)
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -121,8 +122,8 @@ async function cli () {
|
|
|
121
122
|
output = input ? (`${input}.svg`) : 'out.svg'
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
|
-
if (!/\.(?:svg|png|pdf|md)$/.test(output)) {
|
|
125
|
-
error('Output file must end with ".md", ".svg", ".png" or ".pdf"')
|
|
125
|
+
if (!/\.(?:svg|png|pdf|md|markdown)$/.test(output)) {
|
|
126
|
+
error('Output file must end with ".md"/".markdown", ".svg", ".png" or ".pdf"')
|
|
126
127
|
}
|
|
127
128
|
const outputDir = path.dirname(output)
|
|
128
129
|
if (!fs.existsSync(outputDir)) {
|
|
@@ -225,7 +226,10 @@ async function renderMermaid (browser, definition, outputFormat, { viewport, bac
|
|
|
225
226
|
mermaid.initialize(mermaidConfig)
|
|
226
227
|
// should throw an error if mmd diagram is invalid
|
|
227
228
|
try {
|
|
228
|
-
await mermaid.
|
|
229
|
+
await mermaid.run({
|
|
230
|
+
nodes: [container],
|
|
231
|
+
suppressErrors: false
|
|
232
|
+
})
|
|
229
233
|
} catch (error) {
|
|
230
234
|
if (error instanceof Error) {
|
|
231
235
|
// mermaid-js doesn't currently throws JS Errors, but let's leave this
|
|
@@ -346,10 +350,11 @@ function markdownImage ({ url, title, alt }) {
|
|
|
346
350
|
/**
|
|
347
351
|
* Renders a mermaid diagram or mermaid markdown file.
|
|
348
352
|
*
|
|
349
|
-
* @param {`${string}
|
|
353
|
+
* @param {`${string}.${"md" | "markdown"}` | string} [input] - If this ends with `.md`/`.markdown`,
|
|
354
|
+
* path to a markdown file containing mermaid.
|
|
350
355
|
* If this is a string, loads the mermaid definition from the given file.
|
|
351
356
|
* If this is `undefined`, loads the mermaid definition from stdin.
|
|
352
|
-
* @param {`${string}.${"md" | "svg" | "png" | "pdf"}`} output - Path to the output file.
|
|
357
|
+
* @param {`${string}.${"md" | "markdown" | "svg" | "png" | "pdf"}`} output - Path to the output file.
|
|
353
358
|
* @param {Object} [opts] - Options
|
|
354
359
|
* @param {puppeteer.LaunchOptions} [opts.puppeteerConfig] - Puppeteer launch options.
|
|
355
360
|
* @param {boolean} [opts.quiet] - If set, suppress log output.
|
|
@@ -372,7 +377,7 @@ async function run (input, output, { puppeteerConfig = {}, quiet = false, output
|
|
|
372
377
|
if (!outputFormat) {
|
|
373
378
|
outputFormat = path.extname(output).replace('.', '')
|
|
374
379
|
}
|
|
375
|
-
if (outputFormat === 'md') {
|
|
380
|
+
if (outputFormat === 'md' || outputFormat === 'markdown') {
|
|
376
381
|
// fallback to svg in case no outputFormat is given and output file is MD
|
|
377
382
|
outputFormat = 'svg'
|
|
378
383
|
}
|
|
@@ -381,7 +386,7 @@ async function run (input, output, { puppeteerConfig = {}, quiet = false, output
|
|
|
381
386
|
}
|
|
382
387
|
|
|
383
388
|
const definition = await getInputData(input)
|
|
384
|
-
if (/\.md$/.test(input)) {
|
|
389
|
+
if (/\.(md|markdown)$/.test(input)) {
|
|
385
390
|
const imagePromises = []
|
|
386
391
|
for (const mermaidCodeblockMatch of definition.matchAll(mermaidChartsInMarkdownRegexGlobal)) {
|
|
387
392
|
const mermaidDefinition = mermaidCodeblockMatch[1]
|
|
@@ -391,7 +396,10 @@ async function run (input, output, { puppeteerConfig = {}, quiet = false, output
|
|
|
391
396
|
// I.e. if "out.png", use "out-1.png", "out-2.png", etc
|
|
392
397
|
// If it is an output `.md` file, use that to base .svg numbered diagrams on
|
|
393
398
|
// I.e. if "out.md". use "out-1.svg", "out-2.svg", etc
|
|
394
|
-
const outputFile = output.replace(
|
|
399
|
+
const outputFile = output.replace(
|
|
400
|
+
/(\.(md|markdown|png|svg|pdf))$/,
|
|
401
|
+
`-${imagePromises.length + 1}$1`
|
|
402
|
+
).replace(/\.(md|markdown)$/, `.${outputFormat}`)
|
|
395
403
|
const outputFileRelative = `./${path.relative(path.dirname(path.resolve(output)), path.resolve(outputFile))}`
|
|
396
404
|
|
|
397
405
|
const imagePromise = (async () => {
|
|
@@ -416,7 +424,7 @@ async function run (input, output, { puppeteerConfig = {}, quiet = false, output
|
|
|
416
424
|
|
|
417
425
|
const images = await Promise.all(imagePromises)
|
|
418
426
|
|
|
419
|
-
if (/\.md$/.test(output)) {
|
|
427
|
+
if (/\.(md|markdown)$/.test(output)) {
|
|
420
428
|
const outDefinition = definition.replace(mermaidChartsInMarkdownRegexGlobal, (_mermaidMd) => {
|
|
421
429
|
// pop first image from front of array
|
|
422
430
|
const { url, title, alt } = images.shift()
|