@forsakringskassan/docs-generator 2.5.0 → 2.7.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 CHANGED
@@ -206,6 +206,10 @@ The following statuses are recognized:
206
206
 
207
207
  Document title used for `<title>` and `<nav>`
208
208
 
209
+ #### `short-title`
210
+
211
+ Document title used when a shorter title is needed, e.g. site navigation.
212
+
209
213
  #### `visible`
210
214
 
211
215
  Set to `false` to hide document from navigation menu.
@@ -218,20 +222,34 @@ Default `true`.
218
222
 
219
223
  ### Inline tags
220
224
 
221
- #### `{@link ...}`
225
+ #### `{@@link ...}`
222
226
 
223
227
  Implicit title:
224
228
 
225
229
  ```md
226
- Use the {@link MyAwesomeComponent} component.
230
+ Use the {@@link MyAwesomeComponent} component.
227
231
  ```
228
232
 
229
233
  Explicit title:
230
234
 
231
235
  ```md
232
- Use the {@link MyAwesomeComponent awesome component}.
236
+ Use the {@@link MyAwesomeComponent awesome component}.
237
+ ```
238
+
239
+ #### `{@@optional}`
240
+
241
+ Creates a tag (badge) to mark something as optional.
242
+
243
+ **Input:**
244
+
245
+ ```md
246
+ {@@optional}
233
247
  ```
234
248
 
249
+ **Output:**
250
+
251
+ {@optional}
252
+
235
253
  ### Templating
236
254
 
