@forsakringskassan/docs-generator 3.19.1 → 3.20.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-CLyw83WG.mjs';
5
+ import { r as runAsWorker, f as format2, a as resolveConfig } from './vendor-GtJZoX7J.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-DR9lHLhH.mjs.map
57
+ //# sourceMappingURL=format-code.worker-NI_KIDrb.mjs.map
@@ -1 +1 @@
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;;"}
1
+ {"version":3,"file":"format-code.worker-NI_KIDrb.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
@@ -184,6 +184,18 @@ export declare interface DocumentPartialReference {
184
184
  reference: string;
185
185
  }
186
186
 
187
+ /**
188
+ * Serializable metadata exported with extracted documentation.
189
+ *
190
+ * This interface can be augmented to describe application-specific metadata.
191
+ *
192
+ * @public
193
+ * @since %version%
194
+ */
195
+ export declare interface ExtractedDocsMetadata {
196
+ [key: string]: unknown;
197
+ }
198
+
187
199
  /**
188
200
  * Type representing the exported docs module when extracting markdown
189
201
  * documents.
@@ -198,12 +210,14 @@ export declare interface DocumentPartialReference {
198
210
  */
199
211
  export declare interface ExtractedDocsModule {
200
212
  readonly generatorVersion: string;
213
+ readonly version: string | null;
214
+ readonly metadata: ExtractedDocsMetadata | null;
201
215
  readonly basePath: string;
202
216
  readonly exampleFolders: string[];
203
217
  readonly filesPath: string;
204
218
  readonly partialsPath: string;
205
219
  readonly linksPath: string;
206
- sourceFiles(src: Partial<SourceFiles>): SourceFiles[];
220
+ sourceFiles(src?: Partial<SourceFiles>): SourceFiles[];
207
221
  }
208
222
 
209
223
  /**
@@ -245,6 +259,17 @@ export declare interface ExtractMarkdownOptions extends ProcessorOptions {
245
259
  * Folder to write docs to.
246
260
  */
247
261
  outputFolder: string;
262
+ /**
263
+ * Version written to the `version` field of the generated `index.mjs`.
264
+ */
265
+ version?: string;
266
+ /**
267
+ * Callback providing serializable metadata for the generated `index.mjs`.
268
+ *
269
+ * Called once per extraction and awaited. Missing callbacks and nullish
270
+ * results are exported as `null`.
271
+ */
272
+ metadata?: () => ExtractedDocsMetadata | undefined | null | Promise<ExtractedDocsMetadata | undefined | null>;
248
273
  }
249
274
 
250
275
  /**
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-CLyw83WG.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-GtJZoX7J.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 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';
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-Bm-yRJ38.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';
@@ -828,7 +828,7 @@ function cmp(a, b) {
828
828
  return a[0].localeCompare(b[0]);
829
829
  }
830
830
  function findApiContainer(text, cb) {
831
- const regex = /^:::\s*api(.*)\n([\s\S]+?):::\n/gm;
831
+ const regex = /^:::[ \t]*api(?=[ \t]|\r?\n)([^\n]*)\n([\s\S]+?):::\n/gm;
832
832
  return text.replaceAll(regex, (match, info, rawContent) => {
833
833
  const content = rawContent.trim();
834
834
  const trimmedInfo = info.trim();
@@ -908,21 +908,22 @@ async function extractLinks(docs, options) {
908
908
  await fs.mkdir(path__default.dirname(dst), { recursive: true });
909
909
  await fs.writeFile(dst, content, "utf8");
910
910
  }
911
- async function writeIndex(options) {
912
- const { outputFolder } = options;
913
- const dst = path__default.join(outputFolder, "index.mjs");
914
- const lines = [
911
+ function generateIndex$1(options) {
912
+ const { generatorVersion, version, metadata = null } = options;
913
+ return [
915
914
  `import path from "node:path";`,
916
915
  `import { frontMatterFileReader, partialFileReader } from "@forsakringskassan/docs-generator";`,
917
916
  ``,
918
- `export const generatorVersion = "${pkg.version}";`,
917
+ `export const generatorVersion = ${JSON.stringify(generatorVersion)};`,
918
+ `export const version = ${JSON.stringify(version)};`,
919
+ `export const metadata = ${JSON.stringify(metadata)};`,
919
920
  `export const basePath = import.meta.dirname;`,
920
921
  `export const exampleFolders = [path.join(basePath, "files")];`,
921
922
  `export const filesPath = path.join(basePath, "files");`,
922
923
  `export const partialsPath = [path.join(basePath, "partials.json")];`,
923
924
  `export const linksPath = [path.join(basePath, "links.json")];`,
924
925
  ``,
925
- `export function sourceFiles(src) {`,
926
+ `export function sourceFiles(src = {}) {`,
926
927
  ` return [`,
927
928
  ` { `,
928
929
  ` include: path.join(filesPath, "**/*.md"),`,
@@ -938,27 +939,43 @@ async function writeIndex(options) {
938
939
  ` ];`,
939
940
  `}`
940
941
  ];
942
+ }
943
+ async function writeIndex(options) {
944
+ const { outputFolder, version, metadata } = options;
945
+ const dst = path__default.join(outputFolder, "index.mjs");
946
+ const lines = generateIndex$1({
947
+ generatorVersion: pkg.version,
948
+ version,
949
+ metadata
950
+ });
941
951
  await fs.writeFile(dst, lines.join("\n"), "utf8");
942
952
  }
943
953
  async function writeDts(options) {
944
954
  const { outputFolder } = options;
945
955
  const dst = path__default.join(outputFolder, "index.d.mts");
946
956
  const lines = [
947
- `import { SourceFiles } from "@forsakringskassan/docs-generator";`,
957
+ `import { ExtractedDocsMetadata, SourceFiles } from "@forsakringskassan/docs-generator";`,
948
958
  ``,
949
959
  `export declare const generatorVersion: string;`,
960
+ `export declare const version: string | null;`,
961
+ `export declare const metadata: ExtractedDocsMetadata | null;`,
950
962
  `export declare const basePath: string;`,
951
963
  `export declare const exampleFolders: string[];`,
952
964
  `export declare const filesPath: string;`,
953
965
  `export declare const partialsPath: string;`,
954
966
  `export declare const linksPath: string;`,
955
967
  ``,
956
- `export declare function sourceFiles(src: Partial<SourceFiles>): SourceFiles[];`
968
+ `export declare function sourceFiles(this: void, src?: Partial<SourceFiles>): SourceFiles[];`
957
969
  ];
958
970
  await fs.writeFile(dst, lines.join("\n"), "utf8");
959
971
  }
960
972
  function extractMarkdownProcessor(options) {
961
- const { enabled = true, outputFolder } = options;
973
+ const {
974
+ enabled = true,
975
+ outputFolder,
976
+ version = null,
977
+ metadata: metadataFn
978
+ } = options;
962
979
  return {
963
980
  after: "render",
964
981
  name: "extract-markdown-processor",
@@ -988,7 +1005,12 @@ function extractMarkdownProcessor(options) {
988
1005
  return extractExamples(page, { outputFolder });
989
1006
  });
990
1007
  await Promise.all(resources);
991
- await writeIndex({ outputFolder });
1008
+ const metadata = await metadataFn?.() ?? null;
1009
+ await writeIndex({
1010
+ outputFolder,
1011
+ version,
1012
+ metadata
1013
+ });
992
1014
  await writeDts({ outputFolder });
993
1015
  }
994
1016
  };