@dogsbay/commands 0.2.0-beta.181 → 0.2.0-beta.183
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/commands/refactor-files.d.ts +6 -0
- package/dist/commands/refactor-files.js +67 -138
- package/dist/commands/validate.js +1 -84
- package/dist/edits.d.ts +16 -1
- package/dist/edits.js +91 -29
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -2
- package/dist/indexes.d.ts +10 -0
- package/dist/indexes.js +42 -4
- package/dist/node-storage.d.ts +7 -0
- package/dist/node-storage.js +28 -0
- package/dist/refactor-entry.d.ts +13 -0
- package/dist/refactor-entry.js +13 -0
- package/dist/refactor.d.ts +64 -0
- package/dist/refactor.js +428 -0
- package/dist/site-layout.d.ts +24 -0
- package/dist/site-layout.js +91 -0
- package/dist/storage.d.ts +6 -0
- package/dist/storage.js +7 -0
- package/package.json +10 -6
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Storage } from "./storage.js";
|
|
2
|
+
import type { WorkspaceIndex } from "./indexes.js";
|
|
3
|
+
/**
|
|
4
|
+
* What the SITE BUILD needs to resolve a site-absolute link: the content
|
|
5
|
+
* roots (`content.sources[].path` of dogsbay.config.*, else the workspace
|
|
6
|
+
* root — which is right when the workspace IS the content dir) and the
|
|
7
|
+
* basePath / site.url path to strip. Read from the workspace storage, so the
|
|
8
|
+
* engine stays host-agnostic. A `git:` source or several sources with
|
|
9
|
+
* namespace/version/locale axes produce route prefixes this cannot know —
|
|
10
|
+
* the check is then skipped rather than guessed.
|
|
11
|
+
*/
|
|
12
|
+
export interface SiteLayout {
|
|
13
|
+
roots: string[];
|
|
14
|
+
prefixes: string[];
|
|
15
|
+
/** False when the config names sources whose route prefixes are not knowable here. */
|
|
16
|
+
checkable: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function siteLayout(storage: Storage): Promise<SiteLayout>;
|
|
19
|
+
/** A site path is a page when a content root has it as `x.md`, `x/index.md`, `x.mdx` — or an existing FILE (an asset); `_`-prefixed segments are never routed (except `_assets`). */
|
|
20
|
+
export declare function resolveSitePath(index: WorkspaceIndex, layout: SiteLayout, sitePath: string): {
|
|
21
|
+
doc?: string;
|
|
22
|
+
file?: string;
|
|
23
|
+
candidates: string[];
|
|
24
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a site-absolute link (`/guide/install`) lands, as the SITE BUILD routes it: the content
|
|
3
|
+
* roots and basePath of dogsbay.config.*, a page as `x.md` / `x/index.md` / `x.mdx`, else an
|
|
4
|
+
* existing file. Shared by `validate` and the refactors (a moved page's site-path links follow
|
|
5
|
+
* it). No Node: js-yaml and the workspace Storage.
|
|
6
|
+
*/
|
|
7
|
+
import { load as loadYaml } from "js-yaml";
|
|
8
|
+
export async function siteLayout(storage) {
|
|
9
|
+
const out = { roots: [""], prefixes: [], checkable: true };
|
|
10
|
+
for (const name of ["dogsbay.config.yml", "dogsbay.config.yaml", "dogsbay.config.json"]) {
|
|
11
|
+
if (!(await storage.exists(name)))
|
|
12
|
+
continue;
|
|
13
|
+
try {
|
|
14
|
+
const text = await storage.read(name);
|
|
15
|
+
const cfg = (name.endsWith(".json") ? JSON.parse(text) : loadYaml(text));
|
|
16
|
+
if (!cfg || typeof cfg !== "object")
|
|
17
|
+
return out;
|
|
18
|
+
const site = (cfg.site ?? {});
|
|
19
|
+
if (typeof site.basePath === "string" && site.basePath.replace(/\//g, ""))
|
|
20
|
+
out.prefixes.push(site.basePath.replace(/^\/+|\/+$/g, ""));
|
|
21
|
+
if (typeof site.url === "string") {
|
|
22
|
+
try {
|
|
23
|
+
const u = new URL(site.url);
|
|
24
|
+
const pth = u.pathname.replace(/^\/+|\/+$/g, "");
|
|
25
|
+
if (pth)
|
|
26
|
+
out.prefixes.push(pth);
|
|
27
|
+
}
|
|
28
|
+
catch { /* not a URL */ }
|
|
29
|
+
}
|
|
30
|
+
const content = (cfg.content ?? {});
|
|
31
|
+
const sources = Array.isArray(content.sources) ? content.sources : [];
|
|
32
|
+
const roots = [];
|
|
33
|
+
for (const src of sources) {
|
|
34
|
+
if (!src || typeof src !== "object")
|
|
35
|
+
continue;
|
|
36
|
+
const rec = src;
|
|
37
|
+
if (typeof rec.git === "string" || typeof rec.repo === "string") {
|
|
38
|
+
out.checkable = false;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (typeof rec.namespace === "string" || typeof rec.version === "string" || typeof rec.locale === "string")
|
|
42
|
+
out.checkable = false;
|
|
43
|
+
if (typeof rec.path === "string") {
|
|
44
|
+
const root = rec.path.replace(/^\.\/+/, "").replace(/^\/+|\/+$/g, "");
|
|
45
|
+
if (root.startsWith("..")) {
|
|
46
|
+
out.checkable = false;
|
|
47
|
+
continue;
|
|
48
|
+
} // above the workspace: unknowable
|
|
49
|
+
roots.push(root);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (typeof content.path === "string")
|
|
53
|
+
roots.push(content.path.replace(/^\.\/+/, "").replace(/^\/+|\/+$/g, ""));
|
|
54
|
+
if (roots.length)
|
|
55
|
+
out.roots = [...new Set(roots)];
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
/* unreadable config: resolve against the workspace root */
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/** A site path is a page when a content root has it as `x.md`, `x/index.md`, `x.mdx` — or an existing FILE (an asset); `_`-prefixed segments are never routed (except `_assets`). */
|
|
65
|
+
export function resolveSitePath(index, layout, sitePath) {
|
|
66
|
+
const candidates = [];
|
|
67
|
+
let p = sitePath;
|
|
68
|
+
for (const pre of layout.prefixes)
|
|
69
|
+
if (p === pre || p.startsWith(pre + "/")) {
|
|
70
|
+
p = p.slice(pre.length).replace(/^\/+/, "");
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
// `_`-prefixed segments are never routed by the build (fragments, includes) — except under `_assets/`, which is served
|
|
74
|
+
const hidden = (path) => {
|
|
75
|
+
if (path.startsWith("_assets/") || path.includes("/_assets/"))
|
|
76
|
+
return false;
|
|
77
|
+
return path.split("/").some((seg) => seg.startsWith("_"));
|
|
78
|
+
};
|
|
79
|
+
for (const root of layout.roots) {
|
|
80
|
+
const base = root ? `${root}/${p}` : p;
|
|
81
|
+
for (const c of [`${base}.md`, `${base}/index.md`, `${base}.mdx`]) {
|
|
82
|
+
candidates.push(c);
|
|
83
|
+
if (!hidden(c) && (index.docs.has(c) || index.maps.has(c)))
|
|
84
|
+
return { doc: index.docs.has(c) ? c : undefined, file: c, candidates };
|
|
85
|
+
}
|
|
86
|
+
candidates.push(base);
|
|
87
|
+
if (!hidden(base) && index.files.has(base))
|
|
88
|
+
return { file: base, candidates };
|
|
89
|
+
}
|
|
90
|
+
return { candidates };
|
|
91
|
+
}
|
package/dist/storage.d.ts
CHANGED
|
@@ -27,6 +27,11 @@ export interface Storage {
|
|
|
27
27
|
/** Delete a file. Rejects if missing. */
|
|
28
28
|
delete(path: string): Promise<void>;
|
|
29
29
|
exists(path: string): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Move a file as it is, bytes and all (a refactor moving an image). Optional: without it a
|
|
32
|
+
* refactor moves a file by reading and writing its text.
|
|
33
|
+
*/
|
|
34
|
+
move?(from: string, to: string): Promise<void>;
|
|
30
35
|
}
|
|
31
36
|
/** Normalize any incoming path to the workspace-relative posix form. */
|
|
32
37
|
export declare const normalizeStoragePath: (path: string) => string;
|
|
@@ -39,4 +44,5 @@ export declare class MemoryStorage implements Storage {
|
|
|
39
44
|
write(path: string, content: string): Promise<void>;
|
|
40
45
|
delete(path: string): Promise<void>;
|
|
41
46
|
exists(path: string): Promise<boolean>;
|
|
47
|
+
move(from: string, to: string): Promise<void>;
|
|
42
48
|
}
|
package/dist/storage.js
CHANGED
|
@@ -55,4 +55,11 @@ export class MemoryStorage {
|
|
|
55
55
|
async exists(path) {
|
|
56
56
|
return this.files.has(normalizeStoragePath(path));
|
|
57
57
|
}
|
|
58
|
+
async move(from, to) {
|
|
59
|
+
const content = this.files.get(normalizeStoragePath(from));
|
|
60
|
+
if (content === undefined)
|
|
61
|
+
throw new Error(`File not found: ${from}`);
|
|
62
|
+
this.files.set(normalizeStoragePath(to), content);
|
|
63
|
+
this.files.delete(normalizeStoragePath(from));
|
|
64
|
+
}
|
|
58
65
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dogsbay/commands",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.183",
|
|
4
4
|
"description": "Typed, headless-first command engine for the Dogsbay platform — one zod-defined command yields CLI, JSON-RPC, and MCP surfaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"./indexes": {
|
|
14
14
|
"types": "./dist/indexes-entry.d.ts",
|
|
15
15
|
"import": "./dist/indexes-entry.js"
|
|
16
|
+
},
|
|
17
|
+
"./refactor": {
|
|
18
|
+
"types": "./dist/refactor-entry.d.ts",
|
|
19
|
+
"import": "./dist/refactor-entry.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"sideEffects": false,
|
|
@@ -31,11 +35,11 @@
|
|
|
31
35
|
"js-yaml": "^5.2.1",
|
|
32
36
|
"yaml": "^2.9.0",
|
|
33
37
|
"zod": "^4.4.3",
|
|
34
|
-
"@dogsbay/format-dogsbay-md": "0.2.0-beta.
|
|
35
|
-
"@dogsbay/
|
|
36
|
-
"@dogsbay/
|
|
37
|
-
"@dogsbay/render": "0.2.0-beta.
|
|
38
|
-
"@dogsbay/types": "0.2.0-beta.
|
|
38
|
+
"@dogsbay/format-dogsbay-md": "0.2.0-beta.183",
|
|
39
|
+
"@dogsbay/minja": "0.2.0-beta.183",
|
|
40
|
+
"@dogsbay/format-topicmap": "0.2.0-beta.183",
|
|
41
|
+
"@dogsbay/render": "0.2.0-beta.183",
|
|
42
|
+
"@dogsbay/types": "0.2.0-beta.183"
|
|
39
43
|
},
|
|
40
44
|
"license": "MIT",
|
|
41
45
|
"repository": {
|