@forsakringskassan/docs-generator 1.27.0 → 1.28.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/compile-example.js +8 -8
- package/dist/{create-markdown-renderer--V6N9Daq.js → create-markdown-renderer-CPrI2LLQ.js} +17 -2
- package/dist/{generator.d.ts → index.d.ts} +45 -4
- package/dist/{generator.js → index.js} +615 -497
- package/dist/markdown.js +7 -7
- package/dist/style/core.css +3 -6
- package/dist/style/index.css +30 -8
- package/dist/style/site.css +27 -2
- package/dist/{vendor-Dmnzl4fQ.js → vendor-uab7h6x-.js} +19121 -19121
- package/dist/{vue2-DYKDshbg.js → vue2-CBDrnmVO.js} +1 -1
- package/dist/{vue3-CEA3zw16.js → vue3-xJIC7Aol.js} +2 -2
- package/package.json +3 -3
- package/templates/partials/version.njk.html +15 -0
- package/templates/partials/version.html +0 -3
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fs$1 = require('node:fs');
|
|
4
3
|
var fs = require('node:fs/promises');
|
|
5
4
|
var path = require('node:path');
|
|
6
|
-
var vendor = require('./vendor-
|
|
5
|
+
var vendor = require('./vendor-uab7h6x-.js');
|
|
6
|
+
var createMarkdownRenderer = require('./create-markdown-renderer-CPrI2LLQ.js');
|
|
7
7
|
var require$$1 = require('crypto');
|
|
8
8
|
require('node:crypto');
|
|
9
|
+
var vueDocgenApi = require('vue-docgen-api');
|
|
9
10
|
var path$1 = require('node:path/posix');
|
|
11
|
+
var fs$1 = require('node:fs');
|
|
10
12
|
var sass = require('sass');
|
|
11
13
|
var node_url = require('node:url');
|
|
12
|
-
var createMarkdownRenderer = require('./create-markdown-renderer--V6N9Daq.js');
|
|
13
14
|
var esbuild = require('esbuild');
|
|
14
|
-
var vueDocgenApi = require('vue-docgen-api');
|
|
15
15
|
var node_util = require('node:util');
|
|
16
16
|
var nunjucks = require('nunjucks');
|
|
17
17
|
var vue = require('vue');
|
|
18
|
-
var vue2 = require('./vue2-
|
|
19
|
-
var vue3 = require('./vue3-
|
|
18
|
+
var vue2 = require('./vue2-CBDrnmVO.js');
|
|
19
|
+
var vue3 = require('./vue3-xJIC7Aol.js');
|
|
20
20
|
var express = require('express');
|
|
21
|
-
require('
|
|
22
|
-
require('constants');
|
|
23
|
-
require('stream');
|
|
24
|
-
require('util');
|
|
25
|
-
require('assert');
|
|
21
|
+
var childProcess = require('node:child_process');
|
|
26
22
|
require('path');
|
|
27
23
|
require('url');
|
|
24
|
+
require('fs');
|
|
28
25
|
require('fs/promises');
|
|
29
26
|
require('events');
|
|
27
|
+
require('stream');
|
|
30
28
|
require('string_decoder');
|
|
29
|
+
require('constants');
|
|
30
|
+
require('util');
|
|
31
|
+
require('assert');
|
|
31
32
|
require('readline');
|
|
32
33
|
require('child_process');
|
|
33
34
|
require('node:buffer');
|
|
34
|
-
require('node:child_process');
|
|
35
35
|
require('node:process');
|
|
36
36
|
require('node:os');
|
|
37
37
|
require('node:timers/promises');
|
|
@@ -46,6 +46,10 @@ require('tls');
|
|
|
46
46
|
require('tty');
|
|
47
47
|
require('querystring');
|
|
48
48
|
|
|
49
|
+
function defineSources(sources) {
|
|
50
|
+
return sources;
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
function formatSize(value) {
|
|
50
54
|
const suffices = ["kB", "MB"];
|
|
51
55
|
if (value < 1e3) {
|
|
@@ -106,6 +110,13 @@ function haveOutput(doc) {
|
|
|
106
110
|
return Boolean(fileInfo.outputName);
|
|
107
111
|
}
|
|
108
112
|
|
|
113
|
+
function interpolate(value, data) {
|
|
114
|
+
return value.replace(/{{([^}]+)}}/g, (match, raw) => {
|
|
115
|
+
const key = raw.trim();
|
|
116
|
+
return data[key] ?? match;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
109
120
|
function parseImport(raw) {
|
|
110
121
|
const comments = [];
|
|
111
122
|
const stripped = raw.replace(/<!--.*?-->/gms, (match) => {
|
|
@@ -158,214 +169,7 @@ function slugify(value) {
|
|
|
158
169
|
return value.toLowerCase().replace(/\//g, "--").replace(/[^a-z]+/g, "-").replace(/(^-+|-+$)/, "");
|
|
159
170
|
}
|
|
160
171
|
|
|
161
|
-
function resolveScssImport(filePath) {
|
|
162
|
-
const { dir, base } = path$1.parse(filePath);
|
|
163
|
-
const search = [`${base}.css`, `${base}.scss`, `_${base}.scss`, `${base}`];
|
|
164
|
-
for (const variant of search) {
|
|
165
|
-
try {
|
|
166
|
-
const moduleName = path$1.join(dir, variant);
|
|
167
|
-
const resolved = require.resolve(moduleName);
|
|
168
|
-
return node_url.pathToFileURL(resolved);
|
|
169
|
-
} catch (err) {
|
|
170
|
-
if (err.code !== "MODULE_NOT_FOUND") {
|
|
171
|
-
throw err;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
throw new Error(`Failed to resolve "${filePath}"`);
|
|
176
|
-
}
|
|
177
|
-
const tildeImporter = {
|
|
178
|
-
canonicalize(url) {
|
|
179
|
-
const indexOfTilde = url.indexOf("~");
|
|
180
|
-
if (indexOfTilde >= 0) {
|
|
181
|
-
return resolveScssImport(url.slice(indexOfTilde + 1));
|
|
182
|
-
}
|
|
183
|
-
if (url.startsWith("file://")) {
|
|
184
|
-
const path$1 = node_url.fileURLToPath(url);
|
|
185
|
-
const relative = path.isAbsolute(path$1) ? path.relative(__dirname, path$1) : path$1;
|
|
186
|
-
return resolveScssImport(relative.replace(/\\/g, "/"));
|
|
187
|
-
}
|
|
188
|
-
return null;
|
|
189
|
-
},
|
|
190
|
-
async load(url) {
|
|
191
|
-
const filepath = node_url.fileURLToPath(url);
|
|
192
|
-
const parsed = path.parse(filepath);
|
|
193
|
-
const contents = await fs.readFile(filepath, "utf-8");
|
|
194
|
-
return {
|
|
195
|
-
contents,
|
|
196
|
-
syntax: parsed.ext.slice(1) === "scss" ? "scss" : "css"
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
async function compileSassString(dst, style) {
|
|
202
|
-
const result = await sass.compileStringAsync(style, {
|
|
203
|
-
style: "expanded",
|
|
204
|
-
importers: [tildeImporter]
|
|
205
|
-
});
|
|
206
|
-
await fs.mkdir(path.dirname(dst), { recursive: true });
|
|
207
|
-
await fs.writeFile(dst, result.css, "utf-8");
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async function compileStyle(assetFolder, name, src) {
|
|
211
|
-
try {
|
|
212
|
-
const outfile = path$1.join("temp", `asset-${name}.css`);
|
|
213
|
-
const source = await fs.readFile(src, "utf-8");
|
|
214
|
-
await compileSassString(outfile, source);
|
|
215
|
-
const content = await fs.readFile(outfile, "utf-8");
|
|
216
|
-
const fingerprint = createMarkdownRenderer.getFingerprint(content);
|
|
217
|
-
const integrity = getIntegrity(content);
|
|
218
|
-
const filename = `${name}-${fingerprint}.css`;
|
|
219
|
-
const dst = path$1.join(assetFolder, filename);
|
|
220
|
-
await fs.rename(outfile, dst);
|
|
221
|
-
const stat = await fs.stat(dst);
|
|
222
|
-
return {
|
|
223
|
-
name,
|
|
224
|
-
filename,
|
|
225
|
-
publicPath: `./assets/${filename}`,
|
|
226
|
-
integrity,
|
|
227
|
-
size: stat.size,
|
|
228
|
-
type: "css"
|
|
229
|
-
};
|
|
230
|
-
} catch (err) {
|
|
231
|
-
console.error(err);
|
|
232
|
-
throw new Error(`Failed to compile style "${name}"`);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function cssAssetProcessor(assetFolder, assets) {
|
|
237
|
-
return {
|
|
238
|
-
name: "css-asset-processor",
|
|
239
|
-
after: "assets",
|
|
240
|
-
async handler(context) {
|
|
241
|
-
const assetInfo = context.getTemplateData("assets") ?? {};
|
|
242
|
-
const head = context.getTemplateData("injectHead") ?? [];
|
|
243
|
-
const body = context.getTemplateData("injectBody") ?? [];
|
|
244
|
-
for (const asset of assets) {
|
|
245
|
-
const info = await compileStyle(
|
|
246
|
-
assetFolder,
|
|
247
|
-
asset.name,
|
|
248
|
-
asset.src
|
|
249
|
-
);
|
|
250
|
-
const attrs = serializeAttrs(asset.options.attributes);
|
|
251
|
-
const inject = { ...info, attrs: Array.from(attrs).join(" ") };
|
|
252
|
-
assetInfo[asset.name] = info;
|
|
253
|
-
switch (asset.options.appendTo) {
|
|
254
|
-
case "none":
|
|
255
|
-
break;
|
|
256
|
-
case "head":
|
|
257
|
-
head.push(inject);
|
|
258
|
-
break;
|
|
259
|
-
case "body":
|
|
260
|
-
body.push(inject);
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
context.setTemplateData("injectHead", head);
|
|
264
|
-
context.setTemplateData("injectBody", body);
|
|
265
|
-
context.log(info.filename, formatSize(info.size));
|
|
266
|
-
}
|
|
267
|
-
context.setTemplateData("assets", assetInfo);
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
172
|
function toArray$3(value) {
|
|
273
|
-
if (Array.isArray(value)) {
|
|
274
|
-
return value;
|
|
275
|
-
} else {
|
|
276
|
-
return [value];
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
async function compileScript(assetFolder, name, src, options) {
|
|
280
|
-
const iconLib = process.env.DOCS_ICON_LIB ?? "@fkui/icon-lib-default";
|
|
281
|
-
try {
|
|
282
|
-
const outfile = path.join("temp", `asset-${name}.js`);
|
|
283
|
-
await esbuild.build({
|
|
284
|
-
entryPoints: toArray$3(src),
|
|
285
|
-
outfile,
|
|
286
|
-
bundle: true,
|
|
287
|
-
format: "iife",
|
|
288
|
-
platform: "browser",
|
|
289
|
-
external: ["vue", "@fkui/vue"],
|
|
290
|
-
tsconfig: path.join(__dirname, "../tsconfig-examples.json"),
|
|
291
|
-
define: {
|
|
292
|
-
"process.env.DOCS_ICON_LIB": JSON.stringify(iconLib)
|
|
293
|
-
},
|
|
294
|
-
...options
|
|
295
|
-
});
|
|
296
|
-
const content = await fs.readFile(outfile, "utf-8");
|
|
297
|
-
const fingerprint = createMarkdownRenderer.getFingerprint(content);
|
|
298
|
-
const integrity = getIntegrity(content);
|
|
299
|
-
const filename = `${name}-${fingerprint}.js`;
|
|
300
|
-
const dst = path.join(assetFolder, filename);
|
|
301
|
-
await fs.rename(outfile, dst);
|
|
302
|
-
const stat = await fs.stat(dst);
|
|
303
|
-
return {
|
|
304
|
-
name,
|
|
305
|
-
filename,
|
|
306
|
-
publicPath: `./assets/${filename}`,
|
|
307
|
-
integrity,
|
|
308
|
-
size: stat.size,
|
|
309
|
-
type: "js"
|
|
310
|
-
};
|
|
311
|
-
} catch {
|
|
312
|
-
throw new Error(`Failed to compile script "${name}"`);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function jsAssetProcessor(assetFolder, assets) {
|
|
317
|
-
return {
|
|
318
|
-
name: "js-asset-processor",
|
|
319
|
-
after: "assets",
|
|
320
|
-
async handler(context) {
|
|
321
|
-
const assetInfo = context.getTemplateData("assets") ?? {};
|
|
322
|
-
const head = context.getTemplateData("injectHead") ?? [];
|
|
323
|
-
const body = context.getTemplateData("injectBody") ?? [];
|
|
324
|
-
for (const asset of assets) {
|
|
325
|
-
const info = await compileScript(
|
|
326
|
-
assetFolder,
|
|
327
|
-
asset.name,
|
|
328
|
-
asset.src
|
|
329
|
-
);
|
|
330
|
-
const attrs = serializeAttrs(asset.options.attributes);
|
|
331
|
-
const inject = { ...info, attrs: Array.from(attrs).join(" ") };
|
|
332
|
-
assetInfo[asset.name] = info;
|
|
333
|
-
switch (asset.options.appendTo) {
|
|
334
|
-
case "none":
|
|
335
|
-
break;
|
|
336
|
-
case "head":
|
|
337
|
-
head.push(inject);
|
|
338
|
-
break;
|
|
339
|
-
case "body":
|
|
340
|
-
body.push(inject);
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
context.setTemplateData("injectHead", head);
|
|
344
|
-
context.setTemplateData("injectBody", body);
|
|
345
|
-
context.log(info.filename, formatSize(info.size));
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function staticResourcesProcessor(assetFolder, resources) {
|
|
352
|
-
return {
|
|
353
|
-
name: "static-resources-processor",
|
|
354
|
-
after: "render",
|
|
355
|
-
async handler(context) {
|
|
356
|
-
for (const resource of [...resources, ...context.resources]) {
|
|
357
|
-
const src = resource.from;
|
|
358
|
-
const dst = path$1.join(assetFolder, resource.to);
|
|
359
|
-
await fs.cp(src, dst, {
|
|
360
|
-
recursive: true
|
|
361
|
-
});
|
|
362
|
-
context.log(src, "->", dst);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
function toArray$2(value) {
|
|
369
173
|
return Array.isArray(value) ? value : [value];
|
|
370
174
|
}
|
|
371
175
|
function isIndexPage(parsed) {
|
|
@@ -401,7 +205,7 @@ function getBadge(attrs) {
|
|
|
401
205
|
}
|
|
402
206
|
function getComponentAlias(attrs) {
|
|
403
207
|
if (attrs.component) {
|
|
404
|
-
return toArray$
|
|
208
|
+
return toArray$3(attrs.component).map((it) => `component:${it}`);
|
|
405
209
|
} else {
|
|
406
210
|
return [];
|
|
407
211
|
}
|
|
@@ -426,7 +230,7 @@ function parseFile$1(filePath, basePath, content) {
|
|
|
426
230
|
layout: attributes.layout,
|
|
427
231
|
status: attributes.status,
|
|
428
232
|
badge: getBadge(attributes),
|
|
429
|
-
component: attributes.component ? toArray$
|
|
233
|
+
component: attributes.component ? toArray$3(attributes.component) : void 0,
|
|
430
234
|
sortorder: attributes.sortorder ?? Infinity
|
|
431
235
|
},
|
|
432
236
|
body: blocks.body,
|
|
@@ -698,25 +502,232 @@ async function navigationFileReader(filePath, basePath) {
|
|
|
698
502
|
return [doc];
|
|
699
503
|
}
|
|
700
504
|
|
|
701
|
-
function
|
|
702
|
-
const
|
|
703
|
-
const
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
505
|
+
function resolveScssImport(filePath) {
|
|
506
|
+
const { dir, base } = path$1.parse(filePath);
|
|
507
|
+
const search = [`${base}.css`, `${base}.scss`, `_${base}.scss`, `${base}`];
|
|
508
|
+
for (const variant of search) {
|
|
509
|
+
try {
|
|
510
|
+
const moduleName = path$1.join(dir, variant);
|
|
511
|
+
const resolved = require.resolve(moduleName);
|
|
512
|
+
return node_url.pathToFileURL(resolved);
|
|
513
|
+
} catch (err) {
|
|
514
|
+
if (err.code !== "MODULE_NOT_FOUND") {
|
|
515
|
+
throw err;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
712
518
|
}
|
|
519
|
+
throw new Error(`Failed to resolve "${filePath}"`);
|
|
713
520
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
521
|
+
const tildeImporter = {
|
|
522
|
+
canonicalize(url) {
|
|
523
|
+
const indexOfTilde = url.indexOf("~");
|
|
524
|
+
if (indexOfTilde >= 0) {
|
|
525
|
+
return resolveScssImport(url.slice(indexOfTilde + 1));
|
|
526
|
+
}
|
|
527
|
+
if (url.startsWith("file://")) {
|
|
528
|
+
const path$1 = node_url.fileURLToPath(url);
|
|
529
|
+
const relative = path.isAbsolute(path$1) ? path.relative(__dirname, path$1) : path$1;
|
|
530
|
+
return resolveScssImport(relative.replace(/\\/g, "/"));
|
|
531
|
+
}
|
|
532
|
+
return null;
|
|
533
|
+
},
|
|
534
|
+
async load(url) {
|
|
535
|
+
const filepath = node_url.fileURLToPath(url);
|
|
536
|
+
const parsed = path.parse(filepath);
|
|
537
|
+
const contents = await fs.readFile(filepath, "utf-8");
|
|
538
|
+
return {
|
|
539
|
+
contents,
|
|
540
|
+
syntax: parsed.ext.slice(1) === "scss" ? "scss" : "css"
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
async function compileSassString(dst, style) {
|
|
546
|
+
const result = await sass.compileStringAsync(style, {
|
|
547
|
+
style: "expanded",
|
|
548
|
+
importers: [tildeImporter]
|
|
549
|
+
});
|
|
550
|
+
await fs.mkdir(path.dirname(dst), { recursive: true });
|
|
551
|
+
await fs.writeFile(dst, result.css, "utf-8");
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
async function compileStyle(assetFolder, name, src) {
|
|
555
|
+
try {
|
|
556
|
+
const outfile = path$1.join("temp", `asset-${name}.css`);
|
|
557
|
+
const source = await fs.readFile(src, "utf-8");
|
|
558
|
+
await compileSassString(outfile, source);
|
|
559
|
+
const content = await fs.readFile(outfile, "utf-8");
|
|
560
|
+
const fingerprint = createMarkdownRenderer.getFingerprint(content);
|
|
561
|
+
const integrity = getIntegrity(content);
|
|
562
|
+
const filename = `${name}-${fingerprint}.css`;
|
|
563
|
+
const dst = path$1.join(assetFolder, filename);
|
|
564
|
+
await fs.rename(outfile, dst);
|
|
565
|
+
const stat = await fs.stat(dst);
|
|
566
|
+
return {
|
|
567
|
+
name,
|
|
568
|
+
filename,
|
|
569
|
+
publicPath: `./assets/${filename}`,
|
|
570
|
+
integrity,
|
|
571
|
+
size: stat.size,
|
|
572
|
+
type: "css"
|
|
573
|
+
};
|
|
574
|
+
} catch (err) {
|
|
575
|
+
console.error(err);
|
|
576
|
+
throw new Error(`Failed to compile style "${name}"`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function cssAssetProcessor(assetFolder, assets) {
|
|
581
|
+
return {
|
|
582
|
+
name: "css-asset-processor",
|
|
583
|
+
after: "assets",
|
|
584
|
+
async handler(context) {
|
|
585
|
+
const assetInfo = context.getTemplateData("assets") ?? {};
|
|
586
|
+
const head = context.getTemplateData("injectHead") ?? [];
|
|
587
|
+
const body = context.getTemplateData("injectBody") ?? [];
|
|
588
|
+
for (const asset of assets) {
|
|
589
|
+
const info = await compileStyle(
|
|
590
|
+
assetFolder,
|
|
591
|
+
asset.name,
|
|
592
|
+
asset.src
|
|
593
|
+
);
|
|
594
|
+
const attrs = serializeAttrs(asset.options.attributes);
|
|
595
|
+
const inject = { ...info, attrs: Array.from(attrs).join(" ") };
|
|
596
|
+
assetInfo[asset.name] = info;
|
|
597
|
+
switch (asset.options.appendTo) {
|
|
598
|
+
case "none":
|
|
599
|
+
break;
|
|
600
|
+
case "head":
|
|
601
|
+
head.push(inject);
|
|
602
|
+
break;
|
|
603
|
+
case "body":
|
|
604
|
+
body.push(inject);
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
context.setTemplateData("injectHead", head);
|
|
608
|
+
context.setTemplateData("injectBody", body);
|
|
609
|
+
context.log(info.filename, formatSize(info.size));
|
|
610
|
+
}
|
|
611
|
+
context.setTemplateData("assets", assetInfo);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function toArray$2(value) {
|
|
617
|
+
if (Array.isArray(value)) {
|
|
618
|
+
return value;
|
|
619
|
+
} else {
|
|
620
|
+
return [value];
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
async function compileScript(assetFolder, name, src, options) {
|
|
624
|
+
const iconLib = process.env.DOCS_ICON_LIB ?? "@fkui/icon-lib-default";
|
|
625
|
+
try {
|
|
626
|
+
const outfile = path.join("temp", `asset-${name}.js`);
|
|
627
|
+
await esbuild.build({
|
|
628
|
+
entryPoints: toArray$2(src),
|
|
629
|
+
outfile,
|
|
630
|
+
bundle: true,
|
|
631
|
+
format: "iife",
|
|
632
|
+
platform: "browser",
|
|
633
|
+
external: ["vue", "@fkui/vue"],
|
|
634
|
+
tsconfig: path.join(__dirname, "../tsconfig-examples.json"),
|
|
635
|
+
define: {
|
|
636
|
+
"process.env.DOCS_ICON_LIB": JSON.stringify(iconLib)
|
|
637
|
+
},
|
|
638
|
+
...options
|
|
639
|
+
});
|
|
640
|
+
const content = await fs.readFile(outfile, "utf-8");
|
|
641
|
+
const fingerprint = createMarkdownRenderer.getFingerprint(content);
|
|
642
|
+
const integrity = getIntegrity(content);
|
|
643
|
+
const filename = `${name}-${fingerprint}.js`;
|
|
644
|
+
const dst = path.join(assetFolder, filename);
|
|
645
|
+
await fs.rename(outfile, dst);
|
|
646
|
+
const stat = await fs.stat(dst);
|
|
647
|
+
return {
|
|
648
|
+
name,
|
|
649
|
+
filename,
|
|
650
|
+
publicPath: `./assets/${filename}`,
|
|
651
|
+
integrity,
|
|
652
|
+
size: stat.size,
|
|
653
|
+
type: "js"
|
|
654
|
+
};
|
|
655
|
+
} catch {
|
|
656
|
+
throw new Error(`Failed to compile script "${name}"`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function jsAssetProcessor(assetFolder, assets) {
|
|
661
|
+
return {
|
|
662
|
+
name: "js-asset-processor",
|
|
663
|
+
after: "assets",
|
|
664
|
+
async handler(context) {
|
|
665
|
+
const assetInfo = context.getTemplateData("assets") ?? {};
|
|
666
|
+
const head = context.getTemplateData("injectHead") ?? [];
|
|
667
|
+
const body = context.getTemplateData("injectBody") ?? [];
|
|
668
|
+
for (const asset of assets) {
|
|
669
|
+
const info = await compileScript(
|
|
670
|
+
assetFolder,
|
|
671
|
+
asset.name,
|
|
672
|
+
asset.src
|
|
673
|
+
);
|
|
674
|
+
const attrs = serializeAttrs(asset.options.attributes);
|
|
675
|
+
const inject = { ...info, attrs: Array.from(attrs).join(" ") };
|
|
676
|
+
assetInfo[asset.name] = info;
|
|
677
|
+
switch (asset.options.appendTo) {
|
|
678
|
+
case "none":
|
|
679
|
+
break;
|
|
680
|
+
case "head":
|
|
681
|
+
head.push(inject);
|
|
682
|
+
break;
|
|
683
|
+
case "body":
|
|
684
|
+
body.push(inject);
|
|
685
|
+
break;
|
|
686
|
+
}
|
|
687
|
+
context.setTemplateData("injectHead", head);
|
|
688
|
+
context.setTemplateData("injectBody", body);
|
|
689
|
+
context.log(info.filename, formatSize(info.size));
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function staticResourcesProcessor(assetFolder, resources) {
|
|
696
|
+
return {
|
|
697
|
+
name: "static-resources-processor",
|
|
698
|
+
after: "render",
|
|
699
|
+
async handler(context) {
|
|
700
|
+
for (const resource of [...resources, ...context.resources]) {
|
|
701
|
+
const src = resource.from;
|
|
702
|
+
const dst = path$1.join(assetFolder, resource.to);
|
|
703
|
+
await fs.cp(src, dst, {
|
|
704
|
+
recursive: true
|
|
705
|
+
});
|
|
706
|
+
context.log(src, "->", dst);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function getExampleImport(searchDirs, filename) {
|
|
713
|
+
const pattern = searchDirs.map((dir) => `${dir}/**/${filename}`);
|
|
714
|
+
const matches = vendor.globSync(pattern);
|
|
715
|
+
if (matches.length === 0) {
|
|
716
|
+
const message = `No files matched import "${filename}"`;
|
|
717
|
+
throw new Error(message);
|
|
718
|
+
} else if (matches.length > 1) {
|
|
719
|
+
const message = `Multiple files matched import "${filename}"`;
|
|
720
|
+
throw new Error(message);
|
|
721
|
+
} else {
|
|
722
|
+
return createMarkdownRenderer.normalizePath(matches[0]);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function getExampleName(filename) {
|
|
727
|
+
return path.parse(filename).name;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
const vueMajor = parseInt(vue.version.split(".", 2)[0], 10);
|
|
720
731
|
const vueGenerator = {
|
|
721
732
|
[2]: vue2.generateCode,
|
|
722
733
|
[3]: vue3.generateCode
|
|
@@ -982,6 +993,54 @@ function sortNavigationTree(tree) {
|
|
|
982
993
|
}
|
|
983
994
|
}
|
|
984
995
|
|
|
996
|
+
class TemplateLoader {
|
|
997
|
+
async = true;
|
|
998
|
+
folders;
|
|
999
|
+
templateCache;
|
|
1000
|
+
constructor(folders = []) {
|
|
1001
|
+
this.folders = [...folders, path.join(__dirname, "../templates")];
|
|
1002
|
+
this.templateCache = /* @__PURE__ */ new Map();
|
|
1003
|
+
}
|
|
1004
|
+
async getSource(name, callback) {
|
|
1005
|
+
try {
|
|
1006
|
+
const { content, filePath } = await this.resolveTemplate(name);
|
|
1007
|
+
callback(null, {
|
|
1008
|
+
src: content,
|
|
1009
|
+
path: filePath,
|
|
1010
|
+
noCache: false
|
|
1011
|
+
});
|
|
1012
|
+
} catch (err) {
|
|
1013
|
+
if (err instanceof Error) {
|
|
1014
|
+
callback(err, null);
|
|
1015
|
+
} else {
|
|
1016
|
+
callback(new Error(String(err)), null);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
async resolveTemplate(name) {
|
|
1021
|
+
const { templateCache, folders } = this;
|
|
1022
|
+
const cached = templateCache.get(name);
|
|
1023
|
+
if (cached) {
|
|
1024
|
+
return cached;
|
|
1025
|
+
}
|
|
1026
|
+
const searchPaths = folders.map((it) => path.join(it, name));
|
|
1027
|
+
const filePath = searchPaths.find((it) => fs$1.existsSync(it));
|
|
1028
|
+
if (!filePath) {
|
|
1029
|
+
const searched = folders.map((it) => ` - "${it}"`).join("\n");
|
|
1030
|
+
const message = `Failed to resolve template "${name}", searched in:
|
|
1031
|
+
|
|
1032
|
+
${searched}
|
|
1033
|
+
|
|
1034
|
+
Make sure the name is correct and the template file exists in one of the listed directories.`;
|
|
1035
|
+
throw new Error(message);
|
|
1036
|
+
}
|
|
1037
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
1038
|
+
const resolved = { content, filePath };
|
|
1039
|
+
templateCache.set(name, resolved);
|
|
1040
|
+
return resolved;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
985
1044
|
function dump(value) {
|
|
986
1045
|
return `<pre>${JSON.stringify(value, null, 2)}</pre>`;
|
|
987
1046
|
}
|
|
@@ -1065,53 +1124,6 @@ function findTemplate(from, src, format) {
|
|
|
1065
1124
|
return template;
|
|
1066
1125
|
}
|
|
1067
1126
|
|
|
1068
|
-
class Loader {
|
|
1069
|
-
async = true;
|
|
1070
|
-
folders;
|
|
1071
|
-
templateCache;
|
|
1072
|
-
constructor(folders) {
|
|
1073
|
-
this.folders = [...folders, path.join(__dirname, "../templates")];
|
|
1074
|
-
this.templateCache = /* @__PURE__ */ new Map();
|
|
1075
|
-
}
|
|
1076
|
-
async getSource(name, callback) {
|
|
1077
|
-
try {
|
|
1078
|
-
const { content, filePath } = await this.resolveTemplate(name);
|
|
1079
|
-
callback(null, {
|
|
1080
|
-
src: content,
|
|
1081
|
-
path: filePath,
|
|
1082
|
-
noCache: false
|
|
1083
|
-
});
|
|
1084
|
-
} catch (err) {
|
|
1085
|
-
if (err instanceof Error) {
|
|
1086
|
-
callback(err, null);
|
|
1087
|
-
} else {
|
|
1088
|
-
callback(new Error(String(err)), null);
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
async resolveTemplate(name) {
|
|
1093
|
-
const { templateCache, folders } = this;
|
|
1094
|
-
const cached = templateCache.get(name);
|
|
1095
|
-
if (cached) {
|
|
1096
|
-
return cached;
|
|
1097
|
-
}
|
|
1098
|
-
const searchPaths = folders.map((it) => path.join(it, name));
|
|
1099
|
-
const filePath = searchPaths.find((it) => fs$1.existsSync(it));
|
|
1100
|
-
if (!filePath) {
|
|
1101
|
-
const searched = folders.map((it) => ` - "${it}"`).join("\n");
|
|
1102
|
-
const message = `Failed to resolve template "${name}", searched in:
|
|
1103
|
-
|
|
1104
|
-
${searched}
|
|
1105
|
-
|
|
1106
|
-
Make sure the name is correct and the template file exists in one of the listed directories.`;
|
|
1107
|
-
throw new Error(message);
|
|
1108
|
-
}
|
|
1109
|
-
const content = await fs.readFile(filePath, "utf-8");
|
|
1110
|
-
const resolved = { content, filePath };
|
|
1111
|
-
templateCache.set(name, resolved);
|
|
1112
|
-
return resolved;
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
1127
|
const scriptPath = path.join(__dirname, "compile-example.js");
|
|
1116
1128
|
let loader = null;
|
|
1117
1129
|
function haveOutputFile(fileInfo) {
|
|
@@ -1199,7 +1211,7 @@ async function compileStandalones(options) {
|
|
|
1199
1211
|
}
|
|
1200
1212
|
}
|
|
1201
1213
|
function createTemplateLoader(folders) {
|
|
1202
|
-
loader = new
|
|
1214
|
+
loader = new TemplateLoader(folders);
|
|
1203
1215
|
}
|
|
1204
1216
|
async function render(doc, docs, nav, vendors, options) {
|
|
1205
1217
|
const { fileInfo } = doc;
|
|
@@ -1279,9 +1291,10 @@ async function render(doc, docs, nav, vendors, options) {
|
|
|
1279
1291
|
const blocks = options.templateBlocks.get(container) ?? [];
|
|
1280
1292
|
const promises = blocks.map(({ renderer }) => {
|
|
1281
1293
|
if ("filename" in renderer) {
|
|
1294
|
+
const data = renderer.data;
|
|
1282
1295
|
return renderTemplate(renderer.filename, {
|
|
1283
1296
|
...ctx,
|
|
1284
|
-
...
|
|
1297
|
+
...data
|
|
1285
1298
|
});
|
|
1286
1299
|
}
|
|
1287
1300
|
if ("render" in renderer) {
|
|
@@ -1661,214 +1674,6 @@ async function serve(options) {
|
|
|
1661
1674
|
function toArray$1(value) {
|
|
1662
1675
|
return Array.isArray(value) ? value : [value];
|
|
1663
1676
|
}
|
|
1664
|
-
function matomoProcessor(options) {
|
|
1665
|
-
const { enabled, siteId, apiUrl, trackerUrl, hostname } = options;
|
|
1666
|
-
return {
|
|
1667
|
-
after: "generate-docs",
|
|
1668
|
-
name: "matomo-processor",
|
|
1669
|
-
enabled,
|
|
1670
|
-
handler(context) {
|
|
1671
|
-
context.addTemplateBlock("head", "matomo", {
|
|
1672
|
-
filename: "partials/matomo.html",
|
|
1673
|
-
data: {
|
|
1674
|
-
siteId,
|
|
1675
|
-
apiUrl,
|
|
1676
|
-
trackerUrl,
|
|
1677
|
-
hostname: hostname ? toArray$1(hostname) : []
|
|
1678
|
-
}
|
|
1679
|
-
});
|
|
1680
|
-
}
|
|
1681
|
-
};
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
function renderMarkdown(manifest) {
|
|
1685
|
-
return [
|
|
1686
|
-
"## Documentation manifest",
|
|
1687
|
-
"",
|
|
1688
|
-
"> Do not edit this file. It is a automatically generated by `@forsakringskassan/docs-generator`.",
|
|
1689
|
-
"",
|
|
1690
|
-
"```",
|
|
1691
|
-
...manifest.pages.map((it) => it.path),
|
|
1692
|
-
"```",
|
|
1693
|
-
""
|
|
1694
|
-
].join("\n");
|
|
1695
|
-
}
|
|
1696
|
-
function renderJSON(manifest) {
|
|
1697
|
-
return JSON.stringify(manifest, null, 2);
|
|
1698
|
-
}
|
|
1699
|
-
function manifestProcessor(options) {
|
|
1700
|
-
const { markdown, json } = options;
|
|
1701
|
-
return {
|
|
1702
|
-
name: "manifestProcessor",
|
|
1703
|
-
before: "render",
|
|
1704
|
-
async handler(context) {
|
|
1705
|
-
const docs = context.docs.filter(haveOutput);
|
|
1706
|
-
const pages = docs.map(manifestPageFromDocument);
|
|
1707
|
-
pages.sort((a, b) => {
|
|
1708
|
-
return a.path.localeCompare(b.path);
|
|
1709
|
-
});
|
|
1710
|
-
const manifest = { pages };
|
|
1711
|
-
if (markdown) {
|
|
1712
|
-
const content = renderMarkdown(manifest);
|
|
1713
|
-
await fs.writeFile(markdown, content, "utf-8");
|
|
1714
|
-
}
|
|
1715
|
-
if (json) {
|
|
1716
|
-
const content = renderJSON(manifest);
|
|
1717
|
-
await fs.writeFile(json, content, "utf-8");
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
};
|
|
1721
|
-
}
|
|
1722
|
-
|
|
1723
|
-
function themeSelectProcessor() {
|
|
1724
|
-
return {
|
|
1725
|
-
name: "theme-select-processor",
|
|
1726
|
-
after: "generate-docs",
|
|
1727
|
-
handler(context) {
|
|
1728
|
-
context.addTemplateBlock("toolbar", "theme-select", {
|
|
1729
|
-
filename: "partials/theme-select.html"
|
|
1730
|
-
});
|
|
1731
|
-
}
|
|
1732
|
-
};
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
|
-
function versionProcessor(pkg, container) {
|
|
1736
|
-
return {
|
|
1737
|
-
name: "version-processor",
|
|
1738
|
-
after: "generate-docs",
|
|
1739
|
-
handler(context) {
|
|
1740
|
-
context.addTemplateBlock(container, "version", {
|
|
1741
|
-
filename: "partials/version.html",
|
|
1742
|
-
data: { pkg }
|
|
1743
|
-
});
|
|
1744
|
-
}
|
|
1745
|
-
};
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
|
-
function selectableVersionProcessor(pkg, container) {
|
|
1749
|
-
return {
|
|
1750
|
-
name: "selectable-version-processor",
|
|
1751
|
-
after: "generate-docs",
|
|
1752
|
-
handler(context) {
|
|
1753
|
-
context.addTemplateBlock(container, "version", {
|
|
1754
|
-
filename: "partials/selectable-version.html",
|
|
1755
|
-
data: { pkg }
|
|
1756
|
-
});
|
|
1757
|
-
}
|
|
1758
|
-
};
|
|
1759
|
-
}
|
|
1760
|
-
|
|
1761
|
-
function versionBannerProcessor(message, container) {
|
|
1762
|
-
return {
|
|
1763
|
-
name: "version-banner-processor",
|
|
1764
|
-
after: "generate-docs",
|
|
1765
|
-
handler(context) {
|
|
1766
|
-
context.addTemplateBlock(container, "version-banner", {
|
|
1767
|
-
filename: "partials/version-banner.html",
|
|
1768
|
-
data: { message }
|
|
1769
|
-
});
|
|
1770
|
-
}
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
function generateIndex(entries) {
|
|
1775
|
-
const index = {
|
|
1776
|
-
terms: [],
|
|
1777
|
-
results: [],
|
|
1778
|
-
mapping: {}
|
|
1779
|
-
};
|
|
1780
|
-
for (const entry of entries) {
|
|
1781
|
-
index.results.push({
|
|
1782
|
-
url: entry.url,
|
|
1783
|
-
title: entry.title
|
|
1784
|
-
});
|
|
1785
|
-
const resultIndex = index.results.length - 1;
|
|
1786
|
-
for (const word of entry.words) {
|
|
1787
|
-
index.terms.push(word);
|
|
1788
|
-
const termIndex = index.terms.length - 1;
|
|
1789
|
-
index.mapping[termIndex] = resultIndex;
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
return index;
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
function extractTerms(doc) {
|
|
1796
|
-
const { title, component } = doc.attributes;
|
|
1797
|
-
if (title && component) {
|
|
1798
|
-
return component.map((it) => `${title} (${it})`);
|
|
1799
|
-
} else if (component) {
|
|
1800
|
-
return component;
|
|
1801
|
-
} else if (title) {
|
|
1802
|
-
return [title];
|
|
1803
|
-
} else {
|
|
1804
|
-
return [];
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
function isIndexable(doc) {
|
|
1808
|
-
return Boolean(doc.visible && doc.fileInfo.outputName);
|
|
1809
|
-
}
|
|
1810
|
-
function getTerms(doc) {
|
|
1811
|
-
return {
|
|
1812
|
-
url: createMarkdownRenderer.getOutputFilePath(".", doc.fileInfo) ?? "",
|
|
1813
|
-
title: doc.name,
|
|
1814
|
-
words: extractTerms(doc)
|
|
1815
|
-
};
|
|
1816
|
-
}
|
|
1817
|
-
function searchProcessor() {
|
|
1818
|
-
return {
|
|
1819
|
-
after: "generate-docs",
|
|
1820
|
-
name: "search-processor",
|
|
1821
|
-
handler(context) {
|
|
1822
|
-
const entries = context.docs.filter(isIndexable).map(getTerms);
|
|
1823
|
-
const index = generateIndex(entries);
|
|
1824
|
-
const body = JSON.stringify(index);
|
|
1825
|
-
const fingerprint = createMarkdownRenderer.getFingerprint(body);
|
|
1826
|
-
const integrity = getIntegrity(body);
|
|
1827
|
-
const outputName = `search-data-[hash].json`;
|
|
1828
|
-
const expandedName = `search-data-${fingerprint}.json`;
|
|
1829
|
-
context.setTemplateData("searchDataUrl", expandedName);
|
|
1830
|
-
context.setTemplateData("searchDataIntegrity", integrity);
|
|
1831
|
-
context.addDocument({
|
|
1832
|
-
id: "search:data",
|
|
1833
|
-
name: "search-data",
|
|
1834
|
-
alias: [],
|
|
1835
|
-
visible: false,
|
|
1836
|
-
attributes: {
|
|
1837
|
-
sortorder: Infinity
|
|
1838
|
-
},
|
|
1839
|
-
body,
|
|
1840
|
-
outline: [],
|
|
1841
|
-
format: "json",
|
|
1842
|
-
tags: [],
|
|
1843
|
-
template: "json",
|
|
1844
|
-
fileInfo: {
|
|
1845
|
-
path: "",
|
|
1846
|
-
name: "virtual:search-data",
|
|
1847
|
-
fullPath: "virtual:search-data",
|
|
1848
|
-
outputName
|
|
1849
|
-
}
|
|
1850
|
-
});
|
|
1851
|
-
context.addTemplateBlock("toolbar", "search-toolbar", {
|
|
1852
|
-
filename: "partials/search-toolbar.html",
|
|
1853
|
-
data: {
|
|
1854
|
-
rootUrl(doc) {
|
|
1855
|
-
const { fileInfo } = doc;
|
|
1856
|
-
const relative = path$1.relative(fileInfo.path, ".");
|
|
1857
|
-
return relative !== "" ? relative : ".";
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
});
|
|
1861
|
-
context.addTemplateBlock("body:end", "search-dialog", {
|
|
1862
|
-
filename: "partials/search-dialog.html"
|
|
1863
|
-
});
|
|
1864
|
-
context.log("Indexed", entries.length, "documents");
|
|
1865
|
-
}
|
|
1866
|
-
};
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
function toArray(value) {
|
|
1870
|
-
return Array.isArray(value) ? value : [value];
|
|
1871
|
-
}
|
|
1872
1677
|
function filterProcessors(stage2, processors) {
|
|
1873
1678
|
const before = [];
|
|
1874
1679
|
const during = [];
|
|
@@ -1958,10 +1763,10 @@ function createContext() {
|
|
|
1958
1763
|
return sidenav;
|
|
1959
1764
|
},
|
|
1960
1765
|
addDocument(document) {
|
|
1961
|
-
docs = [...docs, ...toArray(document)];
|
|
1766
|
+
docs = [...docs, ...toArray$1(document)];
|
|
1962
1767
|
},
|
|
1963
1768
|
addVendorAsset(asset) {
|
|
1964
|
-
vendors = [...vendors, ...toArray(asset)];
|
|
1769
|
+
vendors = [...vendors, ...toArray$1(asset)];
|
|
1965
1770
|
},
|
|
1966
1771
|
addResource(dst, src) {
|
|
1967
1772
|
resources.push({
|
|
@@ -2151,7 +1956,319 @@ class Generator {
|
|
|
2151
1956
|
}
|
|
2152
1957
|
}
|
|
2153
1958
|
|
|
1959
|
+
function toArray(value) {
|
|
1960
|
+
return Array.isArray(value) ? value : [value];
|
|
1961
|
+
}
|
|
1962
|
+
function matomoProcessor(options) {
|
|
1963
|
+
const { enabled, siteId, apiUrl, trackerUrl, hostname } = options;
|
|
1964
|
+
return {
|
|
1965
|
+
after: "generate-docs",
|
|
1966
|
+
name: "matomo-processor",
|
|
1967
|
+
enabled,
|
|
1968
|
+
handler(context) {
|
|
1969
|
+
context.addTemplateBlock("head", "matomo", {
|
|
1970
|
+
filename: "partials/matomo.html",
|
|
1971
|
+
data: {
|
|
1972
|
+
siteId,
|
|
1973
|
+
apiUrl,
|
|
1974
|
+
trackerUrl,
|
|
1975
|
+
hostname: hostname ? toArray(hostname) : []
|
|
1976
|
+
}
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
function renderMarkdown(manifest) {
|
|
1983
|
+
return [
|
|
1984
|
+
"## Documentation manifest",
|
|
1985
|
+
"",
|
|
1986
|
+
"> Do not edit this file. It is a automatically generated by `@forsakringskassan/docs-generator`.",
|
|
1987
|
+
"",
|
|
1988
|
+
"```",
|
|
1989
|
+
...manifest.pages.map((it) => it.path),
|
|
1990
|
+
"```",
|
|
1991
|
+
""
|
|
1992
|
+
].join("\n");
|
|
1993
|
+
}
|
|
1994
|
+
function renderJSON(manifest) {
|
|
1995
|
+
return JSON.stringify(manifest, null, 2);
|
|
1996
|
+
}
|
|
1997
|
+
function manifestProcessor(options) {
|
|
1998
|
+
const { markdown, json } = options;
|
|
1999
|
+
return {
|
|
2000
|
+
name: "manifestProcessor",
|
|
2001
|
+
before: "render",
|
|
2002
|
+
async handler(context) {
|
|
2003
|
+
const docs = context.docs.filter(haveOutput);
|
|
2004
|
+
const pages = docs.map(manifestPageFromDocument);
|
|
2005
|
+
pages.sort((a, b) => {
|
|
2006
|
+
return a.path.localeCompare(b.path);
|
|
2007
|
+
});
|
|
2008
|
+
const manifest = { pages };
|
|
2009
|
+
if (markdown) {
|
|
2010
|
+
const content = renderMarkdown(manifest);
|
|
2011
|
+
await fs.writeFile(markdown, content, "utf-8");
|
|
2012
|
+
}
|
|
2013
|
+
if (json) {
|
|
2014
|
+
const content = renderJSON(manifest);
|
|
2015
|
+
await fs.writeFile(json, content, "utf-8");
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
function themeSelectProcessor() {
|
|
2022
|
+
return {
|
|
2023
|
+
name: "theme-select-processor",
|
|
2024
|
+
after: "generate-docs",
|
|
2025
|
+
handler(context) {
|
|
2026
|
+
context.addTemplateBlock("toolbar", "theme-select", {
|
|
2027
|
+
filename: "partials/theme-select.html"
|
|
2028
|
+
});
|
|
2029
|
+
}
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
function selectableVersionProcessor(pkg, container) {
|
|
2034
|
+
return {
|
|
2035
|
+
name: "selectable-version-processor",
|
|
2036
|
+
after: "generate-docs",
|
|
2037
|
+
handler(context) {
|
|
2038
|
+
context.addTemplateBlock(container, "version", {
|
|
2039
|
+
filename: "partials/selectable-version.html",
|
|
2040
|
+
data: { pkg }
|
|
2041
|
+
});
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
function generateNavigation(entries) {
|
|
2047
|
+
const children = entries.map((it, index) => {
|
|
2048
|
+
const key = path$1.parse(it.path).name;
|
|
2049
|
+
return {
|
|
2050
|
+
key,
|
|
2051
|
+
sortorder: index,
|
|
2052
|
+
children: [],
|
|
2053
|
+
...it
|
|
2054
|
+
};
|
|
2055
|
+
});
|
|
2056
|
+
return {
|
|
2057
|
+
key: ".",
|
|
2058
|
+
path: "./index.html",
|
|
2059
|
+
sortorder: Infinity,
|
|
2060
|
+
children
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
function topnavProcessor(filename, title) {
|
|
2064
|
+
return {
|
|
2065
|
+
after: "generate-nav",
|
|
2066
|
+
name: "topnav-processor",
|
|
2067
|
+
async handler(context) {
|
|
2068
|
+
const content = await fs.readFile(filename, "utf-8");
|
|
2069
|
+
const parsed = JSON.parse(content);
|
|
2070
|
+
const rootNode = generateNavigation(parsed);
|
|
2071
|
+
context.setTopNavigation({
|
|
2072
|
+
title,
|
|
2073
|
+
...rootNode
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
function run(cmd, defaultValue) {
|
|
2080
|
+
return new Promise((resolve) => {
|
|
2081
|
+
childProcess.exec(cmd, { encoding: "utf-8" }, (error, stdout) => {
|
|
2082
|
+
if (error) {
|
|
2083
|
+
console.error(error);
|
|
2084
|
+
resolve(defaultValue);
|
|
2085
|
+
} else {
|
|
2086
|
+
resolve(stdout.trim());
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
});
|
|
2090
|
+
}
|
|
2091
|
+
async function getGitBranch() {
|
|
2092
|
+
const { CHANGE_BRANCH, CHANGE_NAME } = process.env;
|
|
2093
|
+
if (CHANGE_BRANCH) {
|
|
2094
|
+
return CHANGE_BRANCH;
|
|
2095
|
+
}
|
|
2096
|
+
if (CHANGE_NAME) {
|
|
2097
|
+
return CHANGE_NAME;
|
|
2098
|
+
}
|
|
2099
|
+
const branch = await run("git rev-parse --abbrev-ref HEAD", "unknown");
|
|
2100
|
+
if (branch === "HEAD" || branch === "") {
|
|
2101
|
+
return "unknown";
|
|
2102
|
+
} else {
|
|
2103
|
+
return branch;
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
function getPullRequestID() {
|
|
2107
|
+
return process.env.JOB_BASE_NAME;
|
|
2108
|
+
}
|
|
2109
|
+
async function getSCMData(pkg, options) {
|
|
2110
|
+
const commitHash = await run(`git rev-parse HEAD`);
|
|
2111
|
+
const commitShort = await run(`git rev-parse --short HEAD`);
|
|
2112
|
+
if (!commitHash || !commitShort) {
|
|
2113
|
+
return null;
|
|
2114
|
+
}
|
|
2115
|
+
const { homepage } = pkg;
|
|
2116
|
+
const pr = getPullRequestID();
|
|
2117
|
+
const prUrl = pr ? interpolate(options.prUrlFormat, { homepage, pr }) : void 0;
|
|
2118
|
+
return {
|
|
2119
|
+
branch: await getGitBranch(),
|
|
2120
|
+
commitShort,
|
|
2121
|
+
commitHash,
|
|
2122
|
+
commitUrl: interpolate(options.commitUrlFormat, {
|
|
2123
|
+
hash: commitHash,
|
|
2124
|
+
short: commitShort,
|
|
2125
|
+
homepage
|
|
2126
|
+
}),
|
|
2127
|
+
pr,
|
|
2128
|
+
prUrl
|
|
2129
|
+
};
|
|
2130
|
+
}
|
|
2131
|
+
function getBuildDatetime() {
|
|
2132
|
+
const date = /* @__PURE__ */ new Date();
|
|
2133
|
+
return {
|
|
2134
|
+
date: date.toLocaleDateString("sv-SE"),
|
|
2135
|
+
time: date.toLocaleTimeString("sv-SE")
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
function versionProcessor(pkg, container, options) {
|
|
2139
|
+
const { enabled = true, scm = false } = options ?? {};
|
|
2140
|
+
return {
|
|
2141
|
+
name: "version-processor",
|
|
2142
|
+
after: "generate-docs",
|
|
2143
|
+
async handler(context) {
|
|
2144
|
+
if (!enabled) {
|
|
2145
|
+
return;
|
|
2146
|
+
}
|
|
2147
|
+
const scmData = scm ? await getSCMData(pkg, scm) : null;
|
|
2148
|
+
const buildData = getBuildDatetime();
|
|
2149
|
+
const data = {
|
|
2150
|
+
pkg,
|
|
2151
|
+
scm: scmData,
|
|
2152
|
+
build: buildData
|
|
2153
|
+
};
|
|
2154
|
+
context.addTemplateBlock(container, "version", {
|
|
2155
|
+
filename: "partials/version.njk.html",
|
|
2156
|
+
data
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
};
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
function versionBannerProcessor(message, container) {
|
|
2163
|
+
return {
|
|
2164
|
+
name: "version-banner-processor",
|
|
2165
|
+
after: "generate-docs",
|
|
2166
|
+
handler(context) {
|
|
2167
|
+
context.addTemplateBlock(container, "version-banner", {
|
|
2168
|
+
filename: "partials/version-banner.html",
|
|
2169
|
+
data: { message }
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
function generateIndex(entries) {
|
|
2176
|
+
const index = {
|
|
2177
|
+
terms: [],
|
|
2178
|
+
results: [],
|
|
2179
|
+
mapping: {}
|
|
2180
|
+
};
|
|
2181
|
+
for (const entry of entries) {
|
|
2182
|
+
index.results.push({
|
|
2183
|
+
url: entry.url,
|
|
2184
|
+
title: entry.title
|
|
2185
|
+
});
|
|
2186
|
+
const resultIndex = index.results.length - 1;
|
|
2187
|
+
for (const word of entry.words) {
|
|
2188
|
+
index.terms.push(word);
|
|
2189
|
+
const termIndex = index.terms.length - 1;
|
|
2190
|
+
index.mapping[termIndex] = resultIndex;
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
return index;
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
function extractTerms(doc) {
|
|
2197
|
+
const { title, component } = doc.attributes;
|
|
2198
|
+
if (title && component) {
|
|
2199
|
+
return component.map((it) => `${title} (${it})`);
|
|
2200
|
+
} else if (component) {
|
|
2201
|
+
return component;
|
|
2202
|
+
} else if (title) {
|
|
2203
|
+
return [title];
|
|
2204
|
+
} else {
|
|
2205
|
+
return [];
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
function isIndexable(doc) {
|
|
2209
|
+
return Boolean(doc.visible && doc.fileInfo.outputName);
|
|
2210
|
+
}
|
|
2211
|
+
function getTerms(doc) {
|
|
2212
|
+
return {
|
|
2213
|
+
url: createMarkdownRenderer.getOutputFilePath(".", doc.fileInfo) ?? "",
|
|
2214
|
+
title: doc.name,
|
|
2215
|
+
words: extractTerms(doc)
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
2218
|
+
function searchProcessor() {
|
|
2219
|
+
return {
|
|
2220
|
+
after: "generate-docs",
|
|
2221
|
+
name: "search-processor",
|
|
2222
|
+
handler(context) {
|
|
2223
|
+
const entries = context.docs.filter(isIndexable).map(getTerms);
|
|
2224
|
+
const index = generateIndex(entries);
|
|
2225
|
+
const body = JSON.stringify(index);
|
|
2226
|
+
const fingerprint = createMarkdownRenderer.getFingerprint(body);
|
|
2227
|
+
const integrity = getIntegrity(body);
|
|
2228
|
+
const outputName = `search-data-[hash].json`;
|
|
2229
|
+
const expandedName = `search-data-${fingerprint}.json`;
|
|
2230
|
+
context.setTemplateData("searchDataUrl", expandedName);
|
|
2231
|
+
context.setTemplateData("searchDataIntegrity", integrity);
|
|
2232
|
+
context.addDocument({
|
|
2233
|
+
id: "search:data",
|
|
2234
|
+
name: "search-data",
|
|
2235
|
+
alias: [],
|
|
2236
|
+
visible: false,
|
|
2237
|
+
attributes: {
|
|
2238
|
+
sortorder: Infinity
|
|
2239
|
+
},
|
|
2240
|
+
body,
|
|
2241
|
+
outline: [],
|
|
2242
|
+
format: "json",
|
|
2243
|
+
tags: [],
|
|
2244
|
+
template: "json",
|
|
2245
|
+
fileInfo: {
|
|
2246
|
+
path: "",
|
|
2247
|
+
name: "virtual:search-data",
|
|
2248
|
+
fullPath: "virtual:search-data",
|
|
2249
|
+
outputName
|
|
2250
|
+
}
|
|
2251
|
+
});
|
|
2252
|
+
context.addTemplateBlock("toolbar", "search-toolbar", {
|
|
2253
|
+
filename: "partials/search-toolbar.html",
|
|
2254
|
+
data: {
|
|
2255
|
+
rootUrl(doc) {
|
|
2256
|
+
const { fileInfo } = doc;
|
|
2257
|
+
const relative = path$1.relative(fileInfo.path, ".");
|
|
2258
|
+
return relative !== "" ? relative : ".";
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
});
|
|
2262
|
+
context.addTemplateBlock("body:end", "search-dialog", {
|
|
2263
|
+
filename: "partials/search-dialog.html"
|
|
2264
|
+
});
|
|
2265
|
+
context.log("Indexed", entries.length, "documents");
|
|
2266
|
+
}
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2154
2270
|
exports.Generator = Generator;
|
|
2271
|
+
exports.defineSources = defineSources;
|
|
2155
2272
|
exports.frontMatterFileReader = frontMatterFileReader;
|
|
2156
2273
|
exports.livereloadProcessor = livereloadProcessor;
|
|
2157
2274
|
exports.manifestProcessor = manifestProcessor;
|
|
@@ -2160,6 +2277,7 @@ exports.navigationFileReader = navigationFileReader;
|
|
|
2160
2277
|
exports.searchProcessor = searchProcessor;
|
|
2161
2278
|
exports.selectableVersionProcessor = selectableVersionProcessor;
|
|
2162
2279
|
exports.themeSelectProcessor = themeSelectProcessor;
|
|
2280
|
+
exports.topnavProcessor = topnavProcessor;
|
|
2163
2281
|
exports.versionBannerProcessor = versionBannerProcessor;
|
|
2164
2282
|
exports.versionProcessor = versionProcessor;
|
|
2165
2283
|
exports.vueFileReader = vueFileReader;
|