@forsakringskassan/docs-generator 3.12.1 → 3.14.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
@@ -3,22 +3,24 @@ 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 { t as ts, 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, n as tinylr, w as watch, o as createInstance, p as fse, q as inter } from './vendor-BesEHnwj.mjs';
6
+ import { t as ts, 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, n as tinylr, w as watch, o as createInstance, p as fse, q as inter } from './vendor-BLfCdre8.mjs';
7
7
  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-C7-7Tads.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 fs__default, { existsSync, readFileSync, copyFileSync } from 'node:fs';
15
+ import { version } from 'vue';
16
+ import { g as generateCode } from './vue3-DbJPWpmQ.mjs';
17
+ import { fileURLToPath } from 'node:url';
14
18
  import util, { promisify, styleText } from 'node:util';
15
19
  import { codeFrameColumns } from '@babel/code-frame';
16
20
  import { parse as parse$1 } from '@babel/parser';
17
21
  import traverseModule from '@babel/traverse';
18
22
  import { parse, compileScript as compileScript$1, compileTemplate } from 'vue/compiler-sfc';
19
23
  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
24
  import { compileAsync, NodePackageImporter } from 'sass';
23
25
  import { t as tsconfigPath } from './tsconfig-path-bG7G_cK8.mjs';
24
26
  import esbuild$1, { build } from 'esbuild';
@@ -50,8 +52,6 @@ import 'module';
50
52
  import 'fs/promises';
51
53
  import 'process';
52
54
  import 'v8';
53
- import 'vue';
54
- import './vue3-DbJPWpmQ.mjs';
55
55
 
56
56
  function toArray$2(value) {
57
57
  return Array.isArray(value) ? value : [value];
@@ -230,6 +230,16 @@ function haveOutput(doc) {
230
230
  return Boolean(fileInfo.outputName);
231
231
  }
232
232
 
233
+ function hasPrettyError(value) {
234
+ if (!value) {
235
+ return false;
236
+ }
237
+ if (typeof value !== "object") {
238
+ return false;
239
+ }
240
+ return "prettyError" in value && typeof value.prettyError === "function";
241
+ }
242
+
233
243
  function interpolate(value, data) {
234
244
  return value.replaceAll(/\{\{([^{}]+)\}\}/g, (match, raw) => {
235
245
  const key = raw.trim();
@@ -630,6 +640,108 @@ function isDocumentPartial(doc) {
630
640
  return doc.kind === "partial";
631
641
  }
632
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
+
633
745
  const md$6 = MarkdownItCallable();
634
746
  md$6.renderer.rules.fence = (tokens, idx, _options, env) => {
635
747
  const { collected, exampleFileMatcher } = env;
@@ -4156,7 +4268,7 @@ class Generator {
4156
4268
  this.scripts = [];
4157
4269
  this.styles = [];
4158
4270
  this.resources = [];
4159
- this.sourceFiles = [];
4271
+ this.sourceFiles = options.sourceFiles ?? [];
4160
4272
  this.markdownOptions = options.markdown;
4161
4273
  const bootstrapUrl = new URL("runtime-bootstrap.mjs", import.meta.url);
4162
4274
  this.compileScript(
@@ -4246,16 +4358,14 @@ class Generator {
4246
4358
  to: dst
4247
4359
  });
4248
4360
  }
4249
- /**
4250
- * Generate a manifest listing all generated documents that will be present
4251
- * in `outputFolder`.
4252
- *
4253
- * Note: this only collects documents from the `generate-docs` stage,
4254
- * potential documents generated at later stages will not be present.
4255
- *
4256
- * @public
4257
- */
4258
- async manifest(sourceFiles) {
4361
+ async manifest(explicitSourceFiles) {
4362
+ if (explicitSourceFiles) {
4363
+ this.sourceFiles = explicitSourceFiles;
4364
+ console.error(
4365
+ "[docs-generator] deprecated: passing in `sourceFiles` as a parameter to `Generator.manifest()` is deprecated, should be passed into the constructor options instead."
4366
+ );
4367
+ }
4368
+ const { sourceFiles } = this;
4259
4369
  const processors = [
4260
4370
  fileReaderProcessor(sourceFiles),
4261
4371
  redirectProcessor(),
@@ -4276,8 +4386,13 @@ class Generator {
4276
4386
  });
4277
4387
  return { pages };
4278
4388
  }
4279
- async build(sourceFiles) {
4280
- this.sourceFiles = sourceFiles;
4389
+ async build(explicitSourceFiles) {
4390
+ if (explicitSourceFiles) {
4391
+ this.sourceFiles = explicitSourceFiles;
4392
+ console.error(
4393
+ "[docs-generator] deprecated: passing in `sourceFiles` as a parameter to `Generator.build()` is deprecated, should be passed into the constructor options instead."
4394
+ );
4395
+ }
4281
4396
  const {
4282
4397
  site,
4283
4398
  outputFolder,
@@ -4286,6 +4401,7 @@ class Generator {
4286
4401
  exampleFolders,
4287
4402
  templateFolders,
4288
4403
  setupPath,
4404
+ sourceFiles,
4289
4405
  markdownOptions
4290
4406
  } = this;
4291
4407
  const examplePatterns = this.exampleFolders.map((it) => `${it}/**/*`);
@@ -4350,7 +4466,7 @@ class Generator {
4350
4466
  outputFolder,
4351
4467
  watch,
4352
4468
  rebuild: (_filePath) => {
4353
- return this.build(sourceFiles);
4469
+ return this.build();
4354
4470
  }
4355
4471
  });
4356
4472
  }
@@ -4382,5 +4498,5 @@ class Generator {
4382
4498
  }
4383
4499
  }
4384
4500
 
4385
- 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 };
4501
+ 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 };
4386
4502
  //# sourceMappingURL=index.mjs.map