@mermaid-js/mermaid-cli 10.1.0 → 10.2.4
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/dist/index.html +591 -684
- package/dist-types/src/index.d.ts +1 -1
- package/dist-types/src/index.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/index.js +33 -64
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA6Vc,MAAM;;;;SACN,MAAM;;;;;;AAqBpB;;;;;;;;;;;;;;GAcG;AACH,2BAZW,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;;;;;8BAwGlE;AArQD;;;;;;;;;GASG;AACH,uCAPW,OAAO,WAAW,EAAE,OAAO,cAC3B,MAAM,gBACN,KAAK,GAAG,KAAK,GAAG,KAAK,8FAEnB,QAAQ;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,CAoH9E;AArJD;;;;;;;GAOG;AAEH;;;;;;;;;;;GAWG;AACH,kCAPW,OAAO,WAAW,EAAE,OAAO,cAC3B,MAAM,gBACN,KAAK,GAAG,KAAK,GAAG,KAAK,sCAGnB,QAAQ,MAAM,CAAC,CAK3B;AAzHD,qCA+FC;AAnLD;;;;;GAKG;AACH,+BAHW,MAAM,GACJ,KAAK,CAKjB;sBAnBqB,WAAW"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mermaid-js/mermaid-cli",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.2.4",
|
|
4
4
|
"description": "Command-line interface for mermaid",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "git@github.com:mermaid-js/mermaid-cli.git",
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@fortawesome/fontawesome-free": "^5.6.0",
|
|
31
|
-
"@
|
|
32
|
-
"@tsconfig/node14": "^1.0.3",
|
|
31
|
+
"@tsconfig/node14": "^14.1.0",
|
|
33
32
|
"jest": "^29.0.1",
|
|
34
33
|
"mermaid": "^10.0.0",
|
|
35
34
|
"standard": "^17.0.0",
|
package/src/index.js
CHANGED
|
@@ -52,36 +52,32 @@ const checkConfigFile = file => {
|
|
|
52
52
|
* If `undefined`, reads from `stdin` instead.
|
|
53
53
|
* @returns {Promise<string>} The contents of `inputFile` parsed as `utf8`.
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
async function getInputData (inputFile) {
|
|
56
56
|
// if an input file has been specified using '-i', it takes precedence over
|
|
57
57
|
// piping from stdin
|
|
58
58
|
if (typeof inputFile !== 'undefined') {
|
|
59
|
-
return fs.readFile(inputFile, 'utf-8'
|
|
60
|
-
if (err) {
|
|
61
|
-
return reject(err)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return resolve(data)
|
|
65
|
-
})
|
|
59
|
+
return await fs.promises.readFile(inputFile, 'utf-8')
|
|
66
60
|
}
|
|
67
61
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
return await new Promise((resolve, reject) => {
|
|
63
|
+
let data = ''
|
|
64
|
+
process.stdin.on('readable', function () {
|
|
65
|
+
const chunk = process.stdin.read()
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
if (chunk !== null) {
|
|
68
|
+
data += chunk
|
|
69
|
+
}
|
|
70
|
+
})
|
|
76
71
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
process.stdin.on('error', function (err) {
|
|
73
|
+
reject(err)
|
|
74
|
+
})
|
|
80
75
|
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
process.stdin.on('end', function () {
|
|
77
|
+
resolve(data)
|
|
78
|
+
})
|
|
83
79
|
})
|
|
84
|
-
}
|
|
80
|
+
}
|
|
85
81
|
|
|
86
82
|
/**
|
|
87
83
|
* Commander parser that converts a string to an integer.
|
|
@@ -161,10 +157,19 @@ async function cli () {
|
|
|
161
157
|
checkConfigFile(configFile)
|
|
162
158
|
mermaidConfig = Object.assign(mermaidConfig, JSON.parse(fs.readFileSync(configFile, 'utf-8')))
|
|
163
159
|
}
|
|
164
|
-
|
|
160
|
+
// @ts-expect-error Setting headless to `1` is not officially supported
|
|
161
|
+
let puppeteerConfig = /** @type {import('puppeteer').PuppeteerLaunchOptions} */ ({
|
|
162
|
+
/*
|
|
163
|
+
* `headless: 1` is not officially supported, but setting this to any
|
|
164
|
+
* non-`true` truthy value doesn't change any behavior, but it hides the
|
|
165
|
+
* Puppeteer old Headless deprecation warning,
|
|
166
|
+
* see https://github.com/argos-ci/jest-puppeteer/issues/553#issuecomment-1561826456
|
|
167
|
+
*/
|
|
168
|
+
headless: 1
|
|
169
|
+
})
|
|
165
170
|
if (puppeteerConfigFile) {
|
|
166
171
|
checkConfigFile(puppeteerConfigFile)
|
|
167
|
-
puppeteerConfig = JSON.parse(fs.readFileSync(puppeteerConfigFile, 'utf-8'))
|
|
172
|
+
puppeteerConfig = Object.assign(puppeteerConfig, JSON.parse(fs.readFileSync(puppeteerConfigFile, 'utf-8')))
|
|
168
173
|
}
|
|
169
174
|
|
|
170
175
|
// check cssFile
|
|
@@ -239,54 +244,18 @@ async function renderMermaid (browser, definition, outputFormat, { viewport, bac
|
|
|
239
244
|
body.style.background = backgroundColor
|
|
240
245
|
}, backgroundColor)
|
|
241
246
|
const metadata = await page.$eval('#container', async (container, definition, mermaidConfig, myCSS, backgroundColor) => {
|
|
242
|
-
/**
|
|
243
|
-
* Checks to see if the given object is one of Mermaid's DetailedErrors.
|
|
244
|
-
*
|
|
245
|
-
* @param {unknown} error - The error to check
|
|
246
|
-
* @returns {error is import("mermaid").DetailedError} Returns `true` is the `error`
|
|
247
|
-
* is a `Mermaid.DetailedError`.
|
|
248
|
-
* @see https://github.com/mermaid-js/mermaid/blob/v10.0.1/packages/mermaid/src/utils.ts#L927-L930
|
|
249
|
-
*/
|
|
250
|
-
function isDetailedError (error) {
|
|
251
|
-
return typeof error === 'object' && error !== null && 'str' in error
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
container.textContent = definition
|
|
255
|
-
|
|
256
247
|
/**
|
|
257
248
|
* @typedef {Object} GlobalThisWithMermaid
|
|
258
249
|
* We've already imported these modules in our `index.html` file, so that they
|
|
259
250
|
* get correctly bundled.
|
|
260
251
|
* @property {import("mermaid")["default"]} mermaid Already imported mermaid instance
|
|
261
|
-
* @property {import("@mermaid-js/mermaid-mindmap")} mermaidMindmap Already imported mermaid-mindmap plugin
|
|
262
252
|
*/
|
|
263
|
-
const { mermaid
|
|
253
|
+
const { mermaid } = /** @type {GlobalThisWithMermaid & typeof globalThis} */ (globalThis)
|
|
264
254
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
mermaid.initialize(mermaidConfig)
|
|
255
|
+
mermaid.initialize({ startOnLoad: false, ...mermaidConfig })
|
|
268
256
|
// should throw an error if mmd diagram is invalid
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
nodes: [
|
|
272
|
-
/**
|
|
273
|
-
* @type {HTMLElement} We know this is a `HTMLElement`, since we
|
|
274
|
-
* control the input HTML file
|
|
275
|
-
*/ (container)
|
|
276
|
-
],
|
|
277
|
-
suppressErrors: false
|
|
278
|
-
})
|
|
279
|
-
} catch (error) {
|
|
280
|
-
if (error instanceof Error) {
|
|
281
|
-
// mermaid-js doesn't currently throws JS Errors, but let's leave this
|
|
282
|
-
// here in case it does in the future
|
|
283
|
-
throw error
|
|
284
|
-
} else if (isDetailedError(error)) {
|
|
285
|
-
throw new Error(error.message)
|
|
286
|
-
} else {
|
|
287
|
-
throw new Error(`Unknown mermaid render error: ${error}`)
|
|
288
|
-
}
|
|
289
|
-
}
|
|
257
|
+
const { svg: svgText } = await mermaid.render('my-svg', definition, container)
|
|
258
|
+
container.innerHTML = svgText
|
|
290
259
|
|
|
291
260
|
const svg = container.getElementsByTagName?.('svg')?.[0]
|
|
292
261
|
if (svg?.style) {
|
|
@@ -452,7 +421,7 @@ async function run (input, output, { puppeteerConfig = {}, quiet = false, output
|
|
|
452
421
|
if (input && /\.(md|markdown)$/.test(input)) {
|
|
453
422
|
const imagePromises = []
|
|
454
423
|
for (const mermaidCodeblockMatch of definition.matchAll(mermaidChartsInMarkdownRegexGlobal)) {
|
|
455
|
-
const mermaidDefinition = mermaidCodeblockMatch[
|
|
424
|
+
const mermaidDefinition = mermaidCodeblockMatch[2]
|
|
456
425
|
|
|
457
426
|
/** Output can be either a template image file, or a `.md` output file.
|
|
458
427
|
* If it is a template image file, use that to created numbered diagrams
|