@forsakringskassan/docs-generator 3.18.0 → 3.19.1

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.
@@ -2,7 +2,7 @@ import { createRequire as $createRequire } from "node:module";
2
2
 
3
3
  const require = $createRequire(import.meta.url);
4
4
 
5
- import { r as runAsWorker, f as format2, a as resolveConfig } from './vendor-i-8GIz5x.mjs';
5
+ import { r as runAsWorker, f as format2, a as resolveConfig } from './vendor-CLyw83WG.mjs';
6
6
  import 'node:url';
7
7
  import 'node:path';
8
8
  import 'fs';
@@ -54,4 +54,4 @@ async function formatCode(source, filepath) {
54
54
  runAsWorker(formatCode);
55
55
 
56
56
  export { formatCode };
57
- //# sourceMappingURL=format-code.worker-CFQ372Nb.mjs.map
57
+ //# sourceMappingURL=format-code.worker-DR9lHLhH.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"format-code.worker-CFQ372Nb.mjs","sources":["../src/utils/format-code.worker.ts"],"sourcesContent":["import { type Options, format as prettier, resolveConfig } from \"prettier\";\nimport { runAsWorker } from \"synckit\";\n\nconst configCache = new Map<string, Options | null>();\n\nasync function getConfig(filepath: string): Promise<Options | null> {\n const cached = configCache.get(filepath);\n if (cached !== undefined) {\n return cached;\n }\n const options = await resolveConfig(filepath);\n configCache.set(filepath, options);\n return options;\n}\n\n/**\n * @internal\n */\nexport async function formatCode(\n source: string,\n filepath: string,\n): Promise<string> {\n const options = await getConfig(filepath);\n const formatted = await prettier(source, { ...options, filepath });\n return formatted.trim();\n}\n\n/* eslint-disable-next-line unicorn/no-top-level-side-effects -- required for worker to function */\nrunAsWorker(formatCode);\n"],"names":["prettier"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,WAAA,uBAAkB,GAAA,EAA4B;AAEpD,eAAe,UAAU,QAAA,EAA2C;AAChE,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,GAAA,CAAI,QAAQ,CAAA;AACvC,EAAA,IAAI,WAAW,MAAA,EAAW;AACtB,IAAA,OAAO,MAAA;AAAA,EACX;AACA,EAAA,MAAM,OAAA,GAAU,MAAM,aAAA,CAAc,QAAQ,CAAA;AAC5C,EAAA,WAAA,CAAY,GAAA,CAAI,UAAU,OAAO,CAAA;AACjC,EAAA,OAAO,OAAA;AACX;AAKA,eAAsB,UAAA,CAClB,QACA,QAAA,EACe;AACf,EAAA,MAAM,OAAA,GAAU,MAAM,SAAA,CAAU,QAAQ,CAAA;AACxC,EAAA,MAAM,SAAA,GAAY,MAAMA,OAAA,CAAS,MAAA,EAAQ,EAAE,GAAG,OAAA,EAAS,UAAU,CAAA;AACjE,EAAA,OAAO,UAAU,IAAA,EAAK;AAC1B;AAGA,WAAA,CAAY,UAAU,CAAA;;"}
1
+ {"version":3,"file":"format-code.worker-DR9lHLhH.mjs","sources":["../src/utils/format-code.worker.ts"],"sourcesContent":["import { type Options, format as prettier, resolveConfig } from \"prettier\";\nimport { runAsWorker } from \"synckit\";\n\nconst configCache = new Map<string, Options | null>();\n\nasync function getConfig(filepath: string): Promise<Options | null> {\n const cached = configCache.get(filepath);\n if (cached !== undefined) {\n return cached;\n }\n const options = await resolveConfig(filepath);\n configCache.set(filepath, options);\n return options;\n}\n\n/**\n * @internal\n */\nexport async function formatCode(\n source: string,\n filepath: string,\n): Promise<string> {\n const options = await getConfig(filepath);\n const formatted = await prettier(source, { ...options, filepath });\n return formatted.trim();\n}\n\n/* eslint-disable-next-line unicorn/no-top-level-side-effects -- required for worker to function */\nrunAsWorker(formatCode);\n"],"names":["prettier"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,WAAA,uBAAkB,GAAA,EAA4B;AAEpD,eAAe,UAAU,QAAA,EAA2C;AAChE,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,GAAA,CAAI,QAAQ,CAAA;AACvC,EAAA,IAAI,WAAW,MAAA,EAAW;AACtB,IAAA,OAAO,MAAA;AAAA,EACX;AACA,EAAA,MAAM,OAAA,GAAU,MAAM,aAAA,CAAc,QAAQ,CAAA;AAC5C,EAAA,WAAA,CAAY,GAAA,CAAI,UAAU,OAAO,CAAA;AACjC,EAAA,OAAO,OAAA;AACX;AAKA,eAAsB,UAAA,CAClB,QACA,QAAA,EACe;AACf,EAAA,MAAM,OAAA,GAAU,MAAM,SAAA,CAAU,QAAQ,CAAA;AACxC,EAAA,MAAM,SAAA,GAAY,MAAMA,OAAA,CAAS,MAAA,EAAQ,EAAE,GAAG,OAAA,EAAS,UAAU,CAAA;AACjE,EAAA,OAAO,UAAU,IAAA,EAAK;AAC1B;AAGA,WAAA,CAAY,UAAU,CAAA;;"}
package/dist/index.d.mts CHANGED
@@ -1019,7 +1019,7 @@ export declare interface SourceUrlProcessorOptions extends ProcessorOptions {
1019
1019
  readonly sourceFiles?: string[];
1020
1020
  readonly urlFormat: string;
1021
1021
  /** File extension used for finding component by name */
1022
- readonly componentFileExtension?: string;
1022
+ readonly componentFileExtension?: string | string[];
1023
1023
  }
1024
1024
 
1025
1025
  /**
package/dist/index.mjs CHANGED
@@ -3,13 +3,13 @@ import { createRequire as $createRequire } from "node:module";
3
3
  const require = $createRequire(import.meta.url);
4
4
 
5
5
  import { ApiItemKind, ApiModel } from '@microsoft/api-extractor-model';
6
- import { Z as Ze, M as MarkdownItCallable, g as fm, s as strToU8, z as zlibSync, h as strFromU8, d as dedent, i as closest, j as distance, k as isCI, m as moduleImporter, l as cliProgress, t as tinylr, w as watch, n as createInstance, o as fse, p as inter } from './vendor-i-8GIz5x.mjs';
6
+ import { Z as Ze, M as MarkdownItCallable, g as fm, s as strToU8, z as zlibSync, h as strFromU8, d as dedent, i as closest, j as distance, k as isCI, m as moduleImporter, l as cliProgress, t as tinylr, w as watch, n as createInstance, o as fse, p as inter } from './vendor-CLyw83WG.mjs';
7
7
  import path__default from 'node:path';
8
8
  import fs from 'node:fs/promises';
9
9
  import crypto from 'node:crypto';
10
10
  import path from 'node:path/posix';
11
11
  import { exec, execSync } from 'node:child_process';
12
- import { g as generateId, f as formatCode, p as parseImport, a as getFingerprint, b as parseInfostring, h as hasTag, d as findTag, e as getOutputFilePath, i as isDocumentPage, j as findDocument, k as getDocumentBody, n as normalizePath, l as htmlencode, c as createMarkdownRenderer } from './create-markdown-renderer-DrDHT9bZ.mjs';
12
+ import { g as generateId, f as formatCode, p as parseInfostring, a as getFingerprint, h as hasTag, b as parseImport, d as findTag, e as getOutputFilePath, i as isDocumentPage, j as findDocument, k as getDocumentBody, n as normalizePath, l as htmlencode, c as createMarkdownRenderer } from './create-markdown-renderer-DSov_Gkx.mjs';
13
13
  import { DocExcerpt } from '@microsoft/tsdoc';
14
14
  import pkg from '../package.json' with { type: "json" };
15
15
  import fs__default, { existsSync, readFileSync, copyFileSync } from 'node:fs';
@@ -640,108 +640,6 @@ function isDocumentPartial(doc) {
640
640
  return doc.kind === "partial";
641
641
  }
642
642
 
643
- function getExampleName(filename) {
644
- return path__default.parse(filename).name;
645
- }
646
-
647
- const vueMajor = Number(version.split(".", 2)[0]);
648
- function vueGenerator() {
649
- switch (vueMajor) {
650
- case 2:
651
- throw new Error(
652
- "Vue 2 is no longer supported, upgrade to Vue 3 or downgrade docs-generator"
653
- );
654
- case 3:
655
- return generateCode;
656
- }
657
- }
658
- function generateExample(options) {
659
- const { language, fileMatcher } = options;
660
- if (language === "import") {
661
- const parsed = parseImport(options.source);
662
- const filename = fileMatcher(parsed.filename, "when importing example");
663
- const language2 = parsed.extension;
664
- const comments = parsed.comments;
665
- const content = fs__default.readFileSync(filename, "utf8");
666
- const example = generateExample({
667
- ...options,
668
- source: content,
669
- language: language2,
670
- filename
671
- });
672
- return { ...example, comments };
673
- }
674
- switch (language) {
675
- case "vue":
676
- return generateVueExample(options);
677
- case "html":
678
- return generateStaticExample(options);
679
- default:
680
- return generateStaticExample(options);
681
- }
682
- }
683
- function generateVueExample(options) {
684
- const { filename, source, parent, setupPath, tags } = options;
685
- const fn = vueGenerator();
686
- const slug = getExampleName(filename);
687
- const fingerprint = getFingerprint(source);
688
- const { markup, sourcecode, output } = fn({
689
- filename,
690
- slug,
691
- fingerprint,
692
- code: source,
693
- setupPath
694
- });
695
- if (output) {
696
- return {
697
- source,
698
- language: options.language,
699
- comments: [],
700
- tags,
701
- markup,
702
- output,
703
- runtime: true,
704
- task: {
705
- outputFile: output,
706
- sourcecode,
707
- sourceFile: filename,
708
- parent
709
- }
710
- };
711
- }
712
- return {
713
- source: sourcecode,
714
- language: "plaintext",
715
- comments: [],
716
- tags,
717
- markup,
718
- output: null,
719
- runtime: true,
720
- task: null
721
- };
722
- }
723
- function generateStaticExample(options) {
724
- const { filename, source, language, tags } = options;
725
- const slug = getExampleName(filename);
726
- const fingerprint = getFingerprint(source);
727
- const asset = `${slug}-${fingerprint}.${language}`;
728
- const runtimeLanguages = ["html"];
729
- const runtime = runtimeLanguages.includes(language);
730
- return {
731
- source,
732
- language: options.language,
733
- comments: [],
734
- tags,
735
- markup: source,
736
- output: runtime ? asset : null,
737
- runtime,
738
- task: null
739
- };
740
- }
741
-
742
- const url = new URL("./worker--TrTGmqL.mjs", import.meta.url);
743
- const filePath = fileURLToPath(url);
744
-
745
643
  const md$6 = MarkdownItCallable();
746
644
  md$6.renderer.rules.fence = (tokens, idx, _options, env) => {
747
645
  const { collected, exampleFileMatcher } = env;
@@ -929,39 +827,46 @@ ${JSON.stringify(attributes)}
929
827
  function cmp(a, b) {
930
828
  return a[0].localeCompare(b[0]);
931
829
  }
932
- async function extractDocument(doc, docs, partials, options) {
933
- const { outputFolder } = options;
934
- const markdown = doc.body.replaceAll(
935
- /^:::\s*api(.*)\n([\s\S]+?):::/gm,
936
- (match, info, content2) => {
937
- const needle = content2.trim();
938
- const trimmedInfo = info.trim();
939
- const tags = trimmedInfo ? trimmedInfo.split(/\s+/) : [];
940
- const result = findDocument(docs, needle);
941
- if (!result.document) {
942
- return match;
943
- }
944
- const { document, kind, reference } = result;
945
- if (!isDocumentPartial(document)) {
946
- return match;
947
- }
948
- const body = getDocumentBody(document, tags, {
949
- kind,
950
- reference
951
- });
952
- const fingerprint = getFingerprint(body);
953
- const id = `partial:${document.format}:${fingerprint}`;
954
- partials.set(id, {
955
- id,
956
- format: document.format,
957
- body
958
- });
959
- return `:::api
830
+ function findApiContainer(text, cb) {
831
+ const regex = /^:::\s*api(.*)\n([\s\S]+?):::\n/gm;
832
+ return text.replaceAll(regex, (match, info, rawContent) => {
833
+ const content = rawContent.trim();
834
+ const trimmedInfo = info.trim();
835
+ const tags = trimmedInfo ? trimmedInfo.split(/\s+/) : [];
836
+ return cb({ match, tags, content });
837
+ });
838
+ }
839
+ function onApiContainer(docs, partials, container) {
840
+ const { match, tags, content } = container;
841
+ const result = findDocument(docs, content);
842
+ if (!result.document) {
843
+ return match;
844
+ }
845
+ const { document, kind, reference } = result;
846
+ if (!isDocumentPartial(document)) {
847
+ return match;
848
+ }
849
+ const body = getDocumentBody(document, tags, {
850
+ kind,
851
+ reference
852
+ });
853
+ const fingerprint = getFingerprint(body);
854
+ const id = `partial:${document.format}:${fingerprint}`;
855
+ partials.set(id, {
856
+ id,
857
+ format: document.format,
858
+ body
859
+ });
860
+ return `:::api
960
861
  ${id}
961
862
  :::
962
863
  `;
963
- }
964
- );
864
+ }
865
+ async function extractDocument(doc, docs, partials, options) {
866
+ const { outputFolder } = options;
867
+ const markdown = findApiContainer(doc.body, (container) => {
868
+ return onApiContainer(docs, partials, container);
869
+ });
965
870
  const src = doc.fileInfo.fullPath;
966
871
  const dst = path__default.join(outputFolder, "files", doc.fileInfo.fullPath);
967
872
  const fm2 = await getFrontMatter(src);
@@ -1089,6 +994,108 @@ function extractMarkdownProcessor(options) {
1089
994
  };
1090
995
  }
1091
996
 
997
+ function getExampleName(filename) {
998
+ return path__default.parse(filename).name;
999
+ }
1000
+
1001
+ const vueMajor = Number(version.split(".", 2)[0]);
1002
+ function vueGenerator() {
1003
+ switch (vueMajor) {
1004
+ case 2:
1005
+ throw new Error(
1006
+ "Vue 2 is no longer supported, upgrade to Vue 3 or downgrade docs-generator"
1007
+ );
1008
+ case 3:
1009
+ return generateCode;
1010
+ }
1011
+ }
1012
+ function generateExample(options) {
1013
+ const { language, fileMatcher } = options;
1014
+ if (language === "import") {
1015
+ const parsed = parseImport(options.source);
1016
+ const filename = fileMatcher(parsed.filename, "when importing example");
1017
+ const language2 = parsed.extension;
1018
+ const comments = parsed.comments;
1019
+ const content = fs__default.readFileSync(filename, "utf8");
1020
+ const example = generateExample({
1021
+ ...options,
1022
+ source: content,
1023
+ language: language2,
1024
+ filename
1025
+ });
1026
+ return { ...example, comments };
1027
+ }
1028
+ switch (language) {
1029
+ case "vue":
1030
+ return generateVueExample(options);
1031
+ case "html":
1032
+ return generateStaticExample(options);
1033
+ default:
1034
+ return generateStaticExample(options);
1035
+ }
1036
+ }
1037
+ function generateVueExample(options) {
1038
+ const { filename, source, parent, setupPath, tags } = options;
1039
+ const fn = vueGenerator();
1040
+ const slug = getExampleName(filename);
1041
+ const fingerprint = getFingerprint(source);
1042
+ const { markup, sourcecode, output } = fn({
1043
+ filename,
1044
+ slug,
1045
+ fingerprint,
1046
+ code: source,
1047
+ setupPath
1048
+ });
1049
+ if (output) {
1050
+ return {
1051
+ source,
1052
+ language: options.language,
1053
+ comments: [],
1054
+ tags,
1055
+ markup,
1056
+ output,
1057
+ runtime: true,
1058
+ task: {
1059
+ outputFile: output,
1060
+ sourcecode,
1061
+ sourceFile: filename,
1062
+ parent
1063
+ }
1064
+ };
1065
+ }
1066
+ return {
1067
+ source: sourcecode,
1068
+ language: "plaintext",
1069
+ comments: [],
1070
+ tags,
1071
+ markup,
1072
+ output: null,
1073
+ runtime: true,
1074
+ task: null
1075
+ };
1076
+ }
1077
+ function generateStaticExample(options) {
1078
+ const { filename, source, language, tags } = options;
1079
+ const slug = getExampleName(filename);
1080
+ const fingerprint = getFingerprint(source);
1081
+ const asset = `${slug}-${fingerprint}.${language}`;
1082
+ const runtimeLanguages = ["html"];
1083
+ const runtime = runtimeLanguages.includes(language);
1084
+ return {
1085
+ source,
1086
+ language: options.language,
1087
+ comments: [],
1088
+ tags,
1089
+ markup: source,
1090
+ output: runtime ? asset : null,
1091
+ runtime,
1092
+ task: null
1093
+ };
1094
+ }
1095
+
1096
+ const url = new URL("./worker-DfUDllYf.mjs", import.meta.url);
1097
+ const filePath = fileURLToPath(url);
1098
+
1092
1099
  const md$5 = MarkdownItCallable();
1093
1100
  md$5.renderer.rules.fence = (tokens, idx, _options, rawEnv) => {
1094
1101
  const { collected } = rawEnv;
@@ -1505,6 +1512,19 @@ function selectableVersionProcessor(pkg, container, options) {
1505
1512
  };
1506
1513
  }
1507
1514
 
1515
+ function filenamePattern(base, extensions) {
1516
+ if (typeof extensions === "string") {
1517
+ extensions = [extensions];
1518
+ }
1519
+ switch (extensions.length) {
1520
+ case 0:
1521
+ return base;
1522
+ case 1:
1523
+ return `${base}.${extensions[0]}`;
1524
+ default:
1525
+ return `${base}.{${extensions.join(",")}}`;
1526
+ }
1527
+ }
1508
1528
  function sourceUrlProcessor(...args) {
1509
1529
  const pkg = args.length === 2 ? args[0] : {};
1510
1530
  const options = args.length === 2 ? args[1] : args[0];
@@ -1512,7 +1532,7 @@ function sourceUrlProcessor(...args) {
1512
1532
  enabled = true,
1513
1533
  sourceFiles = ["**/*"],
1514
1534
  urlFormat,
1515
- componentFileExtension = "vue"
1535
+ componentFileExtension = ["vue"]
1516
1536
  } = options;
1517
1537
  const repository = getRepositoryUrl(pkg) ?? "";
1518
1538
  return {
@@ -1529,7 +1549,7 @@ function sourceUrlProcessor(...args) {
1529
1549
  const short = await gitCommitHash("short") ?? "";
1530
1550
  function componentSourceUrl(component) {
1531
1551
  const { source, name } = component;
1532
- const filename = source ?? `${name}.${componentFileExtension}`;
1552
+ const filename = source ?? filenamePattern(name, componentFileExtension);
1533
1553
  const path = matcher(filename, "when generating source url");
1534
1554
  return interpolate(urlFormat, {
1535
1555
  path,
@@ -2125,6 +2145,13 @@ function getComponent(attrs) {
2125
2145
  }
2126
2146
  return toArray$1(attrs.component).map(normalizeComponent);
2127
2147
  }
2148
+ function normalizeBody(text) {
2149
+ text = text.replaceAll("\r\n", "\n");
2150
+ if (!text.endsWith("\n")) {
2151
+ text += "\n";
2152
+ }
2153
+ return text;
2154
+ }
2128
2155
  function parseFile$2(filePath, basePath, content) {
2129
2156
  const relative = basePath ? path__default.relative(basePath, normalizePath(filePath)) : normalizePath(filePath);
2130
2157
  const parsed = path__default.parse(relative);
@@ -2156,7 +2183,7 @@ function parseFile$2(filePath, basePath, content) {
2156
2183
  },
2157
2184
  sortorder: attributes.sortorder ?? Infinity
2158
2185
  },
2159
- body: blocks.body,
2186
+ body: normalizeBody(blocks.body),
2160
2187
  outline,
2161
2188
  format: "markdown",
2162
2189
  tags: [],
@@ -4474,6 +4501,9 @@ class Generator {
4474
4501
  context.addTemplateBlock("footer:right", "footer:right", {
4475
4502
  filename: "partials/footer-right.html"
4476
4503
  });
4504
+ context.addTemplateBlock("component:aside", "component:aside", {
4505
+ filename: "partials/component-aside.html"
4506
+ });
4477
4507
  const generatedFiles = [
4478
4508
  await stage("generate-docs", context, processors),
4479
4509
  await stage("generate-nav", context, processors),