237
255
  The [Nunjucks](https://mozilla.github.io/nunjucks/) templating engine is used for rendering documents to HTML.
@@ -3,10 +3,10 @@
3
3
  var path$1 = require('node:path');
4
4
  var esbuild = require('esbuild');
5
5
  var vue = require('vue');
6
- var vue3 = require('./vue3-Cv0MDe04.js');
6
+ var vue3 = require('./vue3-D4vqQB-D.js');
7
7
  var path = require('node:path/posix');
8
8
  require('@vue/compiler-sfc');
9
- require('./vendor-BFdBzDIw.js');
9
+ require('./vendor-B3CU63aM.js');
10
10
  require('typescript');
11
11
  require('node:url');
12
12
  require('fs');
@@ -22,16 +22,11 @@ require('assert');
22
22
  require('path');
23
23
  require('readline');
24
24
  require('events');
25
- require('child_process');
26
- require('node:stream/promises');
27
- require('node:child_process');
28
- require('node:util');
29
25
  require('node:process');
30
- require('node:tty');
31
- require('node:timers/promises');
32
- require('node:os');
33
- require('node:v8');
34
- require('node:buffer');
26
+ require('node:util');
27
+ require('node:child_process');
28
+ require('node:stream/promises');
29
+ require('fs/promises');
35
30
  require('os');
36
31
  require('http');
37
32
  require('https');
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var vendor = require('./vendor-BFdBzDIw.js');
3
+ var vendor = require('./vendor-B3CU63aM.js');
4
4
  var path = require('node:path/posix');
5
5
  var path$1 = require('node:path');
6
6
  require('crypto');
@@ -81,7 +81,15 @@ class SoftError extends Error {
81
81
  }
82
82
 
83
83
  function processInlineTags(tags, doc, docs, text, handleSoftError) {
84
- return text.replace(/{@([\S}]+)([^}]*)}/g, (_, name, content) => {
84
+ return text.replace(/{@(@?)([^{}]+)}/g, (_, escape, content) => {
85
+ if (escape) {
86
+ return `{@${content}}`;
87
+ }
88
+ const match = content.match(/^(\S+)($|\s[^]+)$/);
89
+ if (!match) {
90
+ return `{@${content}}`;
91
+ }
92
+ const [, name, text2] = match;
85
93
  const tag = tags.find((it) => it.name === name);
86
94
  if (!tag) {
87
95
  return handleSoftError(
@@ -92,7 +100,7 @@ function processInlineTags(tags, doc, docs, text, handleSoftError) {
92
100
  );
93
101
  }
94
102
  try {
95
- return tag.handler(doc, docs, content.trim());
103
+ return tag.handler(doc, docs, text2.trim());
96
104
  } catch (err) {
97
105
  if (err instanceof SoftError) {
98
106
  return handleSoftError(err);
@@ -164,7 +172,15 @@ const linkTag = {
164
172
  }
165
173
  };
166
174
 
167
- const inlineTags = [linkTag];
175
+ const optionalTag = {
176
+ name: "optional",
177
+ description: "Create a tag for symbolize optional content",
178
+ handler() {
179
+ return `<span class="docs-tag docs-tag--default">Optional</span>`;
180
+ }
181
+ };
182
+
183
+ const inlineTags = [linkTag, optionalTag];
168
184
 
169
185
  function findTestId(tags) {
170
186
  const prefix = "test-id=";
@@ -461,9 +477,100 @@ function imageResources(options) {
461
477
  };
462
478
  }
463
479
 
480
+ function altContainer(context) {
481
+ const { md, env, docs } = context;
482
+ return (tokens, index) => {
483
+ const token = tokens[index];
484
+ const needle = token.info;
485
+ const doc = findDocument(docs, needle);
486
+ if (doc && doc.format === "markdown") {
487
+ return md.render(doc.body, env);
488
+ }
489
+ return md.render(token.content, env);
490
+ };
491
+ }
492
+
493
+ function apiContainer(context) {
494
+ const { md, env, docs, included, handleSoftError } = context;
495
+ return (tokens, index) => {
496
+ const token = tokens[index];
497
+ const needle = token.content.trim();
498
+ const doc = findDocument(docs, needle);
499
+ if (!doc) {
500
+ return handleSoftError(
501
+ new SoftError(
502
+ "EINCLUDETARGET",
503
+ `No document matches "${needle}" when trying to include content`,
504
+ { id: needle }
505
+ )
506
+ );
507
+ }
508
+ if (included.has(doc.id)) {
509
+ return handleSoftError(
510
+ new SoftError(
511
+ "EINCLUDERECURSION",
512
+ `Recursion detected when including document "${doc.id}"`
513
+ )
514
+ );
515
+ }
516
+ included.add(doc.id);
517
+ if (doc.format === "html") {
518
+ return doc.body;
519
+ }
520
+ const content = md.render(doc.body, env);
521
+ return (
522
+ /* HTML */
523
+ ` <div>${content}</div> `
524
+ );
525
+ };
526
+ }
527
+
528
+ const defaultTitle = {
529
+ info: "INFO",
530
+ warning: "WARNING",
531
+ danger: "DANGER"
532
+ };
533
+ function messageboxContainer(context, options, alias) {
534
+ const { md, env } = context;
535
+ function getTitle(variant, customTitle) {
536
+ if (customTitle && customTitle.length > 0) {
537
+ return customTitle.join(" ");
538
+ } else {
539
+ return options.title[variant] ?? defaultTitle[variant] ?? "";
540
+ }
541
+ }
542
+ function parseInfo(info) {
543
+ if (alias) {
544
+ const variant = alias;
545
+ const customTitle = info ? info.split(" ") : [];
546
+ const title = getTitle(variant, customTitle);
547
+ return { variant, title };
548
+ } else {
549
+ const [variant = "info", ...customTitle] = info ? info.split(" ") : [];
550
+ const title = getTitle(variant, customTitle);
551
+ return { variant, title };
552
+ }
553
+ }
554
+ return (tokens, index) => {
555
+ const token = tokens[index];
556
+ const { variant, title } = parseInfo(token.info);
557
+ const text = token.content.trim();
558
+ const content = md.render(text, env);
559
+ return (
560
+ /* HTML */
561
+ `
562
+ <div class="docs-messagebox docs-messagebox--${variant}">
563
+ ${title ? `<p class="docs-messagebox__title">${title}</p>` : ""}
564
+ ${content}
565
+ </div>
566
+ `
567
+ );
568
+ };
569
+ }
570
+
464
571
  const markerStr = ":";
465
572
  const markerChar = markerStr.charCodeAt(0);
466
- function parser(md, options) {
573
+ function containerParser(md, options) {
467
574
  function container(state, startLine, endLine, silent) {
468
575
  let pos = state.bMarks[startLine] + state.tShift[startLine];
469
576
  let max = state.eMarks[startLine];
@@ -484,8 +591,9 @@ function parser(md, options) {
484
591
  return false;
485
592
  }
486
593
  const markup = state.src.slice(mem, pos);
487
- const params = state.src.slice(pos, max).trim();
488
- const kind = params.split(" ", 2)[0];
594
+ const params = state.src.slice(pos, max).trim().split(/\s+/);
595
+ const kind = params[0];
596
+ const info = params.slice(1).join(" ");
489
597
  if (silent) {
490
598
  return true;
491
599
  }
@@ -521,7 +629,7 @@ function parser(md, options) {
521
629
  len = state.sCount[startLine];
522
630
  state.line = nextLine + (haveEndMarker ? 1 : 0);
523
631
  const token = state.push(`doc_${kind}`, "div", 0);
524
- token.info = params;
632
+ token.info = info?.trim();
525
633
  token.content = state.getLines(startLine + 1, nextLine, len, true);
526
634
  token.markup = markup;
527
635
  token.map = [startLine, state.line];
@@ -534,49 +642,28 @@ function parser(md, options) {
534
642
  md.renderer.rules[`doc_${kind}`] = fn;
535
643
  }
536
644
  }
537
- function include(docs, env, included, handleSoftError) {
645
+ function containerRenderer(docs, env, included, handleSoftError, options) {
538
646
  return function(md) {
539
- md.use(parser, {
540
- api(tokens, index) {
541
- const token = tokens[index];
542
- const needle = token.content.trim();
543
- const doc = findDocument(docs, needle);
544
- if (!doc) {
545
- return handleSoftError(
546
- new SoftError(
547
- "EINCLUDETARGET",
548
- `No document matches "${needle}" when trying to include content`,
549
- { id: needle }
550
- )
551
- );
552
- }
553
- if (included.has(doc.id)) {
554
- return handleSoftError(
555
- new SoftError(
556
- "EINCLUDERECURSION",
557
- `Recursion detected when including document "${doc.id}"`
558
- )
559
- );
560
- }
561
- included.add(doc.id);
562
- if (doc.format === "html") {
563
- return doc.body;
564
- }
565
- const content = md.render(doc.body, env);
566
- return (
567
- /* HTML */
568
- ` <div>${content}</div> `
569
- );
570
- },
571
- alt(tokens, index) {
572
- const token = tokens[index];
573
- const needle = token.info.split(" ")[1];
574
- const doc = findDocument(docs, needle);
575
- if (doc && doc.format === "markdown") {
576
- return md.render(doc.body, env);
577
- }
578
- return md.render(token.content, env);
579
- }
647
+ const context = {
648
+ md,
649
+ env,
650
+ docs,
651
+ included,
652
+ handleSoftError
653
+ };
654
+ md.use(containerParser, {
655
+ alt: altContainer(context),
656
+ api: apiContainer(context),
657
+ messagebox: messageboxContainer(context, options.messagebox),
658
+ /* aliases for messagebox containers */
659
+ info: messageboxContainer(context, options.messagebox, "info"),
660
+ tip: messageboxContainer(context, options.messagebox, "tip"),
661
+ warning: messageboxContainer(
662
+ context,
663
+ options.messagebox,
664
+ "warning"
665
+ ),
666
+ danger: messageboxContainer(context, options.messagebox, "danger")
580
667
  });
581
668
  };
582
669
  }
@@ -617,6 +704,7 @@ function createMarkdownRenderer(options) {
617
704
  const md = vendor.MarkdownIt({
618
705
  html: true
619
706
  });
707
+ md.use(vendor.deflist_plugin);
620
708
  md.use(
621
709
  codePreview({
622
710
  generateExample: options.generateExample
@@ -628,7 +716,11 @@ function createMarkdownRenderer(options) {
628
716
  addResource: options.addResource
629
717
  })
630
718
  );
631
- md.use(include(docs, env, included, options.handleSoftError));
719
+ md.use(
720
+ containerRenderer(docs, env, included, options.handleSoftError, {
721
+ messagebox: { title: {}, ...options.messagebox }
722
+ })
723
+ );
632
724
  md.use(table());
633
725
  md.use(codeInline());
634
726
  return {
package/dist/index.d.ts CHANGED
@@ -213,6 +213,35 @@ export declare interface GeneratorOptions {
213
213
  * `function setup(options: { rootComponent: string, selector: string }): void`
214
214
  */
215
215
  setupPath: string;
216
+ /**
217
+ * Options for markdown renderer.
218
+ */
219
+ markdown: {
220
+ /**
221
+ * Options for markdown messagebox container.
222
+ */
223
+ messagebox: {
224
+ /**
225
+ * Default titles for messageboxes.
226
+ *
227
+ * If a title is the empty string `""` the usage of title is
228
+ * disabled by default.
229
+ *
230
+ * @example
231
+ * ```json
232
+ * {
233
+ * "title": {
234
+ * "info": "Information",
235
+ * "tip": "Tips",
236
+ * "warning": "Varning",
237
+ * "danger": "Se upp!"
238
+ * }
239
+ * }
240
+ * ```
241
+ */
242
+ title?: Record<string, string>;
243
+ };
244
+ };
216
245
  }
217
246
 
218
247
  /**
@@ -349,6 +378,7 @@ export declare interface NavigationSection {
349
378
  */
350
379
  export declare interface NormalizedDocumentAttributes {
351
380
  title?: string;
381
+ shortTitle?: string;
352
382
  layout?: string;
353
383
  status?: string;
354
384
  badge?: DocumentBadge;
package/dist/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  var fs = require('node:fs/promises');
4
- var vendor = require('./vendor-BFdBzDIw.js');
4
+ var vendor = require('./vendor-B3CU63aM.js');
5
5
  var path = require('node:path');
6
6
  var require$$1 = require('crypto');
7
- var createMarkdownRenderer = require('./create-markdown-renderer-iznOQQKw.js');
7
+ var createMarkdownRenderer = require('./create-markdown-renderer-MuI6-bYd.js');
8
8
  var node_child_process = require('node:child_process');
9
9
  var path$1 = require('node:path/posix');
10
10
  require('node:crypto');
11
11
  var util = require('node:util');
12
12
  var fs$1 = require('node:fs');
13
13
  var vue = require('vue');
14
- var vue3 = require('./vue3-Cv0MDe04.js');
14
+ var vue3 = require('./vue3-D4vqQB-D.js');
15
15
  var vueDocgenApi = require('vue-docgen-api');
16
16
  var sass = require('sass');
17
17
  var node_url = require('node:url');
@@ -31,14 +31,9 @@ require('assert');
31
31
  require('path');
32
32
  require('readline');
33
33
  require('events');
34
- require('child_process');
35
- require('node:stream/promises');
36
34
  require('node:process');
37
- require('node:tty');
38
- require('node:timers/promises');
39
- require('node:os');
40
- require('node:v8');
41
- require('node:buffer');
35
+ require('node:stream/promises');
36
+ require('fs/promises');
42
37
  require('os');
43
38
  require('http');
44
39
  require('https');
@@ -451,13 +446,16 @@ function topnavProcessor(filename, title) {
451
446
  }
452
447
 
453
448
  async function getGitBranch() {
454
- const { CHANGE_BRANCH, CHANGE_NAME } = process.env;
449
+ const { CHANGE_BRANCH, CHANGE_NAME, GITHUB_HEAD_REF } = process.env;
455
450
  if (CHANGE_BRANCH) {
456
451
  return CHANGE_BRANCH;
457
452
  }
458
453
  if (CHANGE_NAME) {
459
454
  return CHANGE_NAME;
460
455
  }
456
+ if (GITHUB_HEAD_REF) {
457
+ return GITHUB_HEAD_REF;
458
+ }
461
459
  const branch = await runCommand(
462
460
  "git rev-parse --abbrev-ref HEAD",
463
461
  "unknown"
@@ -769,6 +767,7 @@ function parseFile$1(filePath, basePath, content) {
769
767
  visible: attributes.visible ?? true,
770
768
  attributes: {
771
769
  title: attributes.title ?? name,
770
+ shortTitle: attributes["short-title"],
772
771
  layout: attributes.layout,
773
772
  status: attributes.status,
774
773
  badge: getBadge(attributes),
@@ -1043,47 +1042,33 @@ async function navigationFileReader(filePath, basePath) {
1043
1042
  return [doc];
1044
1043
  }
1045
1044
 
1046
- function resolveScssImport(filePath, throwError = true) {
1047
- const { dir, base } = path$1.parse(filePath);
1048
- const search = [`${base}.css`, `${base}.scss`, `_${base}.scss`, `${base}`];
1049
- for (const variant of search) {
1050
- try {
1051
- const moduleName = path$1.join(dir, variant);
1052
- const resolved = require.resolve(moduleName);
1053
- return node_url.pathToFileURL(resolved);
1054
- } catch (err) {
1055
- if (err.code !== "MODULE_NOT_FOUND") {
1056
- throw err;
1057
- }
1058
- }
1059
- }
1060
- if (throwError) {
1061
- throw new Error(`Failed to resolve "${filePath}"`);
1062
- }
1063
- return null;
1064
- }
1065
1045
  const WEBPACK_NODE_MODULE_PREFIX = "~";
1066
1046
  const moduleImporter = {
1067
- canonicalize(url) {
1068
- const indexOfPrefix = url.indexOf(WEBPACK_NODE_MODULE_PREFIX);
1069
- if (indexOfPrefix >= 0) {
1070
- return resolveScssImport(url.slice(indexOfPrefix + 1));
1071
- }
1072
- if (url.startsWith("file://")) {
1073
- const path$1 = node_url.fileURLToPath(url);
1074
- const relative = path.isAbsolute(path$1) ? path.relative(__dirname, path$1) : path$1;
1075
- return resolveScssImport(relative.replace(/\\/g, "/"));
1076
- }
1077
- return resolveScssImport(url, false);
1078
- },
1079
- async load(url) {
1080
- const filepath = node_url.fileURLToPath(url);
1081
- const parsed = path.parse(filepath);
1082
- const contents = await fs.readFile(filepath, "utf-8");
1083
- return {
1084
- contents,
1085
- syntax: parsed.ext.slice(1) === "scss" ? "scss" : "css"
1086
- };
1047
+ findFileUrl(url) {
1048
+ let findUrl = url;
1049
+ if (url.startsWith(WEBPACK_NODE_MODULE_PREFIX)) {
1050
+ findUrl = url.substring(1);
1051
+ }
1052
+ const directory = path.dirname(findUrl);
1053
+ const fileName = path.basename(findUrl);
1054
+ const search = [
1055
+ `${fileName}.css`,
1056
+ `${fileName}.scss`,
1057
+ `_${fileName}.scss`,
1058
+ `${fileName}`
1059
+ ];
1060
+ for (const variant of search) {
1061
+ try {
1062
+ const moduleName = path.posix.join(directory, variant);
1063
+ const resolved = require.resolve(moduleName);
1064
+ return new URL(node_url.pathToFileURL(resolved));
1065
+ } catch (err) {
1066
+ if (err.code !== "MODULE_NOT_FOUND") {
1067
+ throw err;
1068
+ }
1069
+ }
1070
+ }
1071
+ return null;
1087
1072
  }
1088
1073
  };
1089
1074
 
@@ -1385,7 +1370,7 @@ function generateNavtree(docs) {
1385
1370
  }
1386
1371
  for (const doc of docs) {
1387
1372
  const [name, isSection] = pathFromDoc(doc);
1388
- const title = doc.attributes.title ?? doc.fileInfo.name;
1373
+ const title = doc.attributes.shortTitle ?? doc.attributes.title ?? doc.fileInfo.name;
1389
1374
  const sortorder = doc.attributes.sortorder;
1390
1375
  if (doc.attributes.href) {
1391
1376
  const parent2 = attach(name);
@@ -1707,13 +1692,11 @@ async function compileExamples(options) {
1707
1692
  external: vendors.map((it) => it.package),
1708
1693
  tasks: dirtyTasks
1709
1694
  };
1710
- const result = await vendor.execa("node", [scriptPath], {
1711
- input: JSON.stringify(batch),
1712
- all: true
1695
+ const result = await vendor.spawn("node", [scriptPath], {
1696
+ stdin: { string: JSON.stringify(batch) }
1713
1697
  });
1714
- const hasOutput = result.all ? result.all.length > 0 : false;
1715
- if (hasOutput) {
1716
- console.log(result.all);
1698
+ if (result.output.length > 0) {
1699
+ console.log(result.output);
1717
1700
  }
1718
1701
  }
1719
1702
  async function compileStandalones(options) {
@@ -1803,7 +1786,8 @@ async function render(doc, docs, nav, vendors, options) {
1803
1786
  },
1804
1787
  handleSoftError(error) {
1805
1788
  throw error;
1806
- }
1789
+ },
1790
+ messagebox: options.markdown.messagebox
1807
1791
  });
1808
1792
  njk.addFilter("marked", (content2) => {
1809
1793
  return markdownRenderer.render(doc, content2);
@@ -2139,7 +2123,7 @@ async function serve(options) {
2139
2123
  printMenu(server.address());
2140
2124
  const livereload = vendor.tinylr();
2141
2125
  livereload.listen(35729);
2142
- const watcher = vendor.chokidar.watch(options.watch);
2126
+ const watcher = vendor.watch(options.watch);
2143
2127
  const rebuild = createRebuilder(options.rebuild, (filePath) => {
2144
2128
  const files = filePath.map((it) => {
2145
2129
  return path$1.relative(options.outputFolder, it);
@@ -2423,7 +2407,8 @@ class Generator {
2423
2407
  cacheFolder,
2424
2408
  exampleFolders,
2425
2409
  templateFolders,
2426
- setupPath
2410
+ setupPath,
2411
+ markdown: {}
2427
2412
  }),
2428
2413
  ...this.processors
2429
2414
  ];
@@ -183,6 +183,13 @@ export declare interface MarkdownOptions {
183
183
  * @returns A replacement string or rethrows error.
184
184
  */
185
185
  handleSoftError(error: SoftErrorType): string;
186
+ /**
187
+ * Options for messagebox container.
188
+ */
189
+ messagebox?: {
190
+ /** Default titles for messageboxes */
191
+ title?: Record<string, string>;
192
+ };
186
193
  }
187
194
 
188
195
  /**
@@ -206,6 +213,7 @@ export declare interface MarkdownRenderer {
206
213
  */
207
214
  export declare interface NormalizedDocumentAttributes {
208
215
  title?: string;
216
+ shortTitle?: string;
209
217
  layout?: string;
210
218
  status?: string;
211
219
  badge?: DocumentBadge;
package/dist/markdown.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var createMarkdownRenderer = require('./create-markdown-renderer-iznOQQKw.js');
4
- require('./vendor-BFdBzDIw.js');
3
+ var createMarkdownRenderer = require('./create-markdown-renderer-MuI6-bYd.js');
4
+ require('./vendor-B3CU63aM.js');
5
5
  require('@vue/compiler-sfc');
6
6
  require('typescript');
7
7
  require('node:url');
@@ -19,16 +19,11 @@ require('assert');
19
19
  require('path');
20
20
  require('readline');
21
21
  require('events');
22
- require('child_process');
23
- require('node:stream/promises');
24
- require('node:child_process');
25
- require('node:util');
26
22
  require('node:process');
27
- require('node:tty');
28
- require('node:timers/promises');
29
- require('node:os');
30
- require('node:v8');
31
- require('node:buffer');
23
+ require('node:util');
24
+ require('node:child_process');
25
+ require('node:stream/promises');
26
+ require('fs/promises');
32
27
  require('os');
33
28
  require('http');
34
29
  require('https');