@forsakringskassan/docs-generator 2.3.0 → 2.4.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.
@@ -3,7 +3,7 @@
3
3
  var path$1 = require('node:path');
4
4
  var esbuild = require('esbuild');
5
5
  var vue = require('vue');
6
- var vue3 = require('./vue3-BapCBGbN.js');
6
+ var vue3 = require('./vue3-CSK73bce.js');
7
7
  var path = require('node:path/posix');
8
8
  require('@vue/compiler-sfc');
9
9
  require('./vendor-BJuS1z3U.js');
package/dist/index.d.ts CHANGED
@@ -165,7 +165,9 @@ declare class Generator_2 {
165
165
  private resources;
166
166
  private sourceFiles;
167
167
  constructor(options: GeneratorOptions);
168
- compileScript(name: string, src: string | URL, options?: Partial<CompileOptions>): void;
168
+ compileScript(name: string, src: string | URL, options?: Partial<CompileOptions>, buildOptions?: {
169
+ define?: Record<string, string>;
170
+ }): void;
169
171
  compileStyle(name: string, src: string | URL, options?: Partial<CompileOptions>): void;
170
172
  /**
171
173
  * @param dst - Destination directory relative to asset folder.
@@ -457,6 +459,10 @@ export declare interface ProcessorRuntime {
457
459
  src: string;
458
460
  /** Bundle name (in dist/processors) folder (default: derived from processor name) */
459
461
  name?: string;
462
+ /** Build options (passed to compileScript) */
463
+ buildOptions?: {
464
+ define?: Record<string, string>;
465
+ };
460
466
  }
461
467
 
462
468
  /* Excluded from this release type: processorRuntimeName */
package/dist/index.js CHANGED
@@ -11,11 +11,11 @@ require('node:crypto');
11
11
  var util = require('node:util');
12
12
  var fs$1 = require('node:fs');
13
13
  var vue = require('vue');
14
- var vue3 = require('./vue3-BapCBGbN.js');
14
+ var vue3 = require('./vue3-CSK73bce.js');
15
15
  var vueDocgenApi = require('vue-docgen-api');
16
16
  var sass = require('sass');
17
17
  var node_url = require('node:url');
18
- var esbuild = require('esbuild');
18
+ var esbuild$1 = require('esbuild');
19
19
  var nunjucks = require('nunjucks');
20
20
  var express = require('express');
21
21
  require('@vue/compiler-sfc');
@@ -612,16 +612,21 @@ function generateVueExample(options) {
612
612
  };
613
613
  }
614
614
  function generateStaticExample(options) {
615
- const { source, language, tags } = options;
615
+ const { filename, source, language, tags } = options;
616
+ const slug = getExampleName(filename);
617
+ const fingerprint = createMarkdownRenderer.getFingerprint(source);
618
+ const asset = `${slug}-${fingerprint}.${language}`;
616
619
  const runtimeLanguages = ["html"];
620
+ const runtime = runtimeLanguages.includes(language);
617
621
  return {
618
622
  source,
619
623
  language: options.language,
620
624
  comments: [],
621
625
  tags,
622
626
  markup: source,
623
- output: null,
624
- runtime: runtimeLanguages.includes(language)
627
+ output: runtime ? asset : null,
628
+ runtime,
629
+ task: null
625
630
  };
626
631
  }
627
632
 
@@ -1038,7 +1043,7 @@ async function navigationFileReader(filePath, basePath) {
1038
1043
  return [doc];
1039
1044
  }
1040
1045
 
1041
- function resolveScssImport(filePath) {
1046
+ function resolveScssImport(filePath, throwError = true) {
1042
1047
  const { dir, base } = path$1.parse(filePath);
1043
1048
  const search = [`${base}.css`, `${base}.scss`, `_${base}.scss`, `${base}`];
1044
1049
  for (const variant of search) {
@@ -1052,20 +1057,24 @@ function resolveScssImport(filePath) {
1052
1057
  }
1053
1058
  }
1054
1059
  }
1055
- throw new Error(`Failed to resolve "${filePath}"`);
1060
+ if (throwError) {
1061
+ throw new Error(`Failed to resolve "${filePath}"`);
1062
+ }
1063
+ return null;
1056
1064
  }
