@mermaid-js/mermaid-cli 10.0.2 → 10.2.2

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.
@@ -13,7 +13,7 @@ export type ParseMDDOptions = {
13
13
  /**
14
14
  * - Mermaid config.
15
15
  */
16
- mermaidConfig?: any;
16
+ mermaidConfig?: import("mermaid").MermaidConfig | undefined;
17
17
  /**
18
18
  * - Optional CSS text.
19
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA4Xc,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;AAzSD;;;;;;;;;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,CAwJ9E;AAzLD;;;;;;;GAOG;AAEH;;;;;;;;;;;GAWG;AACH,kCAPW,OAAO,WAAW,EAAE,OAAO,cAC3B,MAAM,gBACN,KAAK,GAAG,KAAK,GAAG,KAAK,sCAGnB,QAAQ,MAAM,CAAC,CAK3B;AAhHD,qCAsFC;AA9KD;;;;;GAKG;AACH,+BAHW,MAAM,GACJ,KAAK,CAKjB;sBAnBqB,WAAW"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAoVc,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;AAhHD,qCAsFC;AA1KD;;;;;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.0.2",
3
+ "version": "10.2.2",
4
4
  "description": "Command-line interface for mermaid",
5
5
  "license": "MIT",
6
6
  "repository": "git@github.com:mermaid-js/mermaid-cli.git",
@@ -27,8 +27,7 @@
27
27
  "puppeteer": "^19.0.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@fortawesome/fontawesome-free-webfonts": "^1.0.9",
31
- "@mermaid-js/mermaid-mindmap": "^9.2.2",
30
+ "@fortawesome/fontawesome-free": "^5.6.0",
32
31
  "@tsconfig/node14": "^1.0.3",
33
32
  "jest": "^29.0.1",
34
33
  "mermaid": "^10.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
- const getInputData = async inputFile => new Promise((resolve, reject) => {
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', (err, data) => {
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
- let data = ''
69
- process.stdin.on('readable', function () {
70
- const chunk = process.stdin.read()
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
- if (chunk !== null) {
73
- data += chunk
74
- }
75
- })
67
+ if (chunk !== null) {
68
+ data += chunk
69
+ }
70
+ })
76
71
 
77
- process.stdin.on('error', function (err) {
78
- reject(err)
79
- })
72
+ process.stdin.on('error', function (err) {
73
+ reject(err)
74
+ })
80
75
 
81
- process.stdin.on('end', function () {
82
- resolve(data)
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.
@@ -114,7 +110,7 @@ async function cli () {
114
110
  .option('-c, --configFile [configFile]', 'JSON configuration file for mermaid.')
115
111
  .option('-C, --cssFile [cssFile]', 'CSS file for the page.')
116
112
  .addOption(new Option('-s, --scale [scale]', 'Puppeteer scale factor').argParser(parseCommanderInt).default(1))
117
- .option('-f, --pdfFit [pdfFit]', 'Scale PDF to fit chart')
113
+ .option('-f, --pdfFit', 'Scale PDF to fit chart')
118
114
  .option('-q, --quiet', 'Suppress log output')
119
115
  .option('-p --puppeteerConfigFile [puppeteerConfigFile]', 'JSON configuration file for puppeteer.')
120
116
  .parse(process.argv)
@@ -125,7 +121,7 @@ async function cli () {
125
121
 
126
122
  // check input file
127
123
  if (!input) {
128
- warn('No input file specfied, reading from stdin. ' +
124
+ warn('No input file specified, reading from stdin. ' +
129
125
  'If you want to specify an input file, please use `-i <input>.` ' +
130
126
  'You can use `-i -` to read from stdin and to suppress this warning.'
131
127
  )
@@ -239,54 +235,18 @@ async function renderMermaid (browser, definition, outputFormat, { viewport, bac
239
235
  body.style.background = backgroundColor
240
236
  }, backgroundColor)
241
237
  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
238
  /**
257
239
  * @typedef {Object} GlobalThisWithMermaid
258
240
  * We've already imported these modules in our `index.html` file, so that they
259
241
  * get correctly bundled.
260
242
  * @property {import("mermaid")["default"]} mermaid Already imported mermaid instance
261
- * @property {import("@mermaid-js/mermaid-mindmap")} mermaidMindmap Already imported mermaid-mindmap plugin
262
243
  */
263
- const { mermaid, mermaidMindmap } = /** @type {GlobalThisWithMermaid & typeof globalThis} */ (globalThis)
244
+ const { mermaid } = /** @type {GlobalThisWithMermaid & typeof globalThis} */ (globalThis)
264
245
 
265
- await mermaid.registerExternalDiagrams([mermaidMindmap])
266
-
267
- mermaid.initialize(mermaidConfig)
246
+ mermaid.initialize({ startOnLoad: false, ...mermaidConfig })
268
247
  // should throw an error if mmd diagram is invalid
269
- try {
270
- await mermaid.run({
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
- }
248
+ const { svg: svgText } = await mermaid.render('my-svg', definition, container)
249
+ container.innerHTML = svgText
290
250
 
291
251
  const svg = container.getElementsByTagName?.('svg')?.[0]
292
252
  if (svg?.style) {
@@ -452,7 +412,7 @@ async function run (input, output, { puppeteerConfig = {}, quiet = false, output
452
412
  if (input && /\.(md|markdown)$/.test(input)) {
453
413
  const imagePromises = []
454
414
  for (const mermaidCodeblockMatch of definition.matchAll(mermaidChartsInMarkdownRegexGlobal)) {
455
- const mermaidDefinition = mermaidCodeblockMatch[1]
415
+ const mermaidDefinition = mermaidCodeblockMatch[2]
456
416
 
457
417
  /** Output can be either a template image file, or a `.md` output file.
458
418
  * If it is a template image file, use that to created numbered diagrams