@mermaid-js/mermaid-cli 9.2.2 → 9.3.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 +39 -22
- package/dist/assets/{fa-brands-400.ce2af7e2.svg → fa-brands-400-ce2af7e2.svg} +0 -0
- package/dist/assets/{fa-regular-400.e519b693.svg → fa-regular-400-e519b693.svg} +0 -0
- package/dist/assets/{fa-solid-900.3e918c25.svg → fa-solid-900-3e918c25.svg} +0 -0
- package/dist/index.html +220 -216
- package/package.json +4 -4
- package/src/index.js +30 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mermaid-js/mermaid-cli",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0",
|
|
4
4
|
"description": "Command-line interface for mermaid",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "git@github.com:mermaid-js/mermaid-cli.git",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"mmdc": "./src/cli.js"
|
|
11
11
|
},
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": "
|
|
13
|
+
"node": "^14.13 || >=16.0"
|
|
14
14
|
},
|
|
15
15
|
"exports": "./src/index.js",
|
|
16
16
|
"scripts": {
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"mermaid": "^9.2.2",
|
|
32
32
|
"jest": "^29.0.1",
|
|
33
33
|
"standard": "^17.0.0",
|
|
34
|
-
"vite": "^
|
|
34
|
+
"vite": "^4.0.3",
|
|
35
35
|
"vite-plugin-singlefile": "^0.13.1",
|
|
36
|
-
"vite-svg-loader": "^
|
|
36
|
+
"vite-svg-loader": "^4.0.0",
|
|
37
37
|
"yarn-upgrade-all": "^0.7.0"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command } from 'commander'
|
|
1
|
+
import { Command, Option, InvalidArgumentError } from 'commander'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
import path from 'path'
|
|
@@ -60,23 +60,40 @@ const getInputData = async inputFile => new Promise((resolve, reject) => {
|
|
|
60
60
|
})
|
|
61
61
|
})
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Commander parser that converts a string to an integer.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} value - The value from commander.
|
|
67
|
+
* @param {*} _unused - Unused.
|
|
68
|
+
* @returns {number} The value parsed as a number.
|
|
69
|
+
* @throws {InvalidArgumentError} If the arg is not valid.
|
|
70
|
+
* @see https://github.com/tj/commander.js/wiki/Class:-Option#argparserfn
|
|
71
|
+
*/
|
|
72
|
+
function parseCommanderInt (value, _unused) {
|
|
73
|
+
const parsedValue = parseInt(value, 10)
|
|
74
|
+
if (isNaN(parsedValue) || parsedValue < 1) {
|
|
75
|
+
throw new InvalidArgumentError('Not an positive integer.')
|
|
76
|
+
}
|
|
77
|
+
return parsedValue
|
|
78
|
+
}
|
|
79
|
+
|
|
63
80
|
async function cli () {
|
|
64
81
|
const commander = new Command()
|
|
65
82
|
commander
|
|
66
83
|
.version(pkg.version)
|
|
67
|
-
.
|
|
68
|
-
.
|
|
69
|
-
.
|
|
84
|
+
.addOption(new Option('-t, --theme [theme]', 'Theme of the chart').choices(['default', 'forest', 'dark', 'neutral']).default('default'))
|
|
85
|
+
.addOption(new Option('-w, --width [width]', 'Width of the page').argParser(parseCommanderInt).default(800))
|
|
86
|
+
.addOption(new Option('-H, --height [height]', 'Height of the page').argParser(parseCommanderInt).default(600))
|
|
70
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. Required.')
|
|
71
88
|
.option('-o, --output [output]', 'Output file. It should be either md, svg, png or pdf. Optional. Default: input + ".svg"')
|
|
72
|
-
.
|
|
73
|
-
.
|
|
74
|
-
.option('-c, --configFile [configFile]', 'JSON configuration file for mermaid.
|
|
75
|
-
.option('-C, --cssFile [cssFile]', 'CSS file for the page.
|
|
76
|
-
.
|
|
89
|
+
.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
|
+
.addOption(new Option('-b, --backgroundColor [backgroundColor]', 'Background color for pngs/svgs (not pdfs). Example: transparent, red, \'#F0F0F0\'.').default('white'))
|
|
91
|
+
.option('-c, --configFile [configFile]', 'JSON configuration file for mermaid.')
|
|
92
|
+
.option('-C, --cssFile [cssFile]', 'CSS file for the page.')
|
|
93
|
+
.addOption(new Option('-s, --scale [scale]', 'Puppeteer scale factor').argParser(parseCommanderInt).default(1))
|
|
77
94
|
.option('-f, --pdfFit [pdfFit]', 'Scale PDF to fit chart')
|
|
78
95
|
.option('-q, --quiet', 'Suppress log output')
|
|
79
|
-
.option('-p --puppeteerConfigFile [puppeteerConfigFile]', 'JSON configuration file for puppeteer.
|
|
96
|
+
.option('-p --puppeteerConfigFile [puppeteerConfigFile]', 'JSON configuration file for puppeteer.')
|
|
80
97
|
.parse(process.argv)
|
|
81
98
|
|
|
82
99
|
const options = commander.opts()
|
|
@@ -133,19 +150,13 @@ async function cli () {
|
|
|
133
150
|
myCSS = fs.readFileSync(cssFile, 'utf-8')
|
|
134
151
|
}
|
|
135
152
|
|
|
136
|
-
// normalize args
|
|
137
|
-
width = parseInt(width)
|
|
138
|
-
height = parseInt(height)
|
|
139
|
-
backgroundColor = backgroundColor || 'white'
|
|
140
|
-
const deviceScaleFactor = parseInt(scale || 1, 10)
|
|
141
|
-
|
|
142
153
|
await run(
|
|
143
154
|
input, output, {
|
|
144
155
|
puppeteerConfig,
|
|
145
156
|
quiet,
|
|
146
157
|
outputFormat,
|
|
147
158
|
parseMMDOptions: {
|
|
148
|
-
mermaidConfig, backgroundColor, myCSS, pdfFit, viewport: { width, height, deviceScaleFactor }
|
|
159
|
+
mermaidConfig, backgroundColor, myCSS, pdfFit, viewport: { width, height, deviceScaleFactor: scale }
|
|
149
160
|
}
|
|
150
161
|
}
|
|
151
162
|
)
|
|
@@ -353,7 +364,8 @@ async function run (input, output, { puppeteerConfig = {}, quiet = false, output
|
|
|
353
364
|
}
|
|
354
365
|
}
|
|
355
366
|
|
|
356
|
-
|
|
367
|
+
// TODO: should we use a Markdown parser like remark instead of rolling our own parser?
|
|
368
|
+
const mermaidChartsInMarkdown = /^[^\S\n]*```(?:mermaid)(\r?\n([\s\S]*?))```[^\S\n]*$/
|
|
357
369
|
const mermaidChartsInMarkdownRegexGlobal = new RegExp(mermaidChartsInMarkdown, 'gm')
|
|
358
370
|
const browser = await puppeteer.launch(puppeteerConfig)
|
|
359
371
|
try {
|