@forsakringskassan/docs-generator 2.18.0 → 2.19.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/dist/index.js CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  var fs = require('node:fs/promises');
4
4
  var path = require('node:path/posix');
5
- var vendor = require('./vendor-Bagon7WF.js');
5
+ var vendor = require('./vendor-BHA4LIog.js');
6
+ var createMarkdownRenderer = require('./create-markdown-renderer-CbE5KJoX.js');
6
7
  var path$1 = require('node:path');
7
8
  var require$$1 = require('crypto');
8
9
  require('node:crypto');
9
- var createMarkdownRenderer = require('./create-markdown-renderer-CaJTFjAd.js');
10
10
  var node_child_process = require('node:child_process');
11
11
  var util = require('node:util');
12
12
  var codeFrame = require('@babel/code-frame');
@@ -44,7 +44,7 @@ require('tls');
44
44
  require('tty');
45
45
  require('querystring');
46
46
  require('vue');
47
- require('./vue3-CEAR7ggN.js');
47
+ require('./vue3-BhdC7RZQ.js');
48
48
 
49
49
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
50
50
  function toArray$2(value) {
@@ -70,6 +70,21 @@ function matomoProcessor(options) {
70
70
  };
71
71
  }
72
72
 
73
+ const documentAttributeKeys = [
74
+ "title",
75
+ "short-title",
76
+ "layout",
77
+ "name",
78
+ "alias",
79
+ "status",
80
+ "visible",
81
+ "include",
82
+ "component",
83
+ "href",
84
+ "sortorder",
85
+ "redirect_from"
86
+ ];
87
+
73
88
  function cacheKey$1(...args) {
74
89
  return JSON.stringify(args);
75
90
  }
@@ -167,14 +182,14 @@ function getPullRequestID(env) {
167
182
  if (env.JOB_BASE_NAME) {
168
183
  const name = env.JOB_BASE_NAME;
169
184
  const match = name.match(/^PR-(\d+)$/);
170
- return match ? match[1] : undefined;
185
+ return match ? match[1] : void 0;
171
186
  }
172
187
  if (env.GITHUB_REF) {
173
188
  const name = env.GITHUB_REF;
174
189
  const match = name.match(/^refs\/pull\/([^/]+)\/merge$/);
175
- return match ? match[1] : undefined;
190
+ return match ? match[1] : void 0;
176
191
  }
177
- return undefined;
192
+ return void 0;
178
193
  }
179
194
 
180
195
  const RE_MATCH_SSH = /^(ssh:\/\/)?(?<user>[^@]+)@(?<host>[^:]+):(?<path>.*)$/;
@@ -274,7 +289,7 @@ md$4.renderer.rules.fence = (tokens, idx, _options, collected) => {
274
289
  return "";
275
290
  }
276
291
  const nameTag = tags.find((it) => it.startsWith("name="));
