dogsbay 0.2.0-beta.42 → 0.2.0-beta.44

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.
@@ -77,6 +77,17 @@ export async function migrateMkdocs(source, options) {
77
77
  console.log("Pass --force to overwrite.");
78
78
  process.exit(1);
79
79
  }
80
+ // On a --force re-run the existing dogsbay.config.yml carries
81
+ // deployment config the user owns — site.url + site.basePath —
82
+ // that has NO other source: it isn't in mkdocs.yml, and --site-url
83
+ // is deliberately not inherited from the source. Read it so a
84
+ // re-run that omits the flags preserves those values instead of
85
+ // silently resetting site.url to unset and basePath to /docs.
86
+ // Explicit --site-url / --base-path flags still win; a fresh
87
+ // migration (no existing config) is unaffected.
88
+ const existingDeployment = existingConfig
89
+ ? readExistingDeployment(existingConfig)
90
+ : {};
80
91
  console.log();
81
92
  console.log(pc.bold(`Migrating MkDocs site to Dogsbay-MD: ${siteName}`));
82
93
  console.log(`Source: ${sourceDir}`);
@@ -99,7 +110,15 @@ export async function migrateMkdocs(source, options) {
99
110
  // snippets, macros, autodoc, variants — see @dogsbay/format-
100
111
  // mkdocs's CLAUDE.md) runs identically to import-mkdocs; only
101
112
  // the final write target differs.
102
- const { pageCount, lossy } = await collectAndWriteContent(sourceDir, fullDocsDir, outputDir, config, { inlineAutodoc: options.inlineAutodoc ?? false });
113
+ // Lift the mkdocstrings Python handler options from mkdocs.yml.
114
+ // These become the project-level `autodoc.python` config block and
115
+ // also feed `--inline-autodoc`'s parser globalOptions — see
116
+ // plans/autodoc-mkdocstrings-options.md.
117
+ const autodocPythonOptions = extractAutodocOptions(config);
118
+ const { pageCount, lossy } = await collectAndWriteContent(sourceDir, fullDocsDir, outputDir, config, {
119
+ inlineAutodoc: options.inlineAutodoc ?? false,
120
+ autodocPythonOptions,
121
+ });
103
122
  console.log(pc.green(`Wrote`) + ` ${pageCount} pages to ./content/ as Dogsbay-MD`);
104
123
  // 3. Convert MkDocs nav: → ./content/nav.yml in canonical
105
124
  // single-key-map shape (- Label: file.md / nested children).
@@ -139,13 +158,18 @@ export async function migrateMkdocs(source, options) {
139
158
  // site.url is left unset and the build emits relative URLs.
140
159
  // sourceSiteUrl is kept only to warn the user it was dropped.
141
160
  const sourceSiteUrl = config.site_url || undefined;
142
- const siteUrl = options.siteUrl || undefined;
161
+ // Precedence: --site-url flag existing config (--force re-run) →
162
+ // unset. Never the source mkdocs.yml's site_url.
163
+ const siteUrl = options.siteUrl || existingDeployment.siteUrl || undefined;
143
164
  const repoUrl = config.repo_url || undefined;
144
- // --base-path controls where docs sit under the host. Default
145
- // /docs (matches every scaffolded dogsbay site); pass --base-path
146
- // "" to serve at the host root — common for a dedicated repo or
147
- // GitHub Pages project site.
148
- const basePath = options.basePath !== undefined ? options.basePath : "/docs";
165
+ // --base-path controls where docs sit under the host. Precedence:
166
+ // --base-path flag existing config (--force re-run) /docs
167
+ // default (matches every scaffolded dogsbay site). Pass
168
+ // --base-path "" to serve at the host root — common for a
169
+ // dedicated repo or GitHub Pages project site.
170
+ const basePath = options.basePath !== undefined
171
+ ? options.basePath
172
+ : existingDeployment.basePath ?? "/docs";
149
173
  const siteDescription = config.site_description || undefined;
150
174
  const dogsbayConfig = {
151
175
  schemaVersion: 1,
@@ -163,9 +187,29 @@ export async function migrateMkdocs(source, options) {
163
187
  llmsTxt: true,
164
188
  mdMirror: true,
165
189
  },
190
+ // Project-level autodoc render options lifted from the source
191
+ // mkdocs.yml's mkdocstrings handler. resolve-autodoc applies
192
+ // these under per-directive props so migrated reference pages
193
+ // render with the same signature/member-order behaviour the
194
+ // MkDocs site configured. Omitted when the source declared no
195
+ // renderer-relevant options.
196
+ ...(autodocPythonOptions
197
+ ? { autodoc: { python: autodocPythonOptions } }
198
+ : {}),
166
199
  };
167
200
  writeFileSync(join(outputDir, "dogsbay.config.yml"), serializeConfig(dogsbayConfig, "yaml"));
168
201
  console.log(pc.green(`Wrote`) + ` dogsbay.config.yml`);
202
+ // Surface preserved deployment config so a --force re-run isn't a
203
+ // silent black box — the user sees what carried over.
204
+ if (!options.siteUrl && existingDeployment.siteUrl) {
205
+ console.log(pc.green(`Kept`) +
206
+ ` site.url from the existing config: ${existingDeployment.siteUrl}`);
207
+ }
208
+ if (options.basePath === undefined &&
209
+ existingDeployment.basePath !== undefined) {
210
+ console.log(pc.green(`Kept`) +
211
+ ` site.basePath from the existing config: "${existingDeployment.basePath}"`);
212
+ }
169
213
  if (sourceSiteUrl && !siteUrl) {
170
214
  console.log(pc.yellow(`Note:`) +
171
215
  ` source site_url (${sourceSiteUrl}) was not carried over —` +
@@ -304,8 +348,16 @@ async function collectAndWriteContent(sourceDir, fullDocsDir, outputDir, mkdocsC
304
348
  if (opts.inlineAutodoc && autodocSourceRootAbs) {
305
349
  // Snapshot mode: resolve at migration time. The resolved api-*
306
350
  // TreeNodes serialize to Dogsbay-MD `:::api-*` directives via
307
- // format-dogsbay-md's Phase 4a cases.
308
- parseOpts.autodoc = { sourceRoot: autodocSourceRootAbs };
351
+ // format-dogsbay-md's Phase 4a cases. globalOptions carries the
352
+ // mkdocstrings handler options so the snapshot matches what the
353
+ // MkDocs site configured (members_order, merge_init_into_class,
354
+ // …) rather than the bare mkdocstrings defaults.
355
+ parseOpts.autodoc = {
356
+ sourceRoot: autodocSourceRootAbs,
357
+ ...(opts.autodocPythonOptions
358
+ ? { globalOptions: opts.autodocPythonOptions }
359
+ : {}),
360
+ };
309
361
  }
310
362
  // Preserve mode (default): no `autodoc` in parseOpts. The `:::`
311
363
  // paragraphs stay as raw text; we walk them in post-process and
@@ -453,6 +505,84 @@ function extractMkdocstringsConfig(mkdocsConfig) {
453
505
  }
454
506
  return null;
455
507
  }
508
+ /**
509
+ * snake_case mkdocstrings handler option → camelCase Dogsbay
510
+ * `AutodocPythonOptions` key. Options the autodoc renderer doesn't
511
+ * understand (e.g. `extensions`, `preload_modules`,
512
+ * `docstring_section_style`) are intentionally absent — they fall
513
+ * through and are dropped. Mirrors the map in
514
+ * `format-mkdocs/src/importer.ts` so `migrate-mkdocs` and
515
+ * `import-mkdocs` honour the same handler options.
516
+ */
517
+ const MKDOCSTRINGS_OPTION_MAP = {
518
+ show_source: "showSource",
519
+ show_bases: "showBases",
520
+ show_signature: "showSignature",
521
+ unwrap_annotated: "unwrapAnnotated",
522
+ group_by_category: "groupByCategory",
523
+ show_root_full_path: "showRootFullPath",
524
+ show_root_heading: "showRootHeading",
525
+ show_if_no_docstring: "showIfNoDocstring",
526
+ inherited_members: "inheritedMembers",
527
+ merge_init_into_class: "mergeInitIntoClass",
528
+ separate_signature: "separateSignature",
529
+ members_order: "membersOrder",
530
+ filters: "filters",
531
+ heading_level: "headingLevel",
532
+ };
533
+ /**
534
+ * Lift the mkdocstrings Python handler `options:` block out of
535
+ * mkdocs.yml and map it to `AutodocPythonOptions`.
536
+ *
537
+ * A MkDocs site configures the handler once; `import-mkdocs` threads
538
+ * those options into the autodoc renderer as `globalOptions`. Without
539
+ * this, migrated `:::autodoc` directives fall back to the bare
540
+ * mkdocstrings defaults (`merge_init_into_class: false`,
541
+ * `members_order: alphabetical`) — the reference pages lose the
542
+ * expanded constructor signature and the document-order member list.
543
+ *
544
+ * Returns null when mkdocstrings isn't declared or sets no
545
+ * renderer-relevant options. See plans/autodoc-mkdocstrings-options.md.
546
+ */
547
+ function extractAutodocOptions(mkdocsConfig) {
548
+ const mkdocstrings = extractMkdocstringsConfig(mkdocsConfig);
549
+ if (!mkdocstrings)
550
+ return null;
551
+ const raw = mkdocstrings.handlers?.python?.options;
552
+ if (!raw || typeof raw !== "object")
553
+ return null;
554
+ const src = raw;
555
+ const out = {};
556
+ for (const [snake, camel] of Object.entries(MKDOCSTRINGS_OPTION_MAP)) {
557
+ if (src[snake] !== undefined)
558
+ out[camel] = src[snake];
559
+ }
560
+ return Object.keys(out).length > 0 ? out : null;
561
+ }
562
+ /**
563
+ * Read the user-owned deployment config — `site.url` + `site.basePath`
564
+ * — out of an existing `dogsbay.config.yml` so a `--force` re-run can
565
+ * preserve them when the `--site-url` / `--base-path` flags are
566
+ * omitted.
567
+ *
568
+ * Lenient on purpose: `YAML.parse` reads both .yml and .json (JSON is
569
+ * valid YAML), and an unparseable / unexpected-shape config falls
570
+ * through to `{}` rather than aborting the migration — a re-run
571
+ * should never be blocked by a stale config it's about to overwrite.
572
+ */
573
+ function readExistingDeployment(configPath) {
574
+ try {
575
+ const parsed = YAML.parse(readFileSync(configPath, "utf-8"));
576
+ const site = parsed?.site;
577
+ return {
578
+ siteUrl: typeof site?.url === "string" ? site.url : undefined,
579
+ basePath: typeof site?.basePath === "string" ? site.basePath : undefined,
580
+ };
581
+ }
582
+ catch {
583
+ return {};
584
+ }
585
+ }
456
586
  /**
457
587
  * Extract macros plugin data file mappings from mkdocs.yml.
458
588
  * Returns { varName: absolutePath } for each `include_yaml` entry,
@@ -850,7 +980,18 @@ function buildMigrationNotes(args) {
850
980
  }
851
981
  lines.push("Set the destination URL in `dogsbay.config.yml`:", "", "```yaml", "site:", " url: https://you.github.io/your-repo # drives sitemap, llms.txt, canonical", ` basePath: ${basePath || '""'}`, "```", "", "Or re-run the migration with `--site-url` (and optionally", "`--base-path`).", "");
852
982
  }
853
- lines.push("## Re-running the migration", "", "If you find a regression and we ship a fix, re-run with `--force`:", "", "```bash", `npx dogsbay migrate-mkdocs ${sourceDir} --output ${outputDir} --force`, "```", "", "Note that `--force` overwrites all generated files; any hand edits", "to `./content/*.md` since the last migration will be lost. Commit", "your work first.", "");
983
+ // Re-run command spell out the deployment flags so the
984
+ // documented command reproduces the same site.url / basePath even
985
+ // against a fresh output dir. (A bare `--force` re-run also
986
+ // preserves them now, read back from the existing config — see the
987
+ // note below — but a self-contained command is the safer thing to
988
+ // copy.)
989
+ const rerunFlags = ["--output", outputDir, "--force"];
990
+ if (siteUrl)
991
+ rerunFlags.push("--site-url", siteUrl);
992
+ if (basePath !== "/docs")
993
+ rerunFlags.push("--base-path", `"${basePath}"`);
994
+ lines.push("## Re-running the migration", "", "If you find a regression and a later release fixes it, re-run", "with `--force`:", "", "```bash", `npx dogsbay migrate-mkdocs ${sourceDir} ${rerunFlags.join(" ")}`, "```", "", "`--force` overwrites all generated files; any hand edits to", "`./content/*.md` since the last migration will be lost — commit", "your work first.", "", "Your deployment config is preserved across a re-run: `site.url`", "and `site.basePath` are read back from the existing", "`dogsbay.config.yml` when the `--site-url` / `--base-path` flags", "are omitted (the flags still win when passed). Everything else in", "the config is re-derived from the source `mkdocs.yml`.", "");
854
995
  if (lossy.length > 0) {
855
996
  lines.push("## Known limitations", "");
856
997
  lines.push("The following files have content that didn't fully round-trip", "into Dogsbay-MD. Review each one and fix manually:", "");
@@ -176,6 +176,10 @@ export async function siteBuild(cwd, options) {
176
176
  const { resolveAutodocRefs } = await import("../resolve-autodoc.js");
177
177
  const autodocResult = await resolveAutodocRefs(pages, {
178
178
  configDir: dirname(configPath),
179
+ // Project-level autodoc render options (lifted from the source
180
+ // mkdocs.yml by migrate-mkdocs). Layered under per-directive
181
+ // props — see plans/autodoc-mkdocstrings-options.md.
182
+ pythonOptions: config.autodoc?.python,
179
183
  });
180
184
  if (autodocResult.resolved > 0 || autodocResult.failed > 0) {
181
185
  const parts = [];
@@ -94,6 +94,7 @@ function validate(parsed, sourcePath) {
94
94
  throw new Error(`analytics must be an object in ${sourcePath}`);
95
95
  }
96
96
  const agent = validateAgent(obj.agent, sourcePath);
97
+ const autodoc = validateAutodoc(obj.autodoc, sourcePath);
97
98
  const taxonomies = validateTaxonomies(obj.taxonomies, sourcePath);
98
99
  const propSchema = validatePropSchema(obj.propSchema, sourcePath);
99
100
  const plugins = validatePlugins(obj.plugins, sourcePath);
@@ -108,11 +109,66 @@ function validate(parsed, sourcePath) {
108
109
  deploy: obj.deploy,
109
110
  analytics: obj.analytics,
110
111
  agent,
112
+ autodoc,
111
113
  taxonomies,
112
114
  propSchema,
113
115
  plugins,
114
116
  };
115
117
  }
118
+ /**
119
+ * Validate the optional `autodoc:` block. One sub-block per language
120
+ * handler — only `python` exists today. Field names mirror
121
+ * `AutodocPythonOptions`; type-checked individually so a typo'd
122
+ * boolean doesn't silently flip a render default.
123
+ */
124
+ function validateAutodoc(raw, sourcePath) {
125
+ if (raw === undefined)
126
+ return undefined;
127
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
128
+ throw new Error(`autodoc must be an object in ${sourcePath}`);
129
+ }
130
+ const a = raw;
131
+ if (a.python === undefined)
132
+ return {};
133
+ if (typeof a.python !== "object" || a.python === null || Array.isArray(a.python)) {
134
+ throw new Error(`autodoc.python must be an object in ${sourcePath}`);
135
+ }
136
+ const p = a.python;
137
+ const booleanKeys = [
138
+ "mergeInitIntoClass",
139
+ "separateSignature",
140
+ "unwrapAnnotated",
141
+ "inheritedMembers",
142
+ "showIfNoDocstring",
143
+ "showRootHeading",
144
+ "showRootFullPath",
145
+ "showBases",
146
+ "showSource",
147
+ "showSignature",
148
+ "groupByCategory",
149
+ ];
150
+ for (const key of booleanKeys) {
151
+ if (p[key] !== undefined && typeof p[key] !== "boolean") {
152
+ throw new Error(`autodoc.python.${key} must be a boolean in ${sourcePath}`);
153
+ }
154
+ }
155
+ if (p.membersOrder !== undefined &&
156
+ p.membersOrder !== "source" &&
157
+ p.membersOrder !== "alphabetical") {
158
+ throw new Error(`autodoc.python.membersOrder must be "source" or "alphabetical" ` +
159
+ `in ${sourcePath}; got ${JSON.stringify(p.membersOrder)}`);
160
+ }
161
+ if (p.headingLevel !== undefined && typeof p.headingLevel !== "number") {
162
+ throw new Error(`autodoc.python.headingLevel must be a number in ${sourcePath}`);
163
+ }
164
+ if (p.filters !== undefined) {
165
+ if (!Array.isArray(p.filters) ||
166
+ p.filters.some((f) => typeof f !== "string")) {
167
+ throw new Error(`autodoc.python.filters must be an array of strings in ${sourcePath}`);
168
+ }
169
+ }
170
+ return { python: p };
171
+ }
116
172
  function validatePlugins(raw, sourcePath) {
117
173
  if (raw === undefined)
118
174
  return undefined;
@@ -75,6 +75,7 @@ export async function resolveAutodocRefs(pages, options) {
75
75
  for (const page of pages) {
76
76
  await walkAndResolve(page.tree, {
77
77
  configDir: options.configDir,
78
+ pythonOptions: options.pythonOptions,
78
79
  md,
79
80
  onResolved: () => {
80
81
  resolved++;
@@ -187,16 +188,21 @@ async function resolveOne(node, ctx) {
187
188
  // Resolve against configDir so the resolver doesn't depend on
188
189
  // process.cwd().
189
190
  const sourceRoot = resolvePath(ctx.configDir, sourceRootRaw);
190
- // Pull rendering options from props, layered on top of the
191
- // mkdocstrings-compatible defaults. tree-builder.ts uses
192
- // truthy-checks for several of these (e.g. `if (options.showSource
193
- // && symbol.sourceText) { ... }`) — without the defaults the
194
- // collapsible source-code block, attribute signatures, and class
195
- // bases all silently drop. The defaults mirror format-mkdocs/
196
- // src/loader.ts processAutodocDirectives so the migrated
197
- // output matches the legacy import-mkdocs output by default.
191
+ // Layer rendering options, lowest highest precedence:
192
+ // 1. AUTODOC_RENDER_DEFAULTS — bare mkdocstrings defaults.
193
+ // tree-builder.ts truthy-checks several of these, so without
194
+ // them the collapsible source block, attribute signatures,
195
+ // and class bases silently drop.
196
+ // 2. ctx.pythonOptions project-level `config.autodoc.python`,
197
+ // lifted by migrate-mkdocs from the source mkdocs.yml's
198
+ // mkdocstrings handler (members_order, merge_init_into_class,
199
+ // …). This is what makes a migrated reference page match the
200
+ // original instead of the bare-defaults render.
201
+ // 3. props — the per-directive `:::autodoc` YAML body, so an
202
+ // individual symbol can still override the project default.
198
203
  const renderOptions = {
199
204
  ...AUTODOC_RENDER_DEFAULTS,
205
+ ...(ctx.pythonOptions ?? {}),
200
206
  ...props,
201
207
  };
202
208
  delete renderOptions.ref;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dogsbay",
3
- "version": "0.2.0-beta.42",
3
+ "version": "0.2.0-beta.44",
4
4
  "description": "CLI for Dogsbay — scaffold, build, and serve documentation sites with markdown / MkDocs / Obsidian / OpenAPI sources",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,15 +32,15 @@
32
32
  "picocolors": "^1.1.0",
33
33
  "prompts": "^2.4.2",
34
34
  "yaml": "^2.8.3",
35
- "@dogsbay/autodoc-python": "0.2.0-beta.42",
36
- "@dogsbay/format-mkdocs": "0.2.0-beta.42",
37
- "@dogsbay/format-obsidian": "0.2.0-beta.42",
38
- "@dogsbay/format-astro": "0.2.0-beta.42",
39
- "@dogsbay/format-mdx": "0.2.0-beta.42",
40
- "@dogsbay/format-starlight": "0.2.0-beta.42",
41
- "@dogsbay/format-dogsbay-md": "0.2.0-beta.42",
42
- "@dogsbay/format-openapi": "0.2.0-beta.42",
43
- "@dogsbay/types": "0.2.0-beta.42"
35
+ "@dogsbay/autodoc-python": "0.2.0-beta.44",
36
+ "@dogsbay/format-mkdocs": "0.2.0-beta.44",
37
+ "@dogsbay/format-astro": "0.2.0-beta.44",
38
+ "@dogsbay/format-obsidian": "0.2.0-beta.44",
39
+ "@dogsbay/format-mdx": "0.2.0-beta.44",
40
+ "@dogsbay/format-starlight": "0.2.0-beta.44",
41
+ "@dogsbay/format-dogsbay-md": "0.2.0-beta.44",
42
+ "@dogsbay/format-openapi": "0.2.0-beta.44",
43
+ "@dogsbay/types": "0.2.0-beta.44"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/markdown-it": "^14.1.0",