@forsakringskassan/docs-generator 3.13.0 → 3.15.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.mjs CHANGED
@@ -8,17 +8,20 @@ import path__default from 'node:path';
8
8
  import crypto from 'node:crypto';
9
9
  import path from 'node:path/posix';
10
10
  import { exec, execSync } from 'node:child_process';
11
- 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, m as filePath, c as createMarkdownRenderer, o as generateExample } from './create-markdown-renderer-DwLB6VT1.mjs';
11
+ 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-BlUpDhJP.mjs';
12
12
  import { DocExcerpt } from '@microsoft/tsdoc';
13
13
  import fs from 'node:fs/promises';
14
+ import pkg from '../package.json' with { type: "json" };
15
+ import fs__default, { existsSync, readFileSync, copyFileSync } from 'node:fs';
16
+ import { version } from 'vue';
17
+ import { g as generateCode } from './vue3-DbJPWpmQ.mjs';
18
+ import { fileURLToPath } from 'node:url';
14
19
  import util, { promisify, styleText } from 'node:util';
15
20
  import { codeFrameColumns } from '@babel/code-frame';
16
21
  import { parse as parse$1 } from '@babel/parser';
17
22
  import traverseModule from '@babel/traverse';
18
23
  import { parse, compileScript as compileScript$1, compileTemplate } from 'vue/compiler-sfc';
19
24
  import { parse as parse$2 } from 'vue-docgen-api';
20
- import fs__default, { existsSync, readFileSync, copyFileSync } from 'node:fs';
21
- import { fileURLToPath } from 'node:url';
22
25
  import { compileAsync, NodePackageImporter } from 'sass';
23
26
  import { t as tsconfigPath } from './tsconfig-path-bG7G_cK8.mjs';
24
27
  import esbuild$1, { build } from 'esbuild';
@@ -50,8 +53,6 @@ import 'module';
50
53
  import 'fs/promises';
51
54
  import 'process';
52
55
  import 'v8';
53
- import 'vue';
54
- import './vue3-DbJPWpmQ.mjs';
55
56
 
56
57
  function toArray$2(value) {
57
58
  return Array.isArray(value) ? value : [value];
@@ -90,10 +91,11 @@ function memoize(callback) {
90
91
  };
91
92
  }
92
93
 