277
- const name = nameTag ? slugify(nameTag.slice("name=".length)) : undefined;
292
+ const name = nameTag ? slugify(nameTag.slice("name=".length)) : void 0;
278
293
  collected.push({
279
294
  name,
280
295
  content,
@@ -331,8 +346,9 @@ function extractExamplesProcessor(options) {
331
346
  );
332
347
  }
333
348
  await fs.rm(outputFolder, { recursive: true, force: true });
349
+ const docs = context.docs.filter(createMarkdownRenderer.isDocumentPage).filter(haveOutput);
334
350
  let total = 0;
335
- for (const doc of context.docs.filter(haveOutput)) {
351
+ for (const doc of docs) {
336
352
  const examples = findExamples$1(doc).filter(isRelevant);
337
353
  if (examples.length === 0) {
338
354
  continue;
@@ -360,14 +376,14 @@ md$3.renderer.rules.fence = (tokens, idx, _options, collected) => {
360
376
  const { language, tags } = createMarkdownRenderer.parseInfostring(info);
361
377
  const hashContent = `${map?.[0]}:${map?.[1]}:${info}:${content}`;
362
378
  const fingerprint = createMarkdownRenderer.getFingerprint(hashContent);
363
- let extension = undefined;
379
+ let extension = void 0;
364
380
  if (language === "import") {
365
381
  extension = content.split(".").at(-1)?.trim();
366
382
  }
367
383
  if (createMarkdownRenderer.hasTag(tags, "hidden")) {
368
384
  return "";
369
385
  }
370
- const name = createMarkdownRenderer.findTag(tags, "name")?.value ?? undefined;
386
+ const name = createMarkdownRenderer.findTag(tags, "name")?.value ?? void 0;
371
387
  collected.push({
372
388
  name,
373
389
  selector: `#example-${fingerprint}`,
@@ -448,7 +464,7 @@ function manifestProcessor(options = {}) {
448
464
  name: "manifestProcessor",
449
465
  before: "render",
450
466
  async handler(context) {
451
- const docs = context.docs.filter(haveOutput);
467
+ const docs = context.docs.filter(createMarkdownRenderer.isDocumentPage).filter(haveOutput);
452
468
  const pages = docs.map(manifestPageFromDocument);
453
469
  pages.sort((a, b) => {
454
470
  return a.path.localeCompare(b.path);
@@ -479,7 +495,7 @@ function normalizeOptions(options) {
479
495
  const defaults = {
480
496
  enabled: true,
481
497
  container: "body:begin",
482
- message: undefined
498
+ message: void 0
483
499
  };
484
500
  return { ...defaults, ...options };
485
501
  }
@@ -501,7 +517,7 @@ function motdProcessor(options = {}) {
501
517
  };
502
518
  context.addTemplateBlock(container, "motd-container", {
503
519
  filename: "partials/motd-container.njk.html",
504
- data: useLegacyTemplate ? undefined : data
520
+ data: useLegacyTemplate ? void 0 : data
505
521
  });
506
522
  if (useLegacyTemplate) {
507
523
  console.warn(
@@ -609,7 +625,7 @@ function htmlRedirectProcessor() {
609
625
  after: "render",
610
626
  async handler(context) {
611
627
  const { docs, outputFolder } = context;
612
- for (const doc of docs.filter(haveOutput)) {
628
+ for (const doc of docs.filter(createMarkdownRenderer.isDocumentPage).filter(haveOutput)) {
613
629
  if (doc.format !== "redirect") {
614
630
  continue;
615
631
  }
@@ -632,7 +648,7 @@ function redirectFileProcessor(prefix = "/", filename = "_redirects") {
632
648
  after: "render",
633
649
  async handler(context) {
634
650
  const { docs } = context;
635
- const lines = docs.filter(haveOutput).filter(isRedirect).map((doc) => {
651
+ const lines = docs.filter(createMarkdownRenderer.isDocumentPage).filter(haveOutput).filter(isRedirect).map((doc) => {
636
652
  const src = createMarkdownRenderer.normalizePath(
637
653
  doc.fileInfo.path,
638
654
  doc.fileInfo.outputName
@@ -650,7 +666,7 @@ function redirectFileProcessor(prefix = "/", filename = "_redirects") {
650
666
  }
651
667
 
652
668
  function getRedirects(docs) {
653
- return docs.map((it) => {
669
+ return docs.filter(createMarkdownRenderer.isDocumentPage).map((it) => {
654
670
  const { fileInfo } = it;
655
671
  const { path, outputName } = fileInfo;
656
672
  if (outputName === false) {
@@ -674,6 +690,7 @@ function redirectProcessor() {
674
690
  for (const redirect of redirects) {
675
691
  const { dir, base, name } = path.parse(redirect.from);
676
692
  context.addDocument({
693
+ kind: "page",
677
694
  id: `redirect:${redirect.from}-${redirect.to}`,
678
695
  name: `${redirect.from}-${redirect.to}`,
679
696
  alias: [],
@@ -794,7 +811,7 @@ async function getSCMData(pkg, options) {
794
811
  const { homepage } = pkg;
795
812
  const repository = getRepositoryUrl(pkg) ?? "";
796
813
  const pr = getPullRequestID(process.env);
797
- const prUrl = pr ? interpolate(options.prUrlFormat, { homepage, pr, repository }) : undefined;
814
+ const prUrl = pr ? interpolate(options.prUrlFormat, { homepage, pr, repository }) : void 0;
798
815
  return {
799
816
  branch: await getGitBranch(),
800
817
  commitShort,
@@ -911,21 +928,6 @@ function defineSources(sources) {
911
928
  return sources;
912
929
  }
913
930
 
914
- const documentAttributeKeys = [
915
- "title",
916
- "short-title",
917
- "layout",
918
- "name",
919
- "alias",
920
- "status",
921
- "visible",
922
- "include",
923
- "component",
924
- "href",
925
- "sortorder",
926
- "redirect_from"
927
- ];
928
-
929
931
  const threshold = 3;
930
932
  const suggestions = {
931
933
  hidden: "visible"
@@ -1002,7 +1004,7 @@ function isIndexPage(parsed) {
1002
1004
  }
1003
1005
  function getBadge(attrs) {
1004
1006
  if (!attrs.status) {
1005
- return undefined;
1007
+ return void 0;
1006
1008
  }
1007
1009
  switch (attrs.status) {
1008
1010
  case "Produktionsklar":
@@ -1053,7 +1055,7 @@ function* getDocumentAlias(attrs) {
1053
1055
  }
1054
1056
  function getComponent(attrs) {
1055
1057
  if (!attrs.component) {
1056
- return undefined;
1058
+ return void 0;
1057
1059
  }
1058
1060
  return toArray$1(attrs.component).map(normalizeComponent);
1059
1061
  }
@@ -1070,6 +1072,7 @@ function parseFile$1(filePath, basePath, content) {
1070
1072
  const include = attributes.include ?? true;
1071
1073
  validateAttributes(attributes, filePath, content);
1072
1074
  return {
1075
+ kind: "page",
1073
1076
  id: `fs:${filePath.replace(/\\/g, "/")}`,
1074
1077
  name,
1075
1078
  alias: Array.from(getDocumentAlias(attributes)),
@@ -1411,21 +1414,14 @@ function parseAPI(filePath, api) {
1411
1414
  html += generateSlotTable(api.slug, api.slots);
1412
1415
  }
1413
1416
  return {
1417
+ kind: "partial",
1414
1418
  id: `fs:${filePath.replace(/\\/g, "/")}`,
1415
1419
  name: `vue:${componentName}`,
1416
1420
  alias: [],
1417
- visible: false,
1418
- attributes: { sortorder: Infinity, redirectFrom: [] },
1419
1421
  body: html,
1420
- outline: [],
1421
1422
  format: "html",
1422
- tags: [],
1423
- template: "",
1424
1423
  fileInfo: {
1425
- path: "",
1426
- name: "",
1427
- fullPath: "",
1428
- outputName: false
1424
+ fullPath: filePath
1429
1425
  }
1430
1426
  };
1431
1427
  }
@@ -1491,6 +1487,7 @@ function parseFile(filePath, basePath, content) {
1491
1487
  const name = parsed.name;
1492
1488
  const urlpath = parsed.dir;
1493
1489
  return {
1490
+ kind: "page",
1494
1491
  id: `nav:${filePath.replace(/\\/g, "/")}`,
1495
1492
  name,
1496
1493
  alias: [],
@@ -1959,7 +1956,8 @@ function navigationProcessor() {
1959
1956
  stage: "generate-nav",
1960
1957
  name: "navigation-processor",
1961
1958
  handler(context) {
1962
- const navtree = generateNavtree(context.docs);
1959
+ const pages = context.docs.filter(createMarkdownRenderer.isDocumentPage);
1960
+ const navtree = generateNavtree(pages);
1963
1961
  context.setTopNavigation(navtree);
1964
1962
  context.setSideNavigation(navtree);
1965
1963
  }
@@ -2118,9 +2116,14 @@ class TemplateRenderError extends Error {
2118
2116
  }
2119
2117
  prettyError() {
2120
2118
  return [
2119
+ "",
2121
2120
  `An error occured when rendering a document.`,
2122
2121
  ` Document: "${this.filename}".`,
2123
- ` Message: ${this.message}`
2122
+ ` Message: ${this.message}`,
2123
+ "",
2124
+ "---",
2125
+ "",
2126
+ this.stack
2124
2127
  ].join("\n");
2125
2128
  }
2126
2129
  }
@@ -2402,7 +2405,7 @@ function nunjucksProcessor(options) {
2402
2405
  });
2403
2406
  }
2404
2407
  const formats = ["markdown", "json"];
2405
- const docs = context.docs.filter((it) => {
2408
+ const docs = context.docs.filter(createMarkdownRenderer.isDocumentPage).filter((it) => {
2406
2409
  if (!formats.includes(it.format)) {
2407
2410
  return false;
2408
2411
  }
@@ -2494,7 +2497,7 @@ async function compileVendor(assetFolder, vendor, options) {
2494
2497
  __VUE_PROD_DEVTOOLS__: "true",
2495
2498
  __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false"
2496
2499
  },
2497
- alias: vendor.alias ? { [`${vendor.package}`]: vendor.alias } : undefined,
2500
+ alias: vendor.alias ? { [`${vendor.package}`]: vendor.alias } : void 0,
2498
2501
  ...options
2499
2502
  });
2500
2503
  const content = await fs.readFile(outfile, "utf-8");
@@ -2517,7 +2520,7 @@ function normalizeVendorDefinition(vendor) {
2517
2520
  if (typeof vendor === "string") {
2518
2521
  return {
2519
2522
  package: vendor,
2520
- global: undefined,
2523
+ global: void 0,
2521
2524
  expose: "named",
2522
2525
  subpaths: []
2523
2526
  };
@@ -2527,7 +2530,7 @@ function normalizeVendorDefinition(vendor) {
2527
2530
  global: vendor.global,
2528
2531
  expose: vendor.expose ?? "named",
2529
2532
  subpaths: vendor.subpaths ?? [],
2530
- alias: vendor.alias ?? undefined
2533
+ alias: vendor.alias ?? void 0
2531
2534
  };
2532
2535
  }
2533
2536
  }
@@ -2888,7 +2891,7 @@ class Generator {
2888
2891
  const templateLoader = createTemplateLoader([]);
2889
2892
  const context = createContext("", templateLoader);
2890
2893
  await stage("generate-docs", context, processors, { verbose: false });
2891
- const docs = context.docs.filter(haveOutput);
2894
+ const docs = context.docs.filter(createMarkdownRenderer.isDocumentPage).filter(haveOutput);
2892
2895
  const pages = docs.map(manifestPageFromDocument);
2893
2896
  return { pages };
2894
2897
  }
@@ -3001,9 +3004,8 @@ function extractTerms(doc) {
3001
3004
  }
3002
3005
  }
3003
3006
  function isIndexable(doc) {
3004
- return Boolean(
3005
- doc.visible && doc.fileInfo.outputName && doc.format !== "redirect"
3006
- );
3007
+ const { visible, fileInfo, format } = doc;
3008
+ return Boolean(visible && fileInfo.outputName && format !== "redirect");
3007
3009
  }
3008
3010
  function getTerms(doc) {
3009
3011
  return {
@@ -3017,7 +3019,7 @@ function searchProcessor() {
3017
3019
  after: "generate-docs",
3018
3020
  name: "search-processor",
3019
3021
  handler(context) {
3020
- const entries = context.docs.filter(isIndexable).map(getTerms);
3022
+ const entries = context.docs.filter(createMarkdownRenderer.isDocumentPage).filter(isIndexable).map(getTerms);
3021
3023
  const index = generateIndex(entries);
3022
3024
  const body = JSON.stringify(index);
3023
3025
  const fingerprint = createMarkdownRenderer.getFingerprint(body);
@@ -3027,6 +3029,7 @@ function searchProcessor() {
3027
3029
  context.setTemplateData("searchDataUrl", expandedName);
3028
3030
  context.setTemplateData("searchDataIntegrity", integrity);
3029
3031
  context.addDocument({
3032
+ kind: "page",
3030
3033
  id: "search:data",
3031
3034
  name: "search-data",
3032
3035
  alias: [],
@@ -3080,3 +3083,4 @@ exports.topnavProcessor = topnavProcessor;
3080
3083
  exports.versionBannerProcessor = versionBannerProcessor;
3081
3084
  exports.versionProcessor = versionProcessor;
3082
3085
  exports.vueFileReader = vueFileReader;
3086
+ //# sourceMappingURL=index.js.map