clean-jsdoc-theme 4.3.0 → 5.0.0-alpha.1
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/README.md +117 -625
- package/dist/publish.d.mts +218 -0
- package/dist/publish.d.ts +218 -0
- package/dist/publish.js +641 -0
- package/dist/publish.js.map +1 -0
- package/dist/publish.mjs +605 -0
- package/dist/publish.mjs.map +1 -0
- package/package.json +65 -55
- package/.eslintignore +0 -5
- package/.eslintrc.js +0 -3
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -43
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -27
- package/.github/dependabot.yml +0 -9
- package/.github/pull_request_template.md +0 -16
- package/.github/workflows/codeql.yml +0 -72
- package/.github/workflows/greetings.yml +0 -16
- package/.prettierignore +0 -2
- package/.prettierrc +0 -5
- package/.stylelintignore +0 -4
- package/.stylelintrc +0 -18
- package/.travis.yml +0 -30
- package/CHANGELOG.md +0 -260
- package/CODE_OF_CONDUCT.md +0 -76
- package/CODE_OF_CONDUCT_HINDI.md +0 -61
- package/CONTRIBUTING.md +0 -36
- package/LICENSE +0 -21
- package/SECURITY.md +0 -21
- package/clean-jsdoc-theme-defaults.js +0 -37
- package/clean-jsdoc-theme-helper.js +0 -186
- package/css-property-order-fix.js +0 -56
- package/helpers/Environment.html +0 -3
- package/helpers/down-arrow.js +0 -9
- package/jsdoc-config.json +0 -102
- package/minify.js +0 -72
- package/publish.js +0 -1104
- package/static/fonts/Inconsolata-Regular.ttf +0 -0
- package/static/fonts/OpenSans-Regular.ttf +0 -0
- package/static/fonts/WorkSans-Bold.ttf +0 -0
- package/static/scripts/core.js +0 -726
- package/static/scripts/core.min.js +0 -23
- package/static/scripts/resize.js +0 -90
- package/static/scripts/search.js +0 -265
- package/static/scripts/search.min.js +0 -6
- package/static/scripts/third-party/Apache-License-2.0.txt +0 -202
- package/static/scripts/third-party/fuse.js +0 -9
- package/static/scripts/third-party/hljs-line-num-original.js +0 -369
- package/static/scripts/third-party/hljs-line-num.js +0 -1
- package/static/scripts/third-party/hljs-original.js +0 -5171
- package/static/scripts/third-party/hljs.js +0 -1
- package/static/scripts/third-party/popper.js +0 -5
- package/static/scripts/third-party/tippy.js +0 -1
- package/static/scripts/third-party/tocbot.js +0 -672
- package/static/scripts/third-party/tocbot.min.js +0 -1
- package/static/styles/clean-jsdoc-theme-base.css +0 -1159
- package/static/styles/clean-jsdoc-theme-dark.css +0 -412
- package/static/styles/clean-jsdoc-theme-light.css +0 -482
- package/static/styles/clean-jsdoc-theme-scrollbar.css +0 -30
- package/static/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -1
- package/static/styles/clean-jsdoc-theme.min.css +0 -1
- package/tmpl/augments.tmpl +0 -10
- package/tmpl/container.tmpl +0 -208
- package/tmpl/details.tmpl +0 -207
- package/tmpl/example.tmpl +0 -3
- package/tmpl/examples.tmpl +0 -48
- package/tmpl/exceptions.tmpl +0 -32
- package/tmpl/icons.tmpl +0 -73
- package/tmpl/include-target-script-and-styles.tmpl +0 -43
- package/tmpl/layout.tmpl +0 -167
- package/tmpl/mainpage.tmpl +0 -10
- package/tmpl/members.tmpl +0 -42
- package/tmpl/method.tmpl +0 -175
- package/tmpl/mobile-sidebar.tmpl +0 -21
- package/tmpl/navbar-actions.tmpl +0 -19
- package/tmpl/navbar-menu.tmpl +0 -25
- package/tmpl/navbar.tmpl +0 -14
- package/tmpl/params.tmpl +0 -131
- package/tmpl/properties.tmpl +0 -109
- package/tmpl/returns.tmpl +0 -19
- package/tmpl/search.tmpl +0 -17
- package/tmpl/sidebar-items.tmpl +0 -24
- package/tmpl/sidebar-title.tmpl +0 -8
- package/tmpl/sidebar.tmpl +0 -9
- package/tmpl/source.tmpl +0 -13
- package/tmpl/toc.tmpl +0 -4
- package/tmpl/tutorial.tmpl +0 -32
- package/tmpl/type.tmpl +0 -13
package/dist/publish.mjs
ADDED
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/publish.ts
|
|
9
|
+
import { readFile, readdir } from "fs/promises";
|
|
10
|
+
import { readFileSync } from "fs";
|
|
11
|
+
import { createHash } from "crypto";
|
|
12
|
+
import { basename, dirname as dirname2, extname, join as joinPath, resolve as resolvePath } from "path";
|
|
13
|
+
import { pathToFileURL, fileURLToPath } from "url";
|
|
14
|
+
|
|
15
|
+
// src/write-output-files.ts
|
|
16
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
17
|
+
import { dirname, join } from "path";
|
|
18
|
+
async function writeOutputFiles(destination, files) {
|
|
19
|
+
for (const file of files) {
|
|
20
|
+
const target = join(destination, file.path);
|
|
21
|
+
await mkdir(dirname(target), { recursive: true });
|
|
22
|
+
const contents = typeof file.contents === "string" ? file.contents : Buffer.from(file.contents);
|
|
23
|
+
await writeFile(target, contents);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/publish.ts
|
|
28
|
+
var JSDOC_TUTORIAL_TYPE_MARKDOWN = 2;
|
|
29
|
+
function anchorPath() {
|
|
30
|
+
if (typeof __filename === "string") return __filename;
|
|
31
|
+
try {
|
|
32
|
+
const getEsmUrl = new Function(
|
|
33
|
+
"try { return import.meta && import.meta.url; } catch { return undefined; }"
|
|
34
|
+
);
|
|
35
|
+
const url = getEsmUrl();
|
|
36
|
+
if (typeof url === "string" && url.startsWith("file://")) {
|
|
37
|
+
return fileURLToPath(url);
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
throw new Error(
|
|
42
|
+
"clean-jsdoc-theme: could not determine the running module path (neither __filename nor import.meta.url resolved)."
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function resolvePackageDir(name) {
|
|
46
|
+
const start = anchorPath();
|
|
47
|
+
let dir = dirname2(start);
|
|
48
|
+
let prev = "";
|
|
49
|
+
while (dir !== prev) {
|
|
50
|
+
const candidate = resolvePath(dir, "node_modules", name);
|
|
51
|
+
try {
|
|
52
|
+
readFileSync(resolvePath(candidate, "package.json"), "utf8");
|
|
53
|
+
return candidate;
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
prev = dir;
|
|
57
|
+
dir = dirname2(dir);
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`clean-jsdoc-theme: could not locate '${name}' on disk starting from ${start}.`);
|
|
60
|
+
}
|
|
61
|
+
function resolveEsmEntry(name) {
|
|
62
|
+
const pkgRoot = resolvePackageDir(name);
|
|
63
|
+
const pkg = JSON.parse(
|
|
64
|
+
readFileSync(resolvePath(pkgRoot, "package.json"), "utf8")
|
|
65
|
+
);
|
|
66
|
+
const exp = pkg.exports;
|
|
67
|
+
if (exp && typeof exp === "object") {
|
|
68
|
+
const dot = exp["."];
|
|
69
|
+
if (typeof dot === "string") return resolvePath(pkgRoot, dot);
|
|
70
|
+
if (dot && typeof dot === "object") {
|
|
71
|
+
const imp = dot.import;
|
|
72
|
+
if (typeof imp === "string") return resolvePath(pkgRoot, imp);
|
|
73
|
+
if (imp && typeof imp === "object") {
|
|
74
|
+
const def2 = imp.default;
|
|
75
|
+
if (typeof def2 === "string") return resolvePath(pkgRoot, def2);
|
|
76
|
+
}
|
|
77
|
+
const def = dot.default;
|
|
78
|
+
if (typeof def === "string") return resolvePath(pkgRoot, def);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (typeof pkg.module === "string") return resolvePath(pkgRoot, pkg.module);
|
|
82
|
+
if (typeof pkg.main === "string") return resolvePath(pkgRoot, pkg.main);
|
|
83
|
+
throw new Error(
|
|
84
|
+
`clean-jsdoc-theme: could not determine ESM entry file for '${name}' (no exports/module/main).`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
async function loadDep(name, requiredExports) {
|
|
88
|
+
const entry = resolveEsmEntry(name);
|
|
89
|
+
const id = pathToFileURL(entry).href;
|
|
90
|
+
const mod = await import(id);
|
|
91
|
+
for (const key of requiredExports) {
|
|
92
|
+
if (typeof mod[key] !== "function") {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`clean-jsdoc-theme: '${name}' did not export a '${key}' function (resolved from ${entry}; got keys: ${Object.keys(mod).join(", ") || "(none)"}).`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return mod;
|
|
99
|
+
}
|
|
100
|
+
var loadSetu = () => loadDep("@clean-jsdoc-theme/setu", ["generateSite"]);
|
|
101
|
+
var loadDwar = () => loadDep("@clean-jsdoc-theme/dwar", ["render", "runPagefindAgainstDir"]);
|
|
102
|
+
var loadUtils = () => loadDep("@clean-jsdoc-theme/utils", [
|
|
103
|
+
"validateThemeOpts",
|
|
104
|
+
"createGoogleFontResolver",
|
|
105
|
+
"formatDiagnostics",
|
|
106
|
+
"formatBuildReport",
|
|
107
|
+
"normalizeBasePath",
|
|
108
|
+
"withBase"
|
|
109
|
+
]);
|
|
110
|
+
var JSDOC_OWN_OPTS = /* @__PURE__ */ new Set([
|
|
111
|
+
"destination",
|
|
112
|
+
"template",
|
|
113
|
+
"encoding",
|
|
114
|
+
"recurse",
|
|
115
|
+
"readme",
|
|
116
|
+
"package",
|
|
117
|
+
"tutorials",
|
|
118
|
+
"query",
|
|
119
|
+
"private",
|
|
120
|
+
"access",
|
|
121
|
+
"explain",
|
|
122
|
+
"debug",
|
|
123
|
+
"verbose",
|
|
124
|
+
"pedantic",
|
|
125
|
+
"match",
|
|
126
|
+
"nocolor",
|
|
127
|
+
"templates"
|
|
128
|
+
]);
|
|
129
|
+
var defaultTheme = {
|
|
130
|
+
tokens: {
|
|
131
|
+
// Light palette (oklch). bg #fdfdf7 · fg #3e3e3e · border #eeeeee;
|
|
132
|
+
// muted/accent derived to harmonize.
|
|
133
|
+
colors: {
|
|
134
|
+
bg: "oklch(0.9924 0.0079 106.54)",
|
|
135
|
+
bgMuted: "oklch(0.9595 0.0079 106.55)",
|
|
136
|
+
fg: "oklch(0.3639 0 0)",
|
|
137
|
+
fgMuted: "oklch(0.5278 0 0)",
|
|
138
|
+
accent: "oklch(0 0 0)",
|
|
139
|
+
accentFg: "oklch(1 0 0)",
|
|
140
|
+
border: "oklch(0.9561 0 0)"
|
|
141
|
+
},
|
|
142
|
+
// Dark palette (oklch). bg #09090b · fg #9e9e9e · border #141416;
|
|
143
|
+
// muted/accent derived to harmonize.
|
|
144
|
+
darkColors: {
|
|
145
|
+
bg: "oklch(0.1408 0.0044 285.82)",
|
|
146
|
+
bgMuted: "oklch(0.2103 0.0059 285.89)",
|
|
147
|
+
fg: "oklch(0.6993 0 0)",
|
|
148
|
+
fgMuted: "oklch(0.5382 0 0)",
|
|
149
|
+
accent: "oklch(1 0 0)",
|
|
150
|
+
accentFg: "oklch(0 0 0)",
|
|
151
|
+
border: "oklch(0.2321 0.004 286.02)"
|
|
152
|
+
},
|
|
153
|
+
fonts: {
|
|
154
|
+
heading: "Source Serif 4",
|
|
155
|
+
body: "Roboto",
|
|
156
|
+
mono: "ui-monospace, SFMono-Regular, Menlo, monospace"
|
|
157
|
+
},
|
|
158
|
+
shiki: { light: "github-light", dark: "github-dark" }
|
|
159
|
+
},
|
|
160
|
+
basePath: "/"
|
|
161
|
+
};
|
|
162
|
+
function resolveTheme(opts, siteName, fonts, basePath) {
|
|
163
|
+
const aiPrompt = typeof opts.aiPrompt === "string" && opts.aiPrompt.trim() ? opts.aiPrompt.trim() : void 0;
|
|
164
|
+
const copyPage = normalizeCopyPage(opts.copyPage);
|
|
165
|
+
return {
|
|
166
|
+
...defaultTheme,
|
|
167
|
+
basePath,
|
|
168
|
+
...aiPrompt ? { aiPrompt } : {},
|
|
169
|
+
...copyPage ? { copyPage } : {},
|
|
170
|
+
tokens: {
|
|
171
|
+
...defaultTheme.tokens,
|
|
172
|
+
fonts: {
|
|
173
|
+
heading: fonts.heading ?? defaultTheme.tokens.fonts.heading,
|
|
174
|
+
body: fonts.body ?? defaultTheme.tokens.fonts.body,
|
|
175
|
+
mono: fonts.mono ?? defaultTheme.tokens.fonts.mono
|
|
176
|
+
},
|
|
177
|
+
...siteName ? { siteName } : {}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function nonEmptyString(value) {
|
|
182
|
+
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
183
|
+
}
|
|
184
|
+
function contentHash(bytes) {
|
|
185
|
+
return createHash("sha256").update(bytes).digest("hex").slice(0, 8);
|
|
186
|
+
}
|
|
187
|
+
async function copyCustomFiles(raw, ext, hash, label, hrefForServed) {
|
|
188
|
+
const paths = (Array.isArray(raw) ? raw : [raw]).filter(
|
|
189
|
+
(p) => typeof p === "string" && p.trim().length > 0
|
|
190
|
+
);
|
|
191
|
+
const links = [];
|
|
192
|
+
const files = [];
|
|
193
|
+
const seen = /* @__PURE__ */ new Set();
|
|
194
|
+
for (const p of paths) {
|
|
195
|
+
const trimmed = p.trim();
|
|
196
|
+
let bytes;
|
|
197
|
+
try {
|
|
198
|
+
bytes = await readFile(resolvePath(trimmed));
|
|
199
|
+
} catch {
|
|
200
|
+
console.warn(`clean-jsdoc-theme: could not read ${label} ('${trimmed}'); skipping it.`);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const base = basename(trimmed, extname(trimmed)) || "custom";
|
|
204
|
+
const name = hash ? `${base}.${contentHash(bytes)}${ext}` : `${base}${ext}`;
|
|
205
|
+
const servedPath = `_assets/${name}`;
|
|
206
|
+
if (seen.has(servedPath)) continue;
|
|
207
|
+
seen.add(servedPath);
|
|
208
|
+
files.push({ path: servedPath, contents: bytes });
|
|
209
|
+
links.push(hrefForServed(servedPath));
|
|
210
|
+
}
|
|
211
|
+
return { links, files };
|
|
212
|
+
}
|
|
213
|
+
async function resolveCustomAssets(opts, hrefForServed) {
|
|
214
|
+
const hash = opts.hashCustomAssets !== false;
|
|
215
|
+
const [cssAssets, jsAssets] = await Promise.all([
|
|
216
|
+
copyCustomFiles(opts.customCssFile, ".css", hash, "customCssFile", hrefForServed),
|
|
217
|
+
copyCustomFiles(opts.customJsFile, ".js", hash, "customJsFile", hrefForServed)
|
|
218
|
+
]);
|
|
219
|
+
const customCss = nonEmptyString(opts.customCss)?.trim();
|
|
220
|
+
const customJs = nonEmptyString(opts.customJs)?.trim();
|
|
221
|
+
return {
|
|
222
|
+
theme: {
|
|
223
|
+
...customCss ? { customCss } : {},
|
|
224
|
+
...cssAssets.links.length > 0 ? { customCssLinks: cssAssets.links } : {},
|
|
225
|
+
...customJs ? { customJs } : {},
|
|
226
|
+
...jsAssets.links.length > 0 ? { customJsLinks: jsAssets.links } : {}
|
|
227
|
+
},
|
|
228
|
+
files: [...cssAssets.files, ...jsAssets.files]
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function isServableUrl(value) {
|
|
232
|
+
return /^(https?:)?\/\//i.test(value) || /^data:/i.test(value);
|
|
233
|
+
}
|
|
234
|
+
async function prepareSiteName(raw, hrefForServed) {
|
|
235
|
+
if (typeof raw === "string") {
|
|
236
|
+
const trimmed = raw.trim();
|
|
237
|
+
return { siteName: trimmed.length > 0 ? trimmed : void 0, files: [] };
|
|
238
|
+
}
|
|
239
|
+
if (!raw || typeof raw !== "object") return { siteName: void 0, files: [] };
|
|
240
|
+
const files = [];
|
|
241
|
+
const out = {};
|
|
242
|
+
if (typeof raw.alt === "string" && raw.alt.trim().length > 0) out.alt = raw.alt.trim();
|
|
243
|
+
for (const key of ["default", "dark", "light"]) {
|
|
244
|
+
const value = raw[key];
|
|
245
|
+
if (typeof value !== "string" || value.trim().length === 0) continue;
|
|
246
|
+
const v = value.trim();
|
|
247
|
+
if (isServableUrl(v)) {
|
|
248
|
+
out[key] = v;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
const abs = resolvePath(v);
|
|
253
|
+
const buf = await readFile(abs);
|
|
254
|
+
const served = `_assets/logo-${key}${extname(abs)}`;
|
|
255
|
+
files.push({ path: served, contents: buf });
|
|
256
|
+
out[key] = hrefForServed(served);
|
|
257
|
+
} catch {
|
|
258
|
+
console.warn(
|
|
259
|
+
`clean-jsdoc-theme: could not read logo image for siteName.${key} ('${v}'); using it verbatim.`
|
|
260
|
+
);
|
|
261
|
+
out[key] = v;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const hasContent = out.default || out.dark || out.light || out.alt;
|
|
265
|
+
return { siteName: hasContent ? out : void 0, files };
|
|
266
|
+
}
|
|
267
|
+
async function resolvePkg(data, opts) {
|
|
268
|
+
if (typeof opts.package === "string" && opts.package.length > 0) {
|
|
269
|
+
try {
|
|
270
|
+
const json = await readFile(opts.package, "utf8");
|
|
271
|
+
const parsed = JSON.parse(json);
|
|
272
|
+
return pickPkgFields(parsed);
|
|
273
|
+
} catch {
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (typeof data === "function") {
|
|
277
|
+
try {
|
|
278
|
+
const pkgDoclets = data({ kind: "package" }).get();
|
|
279
|
+
if (Array.isArray(pkgDoclets) && pkgDoclets.length > 0) {
|
|
280
|
+
return pickPkgFields(pkgDoclets[0]);
|
|
281
|
+
}
|
|
282
|
+
} catch {
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return void 0;
|
|
286
|
+
}
|
|
287
|
+
function pickPkgFields(raw) {
|
|
288
|
+
const pkg = {};
|
|
289
|
+
if (typeof raw.name === "string") pkg.name = raw.name;
|
|
290
|
+
if (typeof raw.version === "string") pkg.version = raw.version;
|
|
291
|
+
if (typeof raw.description === "string") pkg.description = raw.description;
|
|
292
|
+
if (typeof raw.homepage === "string") pkg.homepage = raw.homepage;
|
|
293
|
+
if (typeof raw.repository === "string") {
|
|
294
|
+
pkg.repository = raw.repository;
|
|
295
|
+
} else if (raw.repository && typeof raw.repository === "object" && typeof raw.repository.url === "string") {
|
|
296
|
+
pkg.repository = raw.repository.url;
|
|
297
|
+
}
|
|
298
|
+
return pkg;
|
|
299
|
+
}
|
|
300
|
+
function normalizeTutorials(root) {
|
|
301
|
+
const walk = (node) => {
|
|
302
|
+
const name = typeof node.name === "string" ? node.name : "";
|
|
303
|
+
if (!name) return null;
|
|
304
|
+
const title = typeof node.title === "string" && node.title.length > 0 ? node.title : name;
|
|
305
|
+
const content = typeof node.content === "string" ? node.content : "";
|
|
306
|
+
const type = node.type === JSDOC_TUTORIAL_TYPE_MARKDOWN ? "markdown" : "html";
|
|
307
|
+
const children2 = Array.isArray(node.children) ? node.children.map(walk).filter((t) => t !== null) : [];
|
|
308
|
+
return { name, title, content, type, children: children2 };
|
|
309
|
+
};
|
|
310
|
+
const children = root?.children;
|
|
311
|
+
if (!Array.isArray(children)) return [];
|
|
312
|
+
return children.map(walk).filter((t) => t !== null);
|
|
313
|
+
}
|
|
314
|
+
function outputSourceFilesEnabled(opts) {
|
|
315
|
+
try {
|
|
316
|
+
const env = __require("jsdoc/env");
|
|
317
|
+
if (env?.conf?.templates?.default?.outputSourceFiles === false) return false;
|
|
318
|
+
} catch {
|
|
319
|
+
}
|
|
320
|
+
if (opts?.templates?.default?.outputSourceFiles === false) return false;
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
function sourceLinkToCommentEnabled(opts) {
|
|
324
|
+
try {
|
|
325
|
+
const env = __require("jsdoc/env");
|
|
326
|
+
if (env?.conf?.templates?.default?.sourceLinkToComment === true) return true;
|
|
327
|
+
} catch {
|
|
328
|
+
}
|
|
329
|
+
if (opts?.templates?.default?.sourceLinkToComment === true) return true;
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
function normalizeSectionOrder(raw) {
|
|
333
|
+
if (!Array.isArray(raw)) return void 0;
|
|
334
|
+
const out = raw.filter((s) => typeof s === "string").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
335
|
+
return out.length > 0 ? out : void 0;
|
|
336
|
+
}
|
|
337
|
+
function normalizeMenu(raw) {
|
|
338
|
+
if (!Array.isArray(raw)) return void 0;
|
|
339
|
+
const out = [];
|
|
340
|
+
for (const entry of raw) {
|
|
341
|
+
if (!entry || typeof entry !== "object") continue;
|
|
342
|
+
const o = entry;
|
|
343
|
+
const item = {};
|
|
344
|
+
if (typeof o.id === "string" && o.id.trim()) item.id = o.id.trim();
|
|
345
|
+
if (typeof o.title === "string" && o.title.trim()) item.title = o.title.trim();
|
|
346
|
+
const link = typeof o.link === "string" && o.link.trim() ? o.link.trim() : typeof o.href === "string" && o.href.trim() ? o.href.trim() : void 0;
|
|
347
|
+
if (link) item.link = link;
|
|
348
|
+
if (typeof o.icon === "string" && o.icon.trim()) item.icon = o.icon.trim();
|
|
349
|
+
if (item.id || item.link) out.push(item);
|
|
350
|
+
}
|
|
351
|
+
return out.length > 0 ? out : void 0;
|
|
352
|
+
}
|
|
353
|
+
var COPY_PAGE_ACTIONS = [
|
|
354
|
+
"copy",
|
|
355
|
+
"view",
|
|
356
|
+
"claude",
|
|
357
|
+
"chatgpt",
|
|
358
|
+
"perplexity"
|
|
359
|
+
];
|
|
360
|
+
function normalizeCopyPage(raw) {
|
|
361
|
+
if (raw === false) return { enabled: false };
|
|
362
|
+
if (raw === true || raw == null) return void 0;
|
|
363
|
+
if (typeof raw !== "object") return void 0;
|
|
364
|
+
const o = raw;
|
|
365
|
+
const config = {};
|
|
366
|
+
if (typeof o.enabled === "boolean") config.enabled = o.enabled;
|
|
367
|
+
if (Array.isArray(o.actions)) {
|
|
368
|
+
const seen = /* @__PURE__ */ new Set();
|
|
369
|
+
for (const a of o.actions) {
|
|
370
|
+
if (typeof a === "string" && COPY_PAGE_ACTIONS.includes(a)) {
|
|
371
|
+
seen.add(a);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
config.actions = COPY_PAGE_ACTIONS.filter((a) => seen.has(a));
|
|
375
|
+
}
|
|
376
|
+
return Object.keys(config).length > 0 ? config : void 0;
|
|
377
|
+
}
|
|
378
|
+
var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"]);
|
|
379
|
+
function computeRelPaths(absPaths) {
|
|
380
|
+
const out = /* @__PURE__ */ new Map();
|
|
381
|
+
if (absPaths.length === 0) return out;
|
|
382
|
+
const split = (p) => p.split(/[\\/]+/).filter((s) => s.length > 0);
|
|
383
|
+
const segLists = absPaths.map(split);
|
|
384
|
+
let common = segLists[0].slice(0, -1);
|
|
385
|
+
for (let i = 1; i < segLists.length && common.length > 0; i++) {
|
|
386
|
+
const segs = segLists[i];
|
|
387
|
+
let j = 0;
|
|
388
|
+
const max = Math.min(common.length, segs.length - 1);
|
|
389
|
+
while (j < max && common[j].toLowerCase() === segs[j].toLowerCase()) j++;
|
|
390
|
+
common = common.slice(0, j);
|
|
391
|
+
}
|
|
392
|
+
for (let i = 0; i < absPaths.length; i++) {
|
|
393
|
+
const segs = segLists[i];
|
|
394
|
+
const rel = common.length > 0 && segs.length > common.length ? segs.slice(common.length).join("/") : segs[segs.length - 1] ?? absPaths[i];
|
|
395
|
+
out.set(absPaths[i], rel);
|
|
396
|
+
}
|
|
397
|
+
return out;
|
|
398
|
+
}
|
|
399
|
+
async function collectSourceFiles(data) {
|
|
400
|
+
let doclets = [];
|
|
401
|
+
if (typeof data === "function") {
|
|
402
|
+
try {
|
|
403
|
+
doclets = data({}).get();
|
|
404
|
+
} catch {
|
|
405
|
+
try {
|
|
406
|
+
doclets = data().get();
|
|
407
|
+
} catch {
|
|
408
|
+
doclets = [];
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (!Array.isArray(doclets) || doclets.length === 0) return [];
|
|
413
|
+
const absSet = /* @__PURE__ */ new Set();
|
|
414
|
+
for (const d of doclets) {
|
|
415
|
+
const meta = d?.meta;
|
|
416
|
+
if (!meta || typeof meta.path !== "string" || typeof meta.filename !== "string") continue;
|
|
417
|
+
const filename = meta.filename;
|
|
418
|
+
const ext = extname(filename).toLowerCase();
|
|
419
|
+
if (ext.length > 0 && !SOURCE_EXTENSIONS.has(ext)) continue;
|
|
420
|
+
absSet.add(resolvePath(meta.path, filename));
|
|
421
|
+
}
|
|
422
|
+
if (absSet.size === 0) return [];
|
|
423
|
+
const absPaths = [...absSet];
|
|
424
|
+
const relPaths = computeRelPaths(absPaths);
|
|
425
|
+
const inputs = [];
|
|
426
|
+
for (const abs of absPaths) {
|
|
427
|
+
try {
|
|
428
|
+
const content = await readFile(abs, "utf8");
|
|
429
|
+
inputs.push({ absPath: abs, relPath: relPaths.get(abs) ?? abs, content });
|
|
430
|
+
} catch (err) {
|
|
431
|
+
console.warn(
|
|
432
|
+
`clean-jsdoc-theme: could not read source file '${abs}' \u2014 ${err.message}; skipping.`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
inputs.sort((a, b) => a.relPath.localeCompare(b.relPath));
|
|
437
|
+
return inputs;
|
|
438
|
+
}
|
|
439
|
+
var DOC_EXTENSIONS = /* @__PURE__ */ new Map([
|
|
440
|
+
[".md", "markdown"],
|
|
441
|
+
[".markdown", "markdown"],
|
|
442
|
+
[".html", "html"],
|
|
443
|
+
[".htm", "html"]
|
|
444
|
+
]);
|
|
445
|
+
var DOC_DIR_SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", ".svn", ".hg"]);
|
|
446
|
+
async function collectDocs(dir) {
|
|
447
|
+
if (typeof dir !== "string" || dir.trim().length === 0) return [];
|
|
448
|
+
const root = resolvePath(dir);
|
|
449
|
+
const docs = [];
|
|
450
|
+
const walk = async (absDir, relPrefix) => {
|
|
451
|
+
let entries;
|
|
452
|
+
try {
|
|
453
|
+
entries = await readdir(absDir, { withFileTypes: true });
|
|
454
|
+
} catch {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
for (const entry of entries) {
|
|
458
|
+
const name = entry.name;
|
|
459
|
+
if (name.startsWith(".")) continue;
|
|
460
|
+
if (entry.isDirectory()) {
|
|
461
|
+
if (DOC_DIR_SKIP.has(name)) continue;
|
|
462
|
+
await walk(joinPath(absDir, name), relPrefix ? `${relPrefix}/${name}` : name);
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
if (!entry.isFile()) continue;
|
|
466
|
+
const ext = extname(name).toLowerCase();
|
|
467
|
+
const type = DOC_EXTENSIONS.get(ext);
|
|
468
|
+
if (!type) continue;
|
|
469
|
+
const abs = joinPath(absDir, name);
|
|
470
|
+
const stem = name.slice(0, name.length - ext.length);
|
|
471
|
+
const relPath = relPrefix ? `${relPrefix}/${stem}` : stem;
|
|
472
|
+
try {
|
|
473
|
+
const content = await readFile(abs, "utf8");
|
|
474
|
+
docs.push({ path: relPath, content, type });
|
|
475
|
+
} catch (err) {
|
|
476
|
+
console.warn(
|
|
477
|
+
`clean-jsdoc-theme: could not read doc file '${abs}' \u2014 ${err.message}; skipping.`
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
await walk(root, "");
|
|
483
|
+
docs.sort((a, b) => a.path.localeCompare(b.path));
|
|
484
|
+
return docs;
|
|
485
|
+
}
|
|
486
|
+
function normalizeDocGroups(raw) {
|
|
487
|
+
return normalizeSectionOrder(raw);
|
|
488
|
+
}
|
|
489
|
+
async function publish(data, opts, tutorials) {
|
|
490
|
+
const destination = opts.destination;
|
|
491
|
+
if (!destination || typeof destination !== "string") {
|
|
492
|
+
throw new Error(
|
|
493
|
+
'clean-jsdoc-theme publish: opts.destination is required (set "opts.destination" in your jsdoc.json).'
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
const [
|
|
497
|
+
{ generateSite },
|
|
498
|
+
{ render, runPagefindAgainstDir },
|
|
499
|
+
{
|
|
500
|
+
validateThemeOpts,
|
|
501
|
+
createGoogleFontResolver,
|
|
502
|
+
formatDiagnostics,
|
|
503
|
+
formatBuildReport,
|
|
504
|
+
normalizeBasePath,
|
|
505
|
+
withBase
|
|
506
|
+
}
|
|
507
|
+
] = await Promise.all([loadSetu(), loadDwar(), loadUtils()]);
|
|
508
|
+
const basePath = normalizeBasePath(opts.basePath);
|
|
509
|
+
const hrefForServed = (servedPath) => withBase(basePath, "/" + servedPath);
|
|
510
|
+
const fontResolver = createGoogleFontResolver();
|
|
511
|
+
const { value, diagnostics } = await validateThemeOpts({
|
|
512
|
+
opts,
|
|
513
|
+
fontResolver,
|
|
514
|
+
unknownKeyPolicy: "suggest-typos",
|
|
515
|
+
knownNonThemeKeys: JSDOC_OWN_OPTS
|
|
516
|
+
});
|
|
517
|
+
const color = Boolean(process.stdout.isTTY) && opts.nocolor !== true;
|
|
518
|
+
const strict = opts.strict === true || opts.templates?.default?.strict === true;
|
|
519
|
+
if (diagnostics.list.length > 0) {
|
|
520
|
+
const formatted = formatDiagnostics(diagnostics, { color });
|
|
521
|
+
if (strict && diagnostics.hasErrors()) {
|
|
522
|
+
console.error(formatted);
|
|
523
|
+
throw new Error(
|
|
524
|
+
"clean-jsdoc-theme: opts validation failed in strict mode (see the diagnostics above). Fix the errors or unset `strict`."
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
console.log(formatted);
|
|
528
|
+
}
|
|
529
|
+
const pkg = await resolvePkg(data, opts);
|
|
530
|
+
const readme = typeof opts.readme === "string" && opts.readme.length > 0 ? opts.readme : void 0;
|
|
531
|
+
const tutorialTree = normalizeTutorials(tutorials);
|
|
532
|
+
const sources = outputSourceFilesEnabled(opts) ? await collectSourceFiles(data) : [];
|
|
533
|
+
const sourceLinkToComment = sourceLinkToCommentEnabled(opts);
|
|
534
|
+
const docsDir = typeof opts.docs === "string" && opts.docs.trim().length > 0 ? opts.docs.trim() : void 0;
|
|
535
|
+
const docs = docsDir ? await collectDocs(docsDir) : [];
|
|
536
|
+
const docGroups = normalizeDocGroups(opts.docGroups);
|
|
537
|
+
const defaultDocGroup = typeof opts.defaultDocGroup === "string" && opts.defaultDocGroup.trim().length > 0 ? opts.defaultDocGroup.trim() : void 0;
|
|
538
|
+
const sectionOrder = normalizeSectionOrder(opts.sectionOrder);
|
|
539
|
+
const menu = normalizeMenu(opts.menu);
|
|
540
|
+
const clubSidebarItems = opts.clubSidebarItems === true;
|
|
541
|
+
const manifest = generateSite(data, {
|
|
542
|
+
...pkg ? { pkg } : {},
|
|
543
|
+
...readme ? { readme } : {},
|
|
544
|
+
...tutorialTree.length > 0 ? { tutorials: tutorialTree } : {},
|
|
545
|
+
...sources.length > 0 ? { sources } : {},
|
|
546
|
+
...sources.length > 0 && sourceLinkToComment ? { sourceLinkToComment } : {},
|
|
547
|
+
...docs.length > 0 ? { docs } : {},
|
|
548
|
+
...docGroups ? { docGroups } : {},
|
|
549
|
+
...defaultDocGroup ? { defaultDocGroup } : {},
|
|
550
|
+
...sectionOrder ? { sectionOrder } : {},
|
|
551
|
+
...menu ? { menu } : {},
|
|
552
|
+
...clubSidebarItems ? { clubSidebarItems } : {}
|
|
553
|
+
});
|
|
554
|
+
const { siteName, files: logoFiles } = await prepareSiteName(value.siteName, hrefForServed);
|
|
555
|
+
const notGoogle = new Set(
|
|
556
|
+
diagnostics.list.filter((d) => d.code === "fonts/not-google" && d.path).map((d) => d.path)
|
|
557
|
+
);
|
|
558
|
+
const fonts = { ...value.fonts };
|
|
559
|
+
if (notGoogle.has("fonts.heading")) delete fonts.heading;
|
|
560
|
+
if (notGoogle.has("fonts.body")) delete fonts.body;
|
|
561
|
+
const customAssets = await resolveCustomAssets(opts, hrefForServed);
|
|
562
|
+
const absoluteDestination = resolvePath(destination);
|
|
563
|
+
const result = await render(manifest, {
|
|
564
|
+
theme: { ...resolveTheme(opts, siteName, fonts, basePath), ...customAssets.theme },
|
|
565
|
+
destination: absoluteDestination
|
|
566
|
+
});
|
|
567
|
+
const outputFiles = [...result.files, ...logoFiles, ...customAssets.files];
|
|
568
|
+
await writeOutputFiles(absoluteDestination, outputFiles);
|
|
569
|
+
const zlib = await import("zlib");
|
|
570
|
+
const gzipSizer = (b) => zlib.gzipSync(b).length;
|
|
571
|
+
console.log(
|
|
572
|
+
formatBuildReport({
|
|
573
|
+
files: outputFiles,
|
|
574
|
+
stats: result.stats,
|
|
575
|
+
destination,
|
|
576
|
+
gzipSizer,
|
|
577
|
+
color
|
|
578
|
+
})
|
|
579
|
+
);
|
|
580
|
+
if (result.errors && result.errors.length > 0) {
|
|
581
|
+
console.warn(
|
|
582
|
+
`clean-jsdoc-theme: ${result.errors.length} page(s) failed to render and were skipped:`
|
|
583
|
+
);
|
|
584
|
+
for (const e of result.errors) {
|
|
585
|
+
console.warn(` - ${e.slug}: ${e.message}`);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
try {
|
|
589
|
+
await runPagefindAgainstDir(absoluteDestination);
|
|
590
|
+
} catch (err) {
|
|
591
|
+
console.warn(`clean-jsdoc-theme: pagefind step skipped \u2014 ${err.message}`);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
export {
|
|
595
|
+
collectDocs,
|
|
596
|
+
computeRelPaths,
|
|
597
|
+
normalizeCopyPage,
|
|
598
|
+
normalizeDocGroups,
|
|
599
|
+
normalizeMenu,
|
|
600
|
+
normalizeSectionOrder,
|
|
601
|
+
outputSourceFilesEnabled,
|
|
602
|
+
publish,
|
|
603
|
+
sourceLinkToCommentEnabled
|
|
604
|
+
};
|
|
605
|
+
//# sourceMappingURL=publish.mjs.map
|