-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-docs.mjs
97 lines (90 loc) · 2.53 KB
/
generate-docs.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import fs from "node:fs/promises";
import path from "node:path";
import isCI from "is-ci";
import {
Generator,
extractExamplesProcessor,
htmlRedirectProcessor,
manifestProcessor,
motdProcessor,
versionProcessor,
redirectFileProcessor,
searchProcessor,
sourceUrlProcessor,
cookieProcessor,
selectableVersionProcessor,
} from "./dist/index.js";
import config from "./docs.config.mjs";
const isRelease = Boolean(process.env.RELEASE);
const pkg = JSON.parse(await fs.readFile("./package.json", "utf-8"));
const docs = new Generator({
site: {
name: "FK Documentation generator",
lang: "sv",
},
outputFolder: "./public",
cacheFolder: "./temp/docs",
exampleFolders: ["./docs", "./src"],
templateFolders: ["./docs/templates"],
vendor: [
{
package: "vue",
expose: "named",
alias: "vue/dist/vue.esm-bundler.js",
},
"@forsakringskassan/docs-live-example",
],
processors: [
extractExamplesProcessor({
outputFolder: "docs/examples/files",
}),
htmlRedirectProcessor(),
redirectFileProcessor(),
manifestProcessor({ markdown: "etc/docs-manifest.md" }),
searchProcessor(),
versionProcessor(pkg, "toolbar", {
scm: !isRelease
? {
commitUrlFormat: "{{ repository }}/commits/{{ hash }}",
prUrlFormat: "{{ repository }}/pull/{{ pr }}",
}
: undefined,
}),
sourceUrlProcessor(pkg, {
sourceFiles: ["docs/**"],
urlFormat: "{{ repository }}/tree/main/{{ path }}",
componentFileExtension: "baz",
}),
cookieProcessor(),
motdProcessor(),
selectableVersionProcessor(pkg, "footer"),
],
setupPath: path.resolve("docs/src/setup.ts"),
});
docs.compileScript("main", "./docs/src/main.js", {
appendTo: "body",
});
docs.compileStyle("docs", "./docs/src/docs-theme.scss", {
appendTo: "head",
});
docs.compileStyle("fkui", "./docs/src/fkui.css", {
appendTo: "head",
});
try {
await docs.build(config.sourceFiles);
} catch (err) {
console.error(err.prettyError ? err.prettyError() : err);
process.exitCode = 1;
}
if (!isCI) {
const latest = `v${pkg.version}`;
const versions = JSON.stringify(
{
latest,
versions: [latest],
},
null,
2,
);
await fs.writeFile("public/versions.json", versions, "utf-8");
}