@dogsbay/format-vitepress 0.2.0-beta.132 → 0.2.0-beta.133

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/dist/migrate.d.ts CHANGED
@@ -6,11 +6,17 @@
6
6
  * clock or network. Find the project with `@dogsbay/detect` first.
7
7
  */
8
8
  import type { ImportLedgerEntry } from "@dogsbay/types";
9
- import { type CorpusFiles } from "@dogsbay/corpus";
10
- export type { CorpusFiles } from "@dogsbay/corpus";
9
+ import { type CorpusFiles, type Unfetched } from "@dogsbay/corpus";
10
+ export type { CorpusFiles, Unfetched } from "@dogsbay/corpus";
11
11
  export interface MigrateInput {
12
12
  /** The project: paths relative to its root (a detection's `root`), text or bytes. */
13
13
  files: CorpusFiles;
14
+ /**
15
+ * Every path of the project (relative to the same root as `files`), when the host lists more
16
+ * than it fetched (a GitHub tree). The import then sees the repo as it is, and `unfetched`
17
+ * says what it needed from those not given: fetch them and call `migrate` again.
18
+ */
19
+ paths?: Iterable<string>;
14
20
  /** Defaults to the config's `title`, else "Docs". */
15
21
  siteName?: string;
16
22
  siteUrl?: string;
@@ -21,5 +27,14 @@ export interface MigrateResult {
21
27
  /** The Dogsbay project: dogsbay.config.yml, content/** (pages, nav.json, _assets), MIGRATION.md. */
22
28
  files: Map<string, string | Uint8Array>;
23
29
  ledger: ImportLedgerEntry[];
30
+ /**
31
+ * The listed `paths` the conversion needed but `files` did not hold. `read`: it read them,
32
+ * so fetch them and convert again (each round can find one more level of an include or
33
+ * `require` chain: cap the rounds). While `read` is not empty the result is not a
34
+ * conversion; when the import could not go on, `files` is empty and the ledger says where
35
+ * it stopped. `copy`: assets the output copies; fetch them for the finished files, no
36
+ * rerun. Both empty: the result is complete.
37
+ */
38
+ unfetched: Unfetched;
24
39
  }
25
40
  export declare function migrate(input: MigrateInput): Promise<MigrateResult>;
package/dist/migrate.js CHANGED
@@ -1,6 +1,11 @@
1
- import { corpusFromMap } from "@dogsbay/corpus";
1
+ import { corpusFromMap, unfetchedMessage } from "@dogsbay/corpus";
2
2
  import { dogsbayMdPageFiles, mountCopies } from "@dogsbay/format-dogsbay-md/browser";
3
3
  import { importVitepressCorpus } from "./import.js";
4
+ /** The ledger line for a conversion that still needs files, or nothing. */
5
+ function unfetchedLedger(read, stoppedOn) {
6
+ const message = unfetchedMessage(read, stoppedOn);
7
+ return message ? [{ severity: "warning", code: "unfetched", message }] : [];
8
+ }
4
9
  const yamlQuote = (s) => JSON.stringify(s);
5
10
  function buildConfig(siteName, siteUrl) {
6
11
  const lines = [`schemaVersion: 1`, `site:`, ` name: ${yamlQuote(siteName)}`, ` basePath: ""`];
@@ -39,16 +44,29 @@ function migrationNotes(a) {
39
44
  return lines.join("\n") + "\n";
40
45
  }
41
46
  export async function migrate(input) {
42
- const corpus = corpusFromMap(input.files);
43
- const imported = importVitepressCorpus(corpus);
47
+ const corpus = corpusFromMap(input.files, { paths: input.paths });
48
+ let imported;
49
+ try {
50
+ imported = importVitepressCorpus(corpus);
51
+ }
52
+ catch (e) {
53
+ // A file it needed was not given: that, not the error, is the answer
54
+ const read = corpus.missing();
55
+ if (read.length)
56
+ return { files: new Map(), ledger: unfetchedLedger(read, e), unfetched: { read, copy: [] } };
57
+ throw e;
58
+ }
44
59
  const siteName = input.siteName?.trim() || imported.siteName?.trim() || "Docs";
45
60
  const files = new Map();
46
61
  // Assets first, then the pages: `convert` copies the mounts before it writes the pages, so a
47
62
  // page wins over a file at the same path
63
+ const copy = [];
48
64
  for (const { from, to } of mountCopies(corpus.paths, imported.assetDirs)) {
49
65
  const bytes = input.files.get(from);
50
66
  if (bytes !== undefined)
51
67
  files.set(`content/${to}`, bytes);
68
+ else
69
+ copy.push(from);
52
70
  }
53
71
  for (const [path, text] of dogsbayMdPageFiles(imported.pages, imported.nav))
54
72
  files.set(`content/${path}`, text);
@@ -60,5 +78,6 @@ export async function migrate(input) {
60
78
  navSource: imported.navSource,
61
79
  ledger: imported.ledger,
62
80
  }));
63
- return { files, ledger: imported.ledger };
81
+ const read = corpus.missing();
82
+ return { files, ledger: [...unfetchedLedger(read), ...imported.ledger], unfetched: { read, copy: copy.sort() } };
64
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/format-vitepress",
3
- "version": "0.2.0-beta.132",
3
+ "version": "0.2.0-beta.133",
4
4
  "description": "VitePress format plugin for Dogsbay — imports VitePress docs projects into TreeNode[] by translating VitePress containers, code-fence conventions, snippets and includes to Dogsbay-MD.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,11 +24,11 @@
24
24
  "README.md"
25
25
  ],
26
26
  "dependencies": {
27
- "@dogsbay/detect": "0.2.0-beta.132",
28
- "@dogsbay/format-dogsbay-md": "0.2.0-beta.132",
29
- "@dogsbay/corpus": "0.2.0-beta.132",
30
- "@dogsbay/literal": "0.2.0-beta.132",
31
- "@dogsbay/types": "0.2.0-beta.132"
27
+ "@dogsbay/corpus": "0.2.0-beta.133",
28
+ "@dogsbay/format-dogsbay-md": "0.2.0-beta.133",
29
+ "@dogsbay/detect": "0.2.0-beta.133",
30
+ "@dogsbay/literal": "0.2.0-beta.133",
31
+ "@dogsbay/types": "0.2.0-beta.133"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^25.9.5",