@gitpagedocs/cli 1.1.60 → 1.1.62

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.
@@ -8,12 +8,7 @@ import {
8
8
  withVersionBadge,
9
9
  normalizeToOutputPath,
10
10
  } from "./doc-path-resolver.mjs";
11
-
12
- /** True when `child` is the same as, or nested inside, `parent` (path-safe). */
13
- function isWithin(parent, child) {
14
- const rel = path.relative(parent, child);
15
- return !rel.startsWith("..") && !path.isAbsolute(rel);
16
- }
11
+ import { layoutsArtifactPaths } from "../contracts/layouts-paths.mjs";
17
12
 
18
13
  const DEFAULT_ICON_SVG = `<?xml version="1.0" encoding="utf-8"?>
19
14
  <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -57,6 +52,29 @@ export async function writeText(root, relativePath, data) {
57
52
  await writeFile(absolutePath, data, "utf-8");
58
53
  }
59
54
 
55
+ /**
56
+ * Write the local layout artifacts into the standalone layouts home.
57
+ *
58
+ * No layouts folder is ever deleted here. The legacy `<outputDir>/layouts/`
59
+ * folder can hold hand-edited templates and the viewer still reads it, so
60
+ * relocating it is an explicit, confirmed migration rather than a side effect of
61
+ * generating. Switching back to official layouts likewise leaves an existing
62
+ * layouts home in place: `layoutsConfigPathOficial` already decides which source
63
+ * the viewer uses, so the files are inert rather than harmful.
64
+ */
65
+ async function writeLayoutArtifacts(options) {
66
+ const { root, layoutsDir, useLocalLayoutConfig, layouts, artifacts, createThemeTemplate } = options;
67
+
68
+ if (!useLocalLayoutConfig) return;
69
+
70
+ const paths = layoutsArtifactPaths(layoutsDir);
71
+ await writeJson(root, paths.config, artifacts.layoutsConfig);
72
+ await writeJson(root, paths.fallbackConfig, artifacts.fallbackLayoutsConfig);
73
+ for (const layout of layouts) {
74
+ await writeJson(root, `${paths.root}/${layout.file}`, createThemeTemplate(layout));
75
+ }
76
+ }
77
+
60
78
  export async function writeConfigOnlyOutput(options) {
61
79
  const {
62
80
  root,
@@ -64,6 +82,7 @@ export async function writeConfigOnlyOutput(options) {
64
82
  outputDir,
65
83
  artifacts,
66
84
  useLocalLayoutConfig,
85
+ layoutsDir,
67
86
  layouts,
68
87
  createThemeTemplate,
69
88
  } = options;
@@ -78,20 +97,14 @@ export async function writeConfigOnlyOutput(options) {
78
97
 
79
98
  await writeJson(root, `${outputDir}/config.json`, artifacts.rootConfig);
80
99
  await writeText(root, `${outputDir}/icon.svg`, DEFAULT_ICON_SVG);
81
- const layoutsPath = path.join(root, outputDir, "layouts");
82
- if (useLocalLayoutConfig) {
83
- await writeJson(root, `${outputDir}/layouts/layoutsConfig.json`, artifacts.layoutsConfig);
84
- await writeJson(root, `${outputDir}/layouts/layoutsFallbackConfig.json`, artifacts.fallbackLayoutsConfig);
85
- for (const layout of layouts) {
86
- const template = createThemeTemplate(layout);
87
- await writeJson(root, `${outputDir}/layouts/${layout.file}`, template);
88
- }
89
- } else if (existsSync(layoutsPath) && !isWithin(root, pkgRoot)) {
90
- // Only clean a stale local layouts/ when the CLI runs from OUTSIDE the
91
- // project (a real install) — never when pkgRoot is inside the project being
92
- // generated (the gitpagedocs source repo), so committed layouts survive.
93
- rmSync(layoutsPath, { recursive: true, force: true });
94
- }
100
+ await writeLayoutArtifacts({
101
+ root,
102
+ layoutsDir,
103
+ useLocalLayoutConfig,
104
+ layouts,
105
+ artifacts,
106
+ createThemeTemplate,
107
+ });
95
108
 
96
109
  for (const [versionId, versionConfig] of Object.entries(artifacts.versionConfigs)) {
97
110
  await writeJson(root, `${outputDir}/docs/versions/${versionId}/config.json`, versionConfig);