93
- function fileMatcher(patterns) {
94
+ function fileMatcher(patterns, options) {
95
+ const { ignore } = options;
94
96
  const fileList = ts(patterns, {
95
97
  posix: true,
96
- ignore: "**/node_modules/**"
98
+ ignore
97
99
  });
98
100
  return memoize((filename, context) => {
99
101
  const matches = fileList.filter((file) => {
@@ -230,6 +232,16 @@ function haveOutput(doc) {
230
232
  return Boolean(fileInfo.outputName);
231
233
  }
232
234
 
235
+ function hasPrettyError(value) {
236
+ if (!value) {
237
+ return false;
238
+ }
239
+ if (typeof value !== "object") {
240
+ return false;
241
+ }
242
+ return "prettyError" in value && typeof value.prettyError === "function";
243
+ }
244
+
233
245
  function interpolate(value, data) {
234
246
  return value.replaceAll(/\{\{([^{}]+)\}\}/g, (match, raw) => {
235
247
  const key = raw.trim();
@@ -630,6 +642,108 @@ function isDocumentPartial(doc) {
630
642
  return doc.kind === "partial";
631
643
  }
632
644
 
645
+ function getExampleName(filename) {
646
+ return path__default.parse(filename).name;
647
+ }
648
+
649
+ const vueMajor = Number(version.split(".", 2)[0]);
650
+ function vueGenerator() {
651
+ switch (vueMajor) {
652
+ case 2:
653
+ throw new Error(
654
+ "Vue 2 is no longer supported, upgrade to Vue 3 or downgrade docs-generator"
655
+ );
656
+ case 3:
657
+ return generateCode;
658
+ }
659
+ }
660
+ function generateExample(options) {
661
+ const { language, fileMatcher } = options;
662
+ if (language === "import") {
663
+ const parsed = parseImport(options.source);
664
+ const filename = fileMatcher(parsed.filename, "when importing example");
665
+ const language2 = parsed.extension;
666
+ const comments = parsed.comments;
667
+ const content = fs__default.readFileSync(filename, "utf8");
668
+ const example = generateExample({
669
+ ...options,
670
+ source: content,
671
+ language: language2,
672
+ filename
673
+ });
674
+ return { ...example, comments };
675
+ }
676
+ switch (language) {
677
+ case "vue":
678
+ return generateVueExample(options);
679
+ case "html":
680
+ return generateStaticExample(options);
681
+ default:
682
+ return generateStaticExample(options);
683
+ }
684
+ }
685
+ function generateVueExample(options) {
686
+ const { filename, source, parent, setupPath, tags } = options;
687
+ const fn = vueGenerator();
688
+ const slug = getExampleName(filename);
689
+ const fingerprint = getFingerprint(source);
690
+ const { markup, sourcecode, output } = fn({
691
+ filename,
692
+ slug,
693
+ fingerprint,
694
+ code: source,
695
+ setupPath
696
+ });
697
+ if (output) {
698
+ return {
699
+ source,
700
+ language: options.language,
701
+ comments: [],
702
+ tags,
703
+ markup,
704
+ output,
705
+ runtime: true,
706
+ task: {
707
+ outputFile: output,
708
+ sourcecode,
709
+ sourceFile: filename,
710
+ parent
711
+ }
712
+ };
713
+ }
714
+ return {
715
+ source: sourcecode,
716
+ language: "plaintext",
717
+ comments: [],
718
+ tags,
719
+ markup,
720
+ output: null,
721
+ runtime: true,
722
+ task: null
723
+ };
724
+ }
725
+ function generateStaticExample(options) {
726
+ const { filename, source, language, tags } = options;
727
+ const slug = getExampleName(filename);
728
+ const fingerprint = getFingerprint(source);
729
+ const asset = `${slug}-${fingerprint}.${language}`;
730
+ const runtimeLanguages = ["html"];
731
+ const runtime = runtimeLanguages.includes(language);
732
+ return {
733
+ source,
734
+ language: options.language,
735
+ comments: [],
736
+ tags,
737
+ markup: source,
738
+ output: runtime ? asset : null,
739
+ runtime,
740
+ task: null
741
+ };
742
+ }
743
+
744
+ const url = new URL("./worker--TrTGmqL.mjs", import.meta.url);
745
+ const filePath = fileURLToPath(url);
746
+
633
747
  const md$6 = MarkdownItCallable();
634
748
  md$6.renderer.rules.fence = (tokens, idx, _options, env) => {
635
749
  const { collected, exampleFileMatcher } = env;
@@ -898,23 +1012,24 @@ async function writeIndex(options) {
898
1012
  `import path from "node:path";`,
899
1013
  `import { frontMatterFileReader, partialFileReader } from "@forsakringskassan/docs-generator";`,
900
1014
  ``,
901
- `export const basename = import.meta.dirname;`,
902
- `export const exampleFolders = [path.join(basename, "files")];`,
903
- `export const filesPath = path.join(basename, "files");`,
904
- `export const partialsPath = [path.join(basename, "partials.json")];`,
905
- `export const linksPath = [path.join(basename, "links.json")];`,
1015
+ `export const generatorVersion = "${pkg.version}";`,
1016
+ `export const basePath = import.meta.dirname;`,
1017
+ `export const exampleFolders = [path.join(basePath, "files")];`,
1018
+ `export const filesPath = path.join(basePath, "files");`,
1019
+ `export const partialsPath = [path.join(basePath, "partials.json")];`,
1020
+ `export const linksPath = [path.join(basePath, "links.json")];`,
906
1021
  ``,
907
1022
  `export function sourceFiles(src) {`,
908
1023
  ` return [`,
909
1024
  ` { `,
910
- ` include: path.join(basename, "files/**/*.md"),`,
911
- ` basename,`,
1025
+ ` include: path.join(filesPath, "**/*.md"),`,
1026
+ ` basePath: filesPath,`,
912
1027
  ` fileReader: frontMatterFileReader,`,
913
1028
  ` ...src`,
914
1029
  ` },`,
915
1030
  ` { `,
916
- ` include: path.join(basename, "partials.json"),`,
917
- ` basename,`,
1031
+ ` include: path.join(basePath, "partials.json"),`,
1032
+ ` basePath,`,
918
1033
  ` fileReader: partialFileReader,`,
919
1034
  ` }`,
920
1035
  ` ];`,
@@ -928,7 +1043,8 @@ async function writeDts(options) {
928
1043
  const lines = [
929
1044
  `import { SourceFiles } from "@forsakringskassan/docs-generator";`,
930
1045
  ``,
931
- `export declare const basename: string;`,
1046
+ `export declare const generatorVersion: string;`,
1047
+ `export declare const basePath: string;`,
932
1048
  `export declare const exampleFolders: string[];`,
933
1049
  `export declare const filesPath: string;`,
934
1050
  `export declare const partialsPath: string;`,
@@ -1401,7 +1517,9 @@ function sourceUrlProcessor(...args) {
1401
1517
  componentFileExtension = "vue"
1402
1518
  } = options;
1403
1519
  const repository = getRepositoryUrl(pkg) ?? "";
1404
- const matcher = fileMatcher(sourceFiles);
1520
+ const matcher = fileMatcher(sourceFiles, {
1521
+ ignore: ["**/node_modules/**"]
1522
+ });
1405
1523
  return {
1406
1524
  after: "generate-docs",
1407
1525
  name: "source-url-processor",
@@ -2757,6 +2875,12 @@ async function vueFileReader(filePath) {
2757
2875
  return [vueApi, vueTranslation];
2758
2876
  }
2759
2877
 
2878
+ async function glob(pattern) {
2879
+ const cwd = process.cwd();
2880
+ const iterator = fs.glob(pattern, { withFileTypes: true });
2881
+ const ents = await Array.fromAsync(iterator);
2882
+ return ents.filter((st) => st.isFile()).map((st) => path__default.relative(cwd, path__default.join(st.parentPath, st.name)));
2883
+ }
2760
2884
  async function globAll(pattern) {
2761
2885
  if (!pattern) {
2762
2886
  return /* @__PURE__ */ new Set();
@@ -2764,9 +2888,7 @@ async function globAll(pattern) {
2764
2888
  if (!Array.isArray(pattern)) {
2765
2889
  pattern = [pattern];
2766
2890
  }
2767
- const results = await Promise.all(
2768
- pattern.map((it) => Ze(it, { nodir: true }))
2769
- );
2891
+ const results = await Promise.all(pattern.map(glob));
2770
2892
  return new Set(results.flat());
2771
2893
  }
2772
2894
  async function getDocumentsForSource(context, src, index) {
@@ -4260,7 +4382,7 @@ class Generator {
4260
4382
  ...this.processors
4261
4383
  ];
4262
4384
  const examplePatterns = this.exampleFolders.map((it) => `${it}/**/*`);
4263
- const exampleFileMatcher = fileMatcher(examplePatterns);
4385
+ const exampleFileMatcher = fileMatcher(examplePatterns, { ignore: [] });
4264
4386
  const templateLoader = createTemplateLoader([]);
4265
4387
  const context = createContext({
4266
4388
  outputFolder: "",
@@ -4333,7 +4455,7 @@ class Generator {
4333
4455
  const templateLoader = createTemplateLoader(templateFolders);
4334
4456
  const context = createContext({
4335
4457
  outputFolder,
4336
- exampleFileMatcher: fileMatcher(examplePatterns),
4458
+ exampleFileMatcher: fileMatcher(examplePatterns, { ignore: [] }),
4337
4459
  templateLoader
4338
4460
  });
4339
4461
  const generatedFiles = [
@@ -4386,5 +4508,5 @@ class Generator {
4386
4508
  }
4387
4509
  }
4388
4510
 
4389
- export { Generator, apiExtractorProcessor, availableProcessors, cookieProcessor, defineSources, extractExamplesProcessor, extractMarkdownProcessor, frontMatterFileReader, htmlRedirectProcessor, isRelease, livereloadProcessor, manifestProcessor, matomoProcessor, motdProcessor, navigationFileReader, partialFileReader, playgroundProcessor, processorRuntimeName, redirectFileProcessor, searchProcessor, selectableVersionProcessor, sourceUrlProcessor, topnavProcessor, versionBannerProcessor, versionProcessor, vueFileReader };
4511
+ export { Generator, apiExtractorProcessor, availableProcessors, cookieProcessor, defineSources, extractExamplesProcessor, extractMarkdownProcessor, frontMatterFileReader, hasPrettyError, htmlRedirectProcessor, isRelease, livereloadProcessor, manifestProcessor, matomoProcessor, motdProcessor, navigationFileReader, partialFileReader, playgroundProcessor, processorRuntimeName, redirectFileProcessor, searchProcessor, selectableVersionProcessor, sourceUrlProcessor, topnavProcessor, versionBannerProcessor, versionProcessor, vueFileReader };
4390
4512
  //# sourceMappingURL=index.mjs.map