clean-jsdoc-theme 5.0.3 → 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.
@@ -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) {
@@ -460,6 +451,15 @@ function sourceLinkToCommentEnabled(opts) {
460
451
  if (opts?.templates?.default?.sourceLinkToComment === true) return true;
461
452
  return false;
462
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
+ }
463
463
  function hasMarkdownPlugin(plugins) {
464
464
  if (!Array.isArray(plugins)) return false;
465
465
  return plugins.some((p) => typeof p === "string" && /(^|[\\/])markdown(\.js)?$/i.test(p.trim()));
@@ -1012,6 +1012,12 @@ async function publish(data, opts, tutorials) {
1012
1012
  ...docImageFiles,
1013
1013
  ...favicon?.files ?? []
1014
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
+ }
1015
1021
  await progress.stage("Writing files", () => writeOutputFiles(absoluteDestination, outputFiles));
1016
1022
  const zlib = await import("zlib");
1017
1023
  const gzipSizer = (b) => zlib.gzipSync(b).length;
@@ -1051,6 +1057,7 @@ async function publish(data, opts, tutorials) {
1051
1057
  }
1052
1058
  // Annotate the CommonJS export names for ESM import in node:
1053
1059
  0 && (module.exports = {
1060
+ cleanOutputDirEnabled,
1054
1061
  collectDocs,
1055
1062
  computeRelPaths,
1056
1063
  hasMarkdownPlugin,