clean-jsdoc-theme 5.0.2 → 5.0.4

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 CHANGED
@@ -85,9 +85,6 @@ npx serve dist
85
85
  - **FAQ & recipes** — [**ankdev.me/clean-jsdoc-theme/guides/faq**](https://ankdev.me/clean-jsdoc-theme/guides/faq): how to embed CodePen / YouTube / sites, write rich doc comments (callouts, steps), and common config tweaks.
86
86
  - **Live demo** — [**ankdev.me/clean-jsdoc-theme/api-docs**](https://ankdev.me/clean-jsdoc-theme/api-docs): a real generated API reference, so you can see the output before installing.
87
87
 
88
- > **v5 is in alpha.** To stay on v4, pin `"clean-jsdoc-theme": "^4"` in your
89
- > `package.json`. Every past release is tagged, so you can check out the matching
90
- > git tag to browse the v4 source.
91
88
 
92
89
  ## License
93
90
 
@@ -1,4 +1,4 @@
1
- import { OutputFile, ThemeColors, CopyPageConfig, MetaTag, PageNavConfig, ThemeConfig, SiteLogo } from '@clean-jsdoc-theme/dwar';
1
+ import { OutputFile, SiteLogo, ThemeColors, CopyPageConfig, MetaTag, PageNavConfig, ThemeConfig } from '@clean-jsdoc-theme/dwar';
2
2
  import { DocInput, MenuItem, PlaygroundSiteConfig } from '@clean-jsdoc-theme/setu';
3
3
 
4
4
  interface JSDocOpts {
@@ -188,11 +188,14 @@ interface JSDocOpts {
188
188
  * - `sourceLinkToComment` — defaults to `false`. By default a `Source:`
189
189
  * link lands on the first line of the declaration; set `true` to point it
190
190
  * at the doclet's doc-comment line instead (the pre-v5 behavior).
191
+ * - `cleanOutputDir` — defaults to `true`; set `false` to keep existing files
192
+ * in the destination instead of emptying it before each build.
191
193
  */
192
194
  templates?: {
193
195
  default?: {
194
196
  outputSourceFiles?: unknown;
195
197
  sourceLinkToComment?: unknown;
198
+ cleanOutputDir?: unknown;
196
199
  };
197
200
  };
198
201
  [key: string]: unknown;
@@ -247,6 +250,15 @@ declare function outputSourceFilesEnabled(opts: JSDocOpts): boolean;
247
250
  * is exactly `=== true`; otherwise `false` (the default: links jump to code).
248
251
  */
249
252
  declare function sourceLinkToCommentEnabled(opts: JSDocOpts): boolean;
253
+ /**
254
+ * Resolve `templates.default.cleanOutputDir`. Probed in the same priority order
255
+ * as {@link outputSourceFilesEnabled} (canonical `jsdoc/env` conf, then a nested
256
+ * `opts.templates` fallback). Defaults to `true` — the build empties its
257
+ * destination first so a page removed or renamed between runs (e.g. a deleted
258
+ * class, or a stale content-hashed `styles.<hash>.css`) doesn't linger in the
259
+ * served site. Resolves to `false` ONLY when one is exactly `=== false`.
260
+ */
261
+ declare function cleanOutputDirEnabled(opts: JSDocOpts): boolean;
250
262
  /**
251
263
  * Whether a JSDoc `conf.plugins` list enables the bundled `plugins/markdown`
252
264
  * plugin. The theme relies on it: JSDoc runs `plugins/markdown` to convert the
@@ -379,4 +391,4 @@ declare function overlayDocs(base: ResolvedDocs, locale: ResolvedDocs): Resolved
379
391
  declare function normalizeDocGroups(raw: unknown): string[] | undefined;
380
392
  declare function publish(data: unknown, opts: JSDocOpts, tutorials?: unknown): Promise<void>;
381
393
 
382
- export { type ResolvedDocs, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizeMeta, normalizePageNav, normalizePlayground, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, resolveFavicon, resolveFooter, sourceLinkToCommentEnabled };
394
+ export { type ResolvedDocs, cleanOutputDirEnabled, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizeMeta, normalizePageNav, normalizePlayground, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, resolveFavicon, resolveFooter, sourceLinkToCommentEnabled };
package/dist/publish.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OutputFile, ThemeColors, CopyPageConfig, MetaTag, PageNavConfig, ThemeConfig, SiteLogo } from '@clean-jsdoc-theme/dwar';
1
+ import { OutputFile, SiteLogo, ThemeColors, CopyPageConfig, MetaTag, PageNavConfig, ThemeConfig } from '@clean-jsdoc-theme/dwar';
2
2
  import { DocInput, MenuItem, PlaygroundSiteConfig } from '@clean-jsdoc-theme/setu';
3
3
 
4
4
  interface JSDocOpts {
@@ -188,11 +188,14 @@ interface JSDocOpts {
188
188
  * - `sourceLinkToComment` — defaults to `false`. By default a `Source:`
189
189
  * link lands on the first line of the declaration; set `true` to point it
190
190
  * at the doclet's doc-comment line instead (the pre-v5 behavior).
191
+ * - `cleanOutputDir` — defaults to `true`; set `false` to keep existing files
192
+ * in the destination instead of emptying it before each build.
191
193
  */
192
194
  templates?: {
193
195
  default?: {
194
196
  outputSourceFiles?: unknown;
195
197
  sourceLinkToComment?: unknown;
198
+ cleanOutputDir?: unknown;
196
199
  };
197
200
  };
198
201
  [key: string]: unknown;
@@ -247,6 +250,15 @@ declare function outputSourceFilesEnabled(opts: JSDocOpts): boolean;
247
250
  * is exactly `=== true`; otherwise `false` (the default: links jump to code).
248
251
  */
249
252
  declare function sourceLinkToCommentEnabled(opts: JSDocOpts): boolean;
253
+ /**
254
+ * Resolve `templates.default.cleanOutputDir`. Probed in the same priority order
255
+ * as {@link outputSourceFilesEnabled} (canonical `jsdoc/env` conf, then a nested
256
+ * `opts.templates` fallback). Defaults to `true` — the build empties its
257
+ * destination first so a page removed or renamed between runs (e.g. a deleted
258
+ * class, or a stale content-hashed `styles.<hash>.css`) doesn't linger in the
259
+ * served site. Resolves to `false` ONLY when one is exactly `=== false`.
260
+ */
261
+ declare function cleanOutputDirEnabled(opts: JSDocOpts): boolean;
250
262
  /**
251
263
  * Whether a JSDoc `conf.plugins` list enables the bundled `plugins/markdown`
252
264
  * plugin. The theme relies on it: JSDoc runs `plugins/markdown` to convert the
@@ -379,4 +391,4 @@ declare function overlayDocs(base: ResolvedDocs, locale: ResolvedDocs): Resolved
379
391
  declare function normalizeDocGroups(raw: unknown): string[] | undefined;
380
392
  declare function publish(data: unknown, opts: JSDocOpts, tutorials?: unknown): Promise<void>;
381
393
 
382
- export { type ResolvedDocs, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizeMeta, normalizePageNav, normalizePlayground, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, resolveFavicon, resolveFooter, sourceLinkToCommentEnabled };
394
+ export { type ResolvedDocs, cleanOutputDirEnabled, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizeMeta, normalizePageNav, normalizePlayground, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, resolveFavicon, resolveFooter, sourceLinkToCommentEnabled };
package/dist/publish.js CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/publish.ts
31
31
  var publish_exports = {};
32
32
  __export(publish_exports, {
33
+ cleanOutputDirEnabled: () => cleanOutputDirEnabled,
33
34
  collectDocs: () => collectDocs,
34
35
  computeRelPaths: () => computeRelPaths,
35
36
  hasMarkdownPlugin: () => hasMarkdownPlugin,
@@ -72,18 +73,8 @@ async function writeOutputFiles(destination, files) {
72
73
  var JSDOC_TUTORIAL_TYPE_MARKDOWN = 2;
73
74
  function anchorPath() {
74
75
  if (typeof __filename === "string") return __filename;
75
- try {
76
- const getEsmUrl = new Function(
77
- "try { return import.meta && import.meta.url; } catch { return undefined; }"
78
- );
79
- const url = getEsmUrl();
80
- if (typeof url === "string" && url.startsWith("file://")) {
81
- return (0, import_node_url.fileURLToPath)(url);
82
- }
83
- } catch {
84
- }
85
76
  throw new Error(
86
- "clean-jsdoc-theme: could not determine the running module path (neither __filename nor import.meta.url resolved)."
77
+ "clean-jsdoc-theme: could not determine the running module path (__filename is unavailable)."
87
78
  );
88
79
  }
89
80
  function resolvePackageDir(name) {
@@ -149,6 +140,7 @@ var loadUtils = () => loadDep("@clean-jsdoc-theme/utils", [
149
140
  "createGoogleFontResolver",
150
141
  "formatDiagnostics",
151
142
  "formatBuildReport",
143
+ "formatRenderError",
152
144
  "normalizeBasePath",
153
145
  "withBase",
154
146
  "toExtractManifest"
@@ -459,6 +451,15 @@ function sourceLinkToCommentEnabled(opts) {
459
451
  if (opts?.templates?.default?.sourceLinkToComment === true) return true;
460
452
  return false;
461
453
  }
454
+ function cleanOutputDirEnabled(opts) {
455
+ try {
456
+ const env = require("jsdoc/env");
457
+ if (env?.conf?.templates?.default?.cleanOutputDir === false) return false;
458
+ } catch {
459
+ }
460
+ if (opts?.templates?.default?.cleanOutputDir === false) return false;
461
+ return true;
462
+ }
462
463
  function hasMarkdownPlugin(plugins) {
463
464
  if (!Array.isArray(plugins)) return false;
464
465
  return plugins.some((p) => typeof p === "string" && /(^|[\\/])markdown(\.js)?$/i.test(p.trim()));
@@ -850,6 +851,7 @@ async function publish(data, opts, tutorials) {
850
851
  createGoogleFontResolver,
851
852
  formatDiagnostics,
852
853
  formatBuildReport,
854
+ formatRenderError,
853
855
  normalizeBasePath,
854
856
  withBase,
855
857
  toExtractManifest
@@ -1010,6 +1012,12 @@ async function publish(data, opts, tutorials) {
1010
1012
  ...docImageFiles,
1011
1013
  ...favicon?.files ?? []
1012
1014
  ];
1015
+ if (!buildSpec && cleanOutputDirEnabled(opts)) {
1016
+ await progress.stage(
1017
+ "Cleaning output",
1018
+ () => (0, import_promises2.rm)(absoluteDestination, { recursive: true, force: true })
1019
+ );
1020
+ }
1013
1021
  await progress.stage("Writing files", () => writeOutputFiles(absoluteDestination, outputFiles));
1014
1022
  const zlib = await import("zlib");
1015
1023
  const gzipSizer = (b) => zlib.gzipSync(b).length;
@@ -1027,7 +1035,15 @@ async function publish(data, opts, tutorials) {
1027
1035
  `clean-jsdoc-theme: ${result.errors.length} page(s) failed to render and were skipped:`
1028
1036
  );
1029
1037
  for (const e of result.errors) {
1030
- console.warn(` - ${e.slug}: ${e.message}`);
1038
+ console.warn(formatRenderError(e));
1039
+ }
1040
+ }
1041
+ if (result.warnings && result.warnings.length > 0) {
1042
+ console.warn(
1043
+ `clean-jsdoc-theme: ${result.warnings.length} content warning(s) (non-fatal):`
1044
+ );
1045
+ for (const w of result.warnings) {
1046
+ console.warn(formatRenderError(w));
1031
1047
  }
1032
1048
  }
1033
1049
  try {
@@ -1041,6 +1057,7 @@ async function publish(data, opts, tutorials) {
1041
1057
  }
1042
1058
  // Annotate the CommonJS export names for ESM import in node:
1043
1059
  0 && (module.exports = {
1060
+ cleanOutputDirEnabled,
1044
1061
  collectDocs,
1045
1062
  computeRelPaths,
1046
1063
  hasMarkdownPlugin,