1057
- const tildeImporter = {
1065
+ const WEBPACK_NODE_MODULE_PREFIX = "~";
1066
+ const moduleImporter = {
1058
1067
  canonicalize(url) {
1059
- const indexOfTilde = url.indexOf("~");
1060
- if (indexOfTilde >= 0) {
1061
- return resolveScssImport(url.slice(indexOfTilde + 1));
1068
+ const indexOfPrefix = url.indexOf(WEBPACK_NODE_MODULE_PREFIX);
1069
+ if (indexOfPrefix >= 0) {
1070
+ return resolveScssImport(url.slice(indexOfPrefix + 1));
1062
1071
  }
1063
1072
  if (url.startsWith("file://")) {
1064
1073
  const path$1 = node_url.fileURLToPath(url);
1065
1074
  const relative = path.isAbsolute(path$1) ? path.relative(__dirname, path$1) : path$1;
1066
1075
  return resolveScssImport(relative.replace(/\\/g, "/"));
1067
1076
  }
1068
- return null;
1077
+ return resolveScssImport(url, false);
1069
1078
  },
1070
1079
  async load(url) {
1071
1080
  const filepath = node_url.fileURLToPath(url);
@@ -1081,7 +1090,7 @@ const tildeImporter = {
1081
1090
  async function compileSassString(dst, style) {
1082
1091
  const result = await sass.compileStringAsync(style, {
1083
1092
  style: "expanded",
1084
- importers: [new sass.NodePackageImporter(), tildeImporter]
1093
+ importers: [new sass.NodePackageImporter(), moduleImporter]
1085
1094
  });
1086
1095
  await fs.mkdir(path.dirname(dst), { recursive: true });
1087
1096
  await fs.writeFile(dst, result.css, "utf-8");
@@ -1155,12 +1164,23 @@ function cssAssetProcessor(assetFolder, assets) {
1155
1164
  };
1156
1165
  }
1157
1166
 
1158
- async function compileScript(assetFolder, name, src, options) {
1167
+ function esbuild(options) {
1168
+ return esbuild$1.build(options);
1169
+ }
1170
+
1171
+ async function compileScript(options) {
1172
+ const {
1173
+ assetFolder,
1174
+ name,
1175
+ src,
1176
+ buildOptions,
1177
+ fs: fs$1 = fs
1178
+ } = options;
1159
1179
  const iconLib = process.env.DOCS_ICON_LIB ?? "@fkui/icon-lib-default";
1160
1180
  try {
1161
1181
  const entryPoints = [src instanceof URL ? node_url.fileURLToPath(src) : src];
1162
1182
  const outfile = path.join("temp", `asset-${name}.js`);
1163
- await esbuild.build({
1183
+ await esbuild({
1164
1184
  entryPoints,
1165
1185
  outfile,
1166
1186
  bundle: true,
@@ -1168,19 +1188,20 @@ async function compileScript(assetFolder, name, src, options) {
1168
1188
  platform: "browser",
1169
1189
  external: ["vue", "@fkui/vue"],
1170
1190
  tsconfig: path.join(__dirname, "../tsconfig-examples.json"),
1191
+ ...buildOptions,
1171
1192
  define: {
1172
- "process.env.DOCS_ICON_LIB": JSON.stringify(iconLib)
1173
- },
1174
- ...options
1193
+ "process.env.DOCS_ICON_LIB": JSON.stringify(iconLib),
1194
+ ...buildOptions?.define
1195
+ }
1175
1196
  });
1176
- const content = await fs.readFile(outfile, "utf-8");
1197
+ const content = await fs$1.readFile(outfile, "utf-8");
1177
1198
  const fingerprint = createMarkdownRenderer.getFingerprint(content);
1178
1199
  const integrity = getIntegrity(content);
1179
1200
  const filename = `${name}-${fingerprint}.js`;
1180
1201
  const dst = path.join(assetFolder, filename);
1181
- await fs.mkdir(path.dirname(dst), { recursive: true });
1182
- await fs.rename(outfile, dst);
1183
- const stat = await fs.stat(dst);
1202
+ await fs$1.mkdir(path.dirname(dst), { recursive: true });
1203
+ await fs$1.rename(outfile, dst);
1204
+ const stat = await fs$1.stat(dst);
1184
1205
  return {
1185
1206
  name,
1186
1207
  filename,
@@ -1210,11 +1231,12 @@ function jsAssetProcessor(assetFolder, assets) {
1210
1231
  const head = context.getTemplateData("injectHead") ?? [];
1211
1232
  const body = context.getTemplateData("injectBody") ?? [];
1212
1233
  for (const asset of toSorted(assets, byPriority)) {
1213
- const info = await compileScript(
1234
+ const info = await compileScript({
1214
1235
  assetFolder,
1215
- asset.name,
1216
- asset.src
1217
- );
1236
+ name: asset.name,
1237
+ src: asset.src,
1238
+ buildOptions: asset.buildOptions
1239
+ });
1218
1240
  const attrs = serializeAttrs(asset.options.attributes);
1219
1241
  const inject = { ...info, attrs: Array.from(attrs).join(" ") };
1220
1242
  assetInfo[asset.name] = info;
@@ -1274,10 +1296,17 @@ function compileProcessorRuntime(generator, distDir, processors) {
1274
1296
  const name = processorRuntimeName(processor, entry);
1275
1297
  const bundled = new URL(`${name}.js`, distDir);
1276
1298
  const scriptPath = fs$1.existsSync(bundled) ? bundled : entry.src;
1277
- generator.compileScript(assetName, scriptPath, {
1278
- appendTo: "body",
1279
- priority: 50
1280
- });
1299
+ generator.compileScript(
1300
+ assetName,
1301
+ scriptPath,
1302
+ {
1303
+ appendTo: "body",
1304
+ priority: 50
1305
+ },
1306
+ {
1307
+ ...entry.buildOptions
1308
+ }
1309
+ );
1281
1310
  }
1282
1311
  }
1283
1312
  }
@@ -1756,7 +1785,9 @@ async function render(doc, docs, nav, vendors, options) {
1756
1785
  });
1757
1786
  if (example.output) {
1758
1787
  const { dir, name } = path.parse(example.output);
1759
- generatedExamples.push(example.task);
1788
+ if (example.task) {
1789
+ generatedExamples.push(example.task);
1790
+ }
1760
1791
  generatedStandalone.push({
1761
1792
  outputFile: path.join(dir, `${name}.html`),
1762
1793
  content: example.markup
@@ -1959,7 +1990,7 @@ async function compileVendor(assetFolder, vendor, options) {
1959
1990
  const source = getAssetSource(vendor, customRequire.toString());
1960
1991
  const tsconfig = path.resolve(__dirname, "../tsconfig-examples.json");
1961
1992
  await fs.writeFile(tmpfile, source, "utf-8");
1962
- await esbuild.build({
1993
+ await esbuild$1.build({
1963
1994
  entryPoints: [tmpfile],
1964
1995
  outfile,
1965
1996
  bundle: true,
@@ -2306,7 +2337,7 @@ class Generator {
2306
2337
  priority: 100
2307
2338
  });
2308
2339
  }
2309
- compileScript(name, src, options) {
2340
+ compileScript(name, src, options, buildOptions) {
2310
2341
  this.scripts.push({
2311
2342
  name,
2312
2343
  src,
@@ -2315,6 +2346,9 @@ class Generator {
2315
2346
  attributes: {},
2316
2347
  priority: 0,
2317
2348
  ...options
2349
+ },
2350
+ buildOptions: {
2351
+ ...buildOptions
2318
2352
  }
2319
2353
  });
2320
2354
  }
@@ -127,9 +127,11 @@ export declare interface ExampleStaticResult {
127
127
  /** HTML markup to inject into document */
128
128
  markup: string;
129
129
  /** asset filename */
130
- output: null;
130
+ output: string | null;
131
131
  /** enables/disables running example live in the browser */
132
132
  runtime: boolean;
133
+ /** task data for compiler */
134
+ task: null;
133
135
  }
134
136
 
135
137
  /**
@@ -12776,6 +12776,9 @@ function generateCode(options) {
12776
12776
  "export default",
12777
12777
  "const exampleComponent = "
12778
12778
  );
12779
+ } else {
12780
+ sourcecode += `const exampleComponent = {};
12781
+ `;
12779
12782
  }
12780
12783
  if (descriptor.template) {
12781
12784
  const js = require$$0.compileTemplate({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forsakringskassan/docs-generator",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Documentation generator",
5
5
  "keywords": [
6
6
  "documentation"
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "livereload-js": "4.0.2",
57
57
  "nunjucks": "3.2.4",
58
- "piscina": "4.6.1",
58
+ "piscina": "4.7.0",
59
59
  "vue-docgen-api": "4.79.2"
60
60
  },
61
61
  "peerDependencies": {