archidocs 1.3.0 → 1.3.1
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/cli/commands.d.ts +8 -8
- package/dist/cli/commands.js +7 -7
- package/dist/cli/dev.d.ts +5 -6
- package/dist/cli/dev.js +12 -14
- package/dist/cli/diff-format.d.ts +1 -5
- package/dist/cli/main.js +2 -324
- package/dist/cli/run.d.ts +18 -0
- package/dist/cli/run.js +283 -0
- package/dist/commands/build.d.ts +51 -0
- package/dist/commands/build.js +39 -0
- package/dist/commands/check.d.ts +8 -0
- package/dist/commands/check.js +5 -0
- package/dist/commands/diff.d.ts +29 -0
- package/dist/commands/diff.js +25 -0
- package/dist/commands/export.d.ts +41 -0
- package/dist/commands/export.js +47 -0
- package/dist/commands/history.d.ts +18 -0
- package/dist/commands/history.js +9 -0
- package/dist/commands/index.d.ts +11 -0
- package/dist/commands/index.js +11 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/load.d.ts +0 -2
- package/dist/core/load.js +5 -6
- package/dist/core/workspace-files.d.ts +13 -0
- package/dist/core/workspace-files.js +20 -0
- package/dist/git.d.ts +2 -0
- package/dist/git.js +14 -4
- package/dist/history/git.d.ts +0 -10
- package/dist/history/git.js +1 -30
- package/dist/history/index.d.ts +15 -31
- package/dist/history/index.js +47 -43
- package/dist/history/points.d.ts +23 -0
- package/dist/history/points.js +28 -0
- package/dist/history/site.d.ts +30 -0
- package/dist/history/site.js +37 -0
- package/dist/mcp/history.d.ts +4 -4
- package/dist/mcp/history.js +56 -116
- package/dist/mcp/server.js +18 -17
- package/dist/mcp/site.d.ts +12 -0
- package/dist/mcp/site.js +46 -0
- package/dist/mcp/source.d.ts +14 -7
- package/dist/mcp/source.js +25 -99
- package/dist/revisions/find.d.ts +64 -0
- package/dist/revisions/find.js +85 -0
- package/dist/revisions/index.d.ts +57 -0
- package/dist/revisions/index.js +24 -0
- package/dist/revisions/site.d.ts +82 -0
- package/dist/revisions/site.js +157 -0
- package/dist/revisions/text.d.ts +8 -0
- package/dist/revisions/text.js +17 -0
- package/dist/revisions/touching.d.ts +7 -0
- package/dist/revisions/touching.js +7 -0
- package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
- package/dist/viewer/assets/{png-CAaXWR-k.js → png-DMwnpRCt.js} +1 -1
- package/dist/viewer/assets/{svg-BPVHfD36.js → svg-DN6lMeZo.js} +1 -1
- package/dist/viewer/index.html +1 -1
- package/dist/workspace/index.d.ts +37 -0
- package/dist/workspace/index.js +52 -0
- package/package.json +1 -1
- package/dist/viewer/assets/index-BXa5R96a.js +0 -138
- /package/dist/{history → revisions}/migrate.d.ts +0 -0
- /package/dist/{history → revisions}/migrate.js +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one rule for which files make up a Workspace: `load`'s walk, the
|
|
3
|
+
* Checkout's fingerprint and (later) dev's watcher all use it. Pure and
|
|
4
|
+
* browser-safe, so core can use it.
|
|
5
|
+
*/
|
|
6
|
+
/** Whether `load` skips a folder or file by its name: hidden ones (`.git`, editor swap files) and `node_modules`. */
|
|
7
|
+
export declare function isSkippedName(name: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Whether a path, relative to the Workspace root and `/` or `\` separated,
|
|
10
|
+
* is a Workspace file: no part of it is skipped, and it is a `.yaml` model
|
|
11
|
+
* file or an `.md` ADR.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isWorkspaceFile(path: string): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one rule for which files make up a Workspace: `load`'s walk, the
|
|
3
|
+
* Checkout's fingerprint and (later) dev's watcher all use it. Pure and
|
|
4
|
+
* browser-safe, so core can use it.
|
|
5
|
+
*/
|
|
6
|
+
/** Whether `load` skips a folder or file by its name: hidden ones (`.git`, editor swap files) and `node_modules`. */
|
|
7
|
+
export function isSkippedName(name) {
|
|
8
|
+
return name.startsWith(".") || name === "node_modules";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Whether a path, relative to the Workspace root and `/` or `\` separated,
|
|
12
|
+
* is a Workspace file: no part of it is skipped, and it is a `.yaml` model
|
|
13
|
+
* file or an `.md` ADR.
|
|
14
|
+
*/
|
|
15
|
+
export function isWorkspaceFile(path) {
|
|
16
|
+
const parts = path.split(/[\\/]/).filter((part) => part !== "");
|
|
17
|
+
if (parts.length === 0 || parts.some(isSkippedName))
|
|
18
|
+
return false;
|
|
19
|
+
return path.endsWith(".yaml") || path.endsWith(".md");
|
|
20
|
+
}
|
package/dist/git.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
|
|
2
|
+
export declare function git(cwd: string, ...args: string[]): Promise<string>;
|
|
1
3
|
/** HEAD's sha and commit time, so a Bundle built twice at one commit is byte-identical. Both null outside git or before the first commit. */
|
|
2
4
|
export declare function gitHead(cwd: string): Promise<{
|
|
3
5
|
commit: string | null;
|
package/dist/git.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
|
+
const exec = promisify(execFile);
|
|
4
|
+
/** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
|
|
5
|
+
export async function git(cwd, ...args) {
|
|
6
|
+
try {
|
|
7
|
+
const { stdout } = await exec("git", ["-c", "core.quotePath=false", ...args], { cwd, maxBuffer: 1024 * 1024 * 1024, encoding: "utf8" });
|
|
8
|
+
return stdout;
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
const err = e;
|
|
12
|
+
throw new Error(err.stderr?.trim() || err.message, { cause: e });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
3
15
|
/** HEAD's sha and commit time, so a Bundle built twice at one commit is byte-identical. Both null outside git or before the first commit. */
|
|
4
16
|
export async function gitHead(cwd) {
|
|
5
17
|
try {
|
|
6
|
-
const
|
|
7
|
-
const [commit, builtAt] = stdout.trim().split(" ");
|
|
18
|
+
const [commit, builtAt] = (await git(cwd, "log", "-1", "--format=%H %cI")).trim().split(" ");
|
|
8
19
|
return { commit: commit || null, builtAt: builtAt || null };
|
|
9
20
|
}
|
|
10
21
|
catch {
|
|
@@ -14,8 +25,7 @@ export async function gitHead(cwd) {
|
|
|
14
25
|
/** The top folder of the git checkout holding `cwd`, or null outside git. */
|
|
15
26
|
export async function gitTopLevel(cwd) {
|
|
16
27
|
try {
|
|
17
|
-
|
|
18
|
-
return stdout.trim() || null;
|
|
28
|
+
return (await git(cwd, "rev-parse", "--show-toplevel")).trim() || null;
|
|
19
29
|
}
|
|
20
30
|
catch {
|
|
21
31
|
return null;
|
package/dist/history/git.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { FileSystem } from "../core/fs.ts";
|
|
2
|
-
/** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
|
|
3
|
-
export declare function git(cwd: string, ...args: string[]): Promise<string>;
|
|
4
2
|
/**
|
|
5
3
|
* A read-only FileSystem over the tree of one commit. Paths are absolute
|
|
6
4
|
* under `repoRoot`, as on disk; files are read with `git show`, so no
|
|
@@ -28,12 +26,4 @@ export declare function defaultBranch(repoRoot: string): Promise<string>;
|
|
|
28
26
|
export declare function firstParentCommitsTouching(repoRoot: string, branch: string, path: string): Promise<CommitInfo[]>;
|
|
29
27
|
/** Tag names by the commit they point at. */
|
|
30
28
|
export declare function tagsByCommit(repoRoot: string): Promise<Map<string, string[]>>;
|
|
31
|
-
/** Whether `point` is a date (`YYYY-MM-DD` or a full ISO 8601 time) rather than a ref. */
|
|
32
|
-
export declare const isDate: (point: string) => boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Resolves a point in time to a commit sha: a date to the last first-parent
|
|
35
|
-
* default-branch commit at or before it, anything else as a git ref.
|
|
36
|
-
* Undefined when there is no such commit.
|
|
37
|
-
*/
|
|
38
|
-
export declare function resolvePoint(repoRoot: string, point: string): Promise<string | undefined>;
|
|
39
29
|
export declare const joinRepo: (repoRoot: string, rel: string) => string;
|
package/dist/history/git.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
1
|
import { join, relative, sep } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
const exec = promisify(execFile);
|
|
5
|
-
/** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
|
|
6
|
-
export async function git(cwd, ...args) {
|
|
7
|
-
try {
|
|
8
|
-
const { stdout } = await exec("git", ["-c", "core.quotePath=false", ...args], { cwd, maxBuffer: 1024 * 1024 * 1024, encoding: "utf8" });
|
|
9
|
-
return stdout;
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
const err = e;
|
|
13
|
-
throw new Error(err.stderr?.trim() || err.message, { cause: e });
|
|
14
|
-
}
|
|
15
|
-
}
|
|
2
|
+
import { git } from "../git.js";
|
|
16
3
|
/**
|
|
17
4
|
* A read-only FileSystem over the tree of one commit. Paths are absolute
|
|
18
5
|
* under `repoRoot`, as on disk; files are read with `git show`, so no
|
|
@@ -107,20 +94,4 @@ export async function tagsByCommit(repoRoot) {
|
|
|
107
94
|
}
|
|
108
95
|
return map;
|
|
109
96
|
}
|
|
110
|
-
/** Whether `point` is a date (`YYYY-MM-DD` or a full ISO 8601 time) rather than a ref. */
|
|
111
|
-
export const isDate = (point) => /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:?\d{2})?)?$/.test(point);
|
|
112
|
-
/** A bare date means the end of that day (UTC); a time is taken as given. */
|
|
113
|
-
const endOf = (date) => (/^\d{4}-\d{2}-\d{2}$/.test(date) ? `${date}T23:59:59Z` : date);
|
|
114
|
-
/**
|
|
115
|
-
* Resolves a point in time to a commit sha: a date to the last first-parent
|
|
116
|
-
* default-branch commit at or before it, anything else as a git ref.
|
|
117
|
-
* Undefined when there is no such commit.
|
|
118
|
-
*/
|
|
119
|
-
export async function resolvePoint(repoRoot, point) {
|
|
120
|
-
if (isDate(point)) {
|
|
121
|
-
const sha = (await git(repoRoot, "rev-list", "-1", "--first-parent", `--before=${endOf(point)}`, await defaultBranch(repoRoot)).catch(() => "")).trim();
|
|
122
|
-
return sha || undefined;
|
|
123
|
-
}
|
|
124
|
-
return (await git(repoRoot, "rev-parse", "--verify", "--quiet", "--end-of-options", `${point}^{commit}`).catch(() => "")).trim() || undefined;
|
|
125
|
-
}
|
|
126
97
|
export const joinRepo = (repoRoot, rel) => (rel === "" ? repoRoot : join(repoRoot, rel));
|
package/dist/history/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { type ChangeCounts } from "../core/index.ts";
|
|
2
1
|
import { Bundle } from "../schema/bundle.ts";
|
|
2
|
+
import { type PreviewMark, type RevisionIndex } from "../revisions/index.ts";
|
|
3
3
|
import { type CommitInfo } from "./git.ts";
|
|
4
|
-
|
|
5
|
-
export {
|
|
4
|
+
import { type SiteContent } from "./site.ts";
|
|
5
|
+
export { migrateBundle, migrations, type Migration } from "../revisions/index.ts";
|
|
6
|
+
export { type CommitInfo } from "./git.ts";
|
|
7
|
+
export { writeSite, type PastBundle, type SiteContent } from "./site.ts";
|
|
8
|
+
export { resolvePoint, pointMessage, type PointFailure, type ResolvedPoint } from "./points.ts";
|
|
6
9
|
/** The cache a checkout keeps past Bundles and their index entries in, under the repo root. */
|
|
7
10
|
export declare const CACHE_DIR: string;
|
|
8
11
|
/** Where a Workspace's history lives: its git repo and the Workspace root within it. */
|
|
@@ -11,23 +14,6 @@ export interface History {
|
|
|
11
14
|
/** The Workspace root relative to the repo root, with `/` separators; "" when they are the same folder. */
|
|
12
15
|
workspacePath: string;
|
|
13
16
|
}
|
|
14
|
-
/** One Revision as the index records it; `bundle: false` marks a Revision whose Bundle was dropped. */
|
|
15
|
-
export interface RevisionEntry {
|
|
16
|
-
sha: string;
|
|
17
|
-
date: string;
|
|
18
|
-
subject: string;
|
|
19
|
-
author: string;
|
|
20
|
-
tags: string[];
|
|
21
|
-
/** Changes against the previous Revision (or an empty Model for the first). */
|
|
22
|
-
counts: ChangeCounts;
|
|
23
|
-
changedIds: string[];
|
|
24
|
-
bundle: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface RevisionIndex {
|
|
27
|
-
schemaVersion: number;
|
|
28
|
-
/** Newest first. */
|
|
29
|
-
revisions: RevisionEntry[];
|
|
30
|
-
}
|
|
31
17
|
export declare const history: (repoRoot: string, workspaceRoot: string) => History;
|
|
32
18
|
/**
|
|
33
19
|
* The Revisions: first-parent default-branch commits that changed something
|
|
@@ -66,19 +52,22 @@ export declare function buildHistory(h: History, options?: {
|
|
|
66
52
|
}): Promise<BuildResult>;
|
|
67
53
|
/** Past Bundles a published site keeps by default: the latest 200 Revisions, plus every tagged one. */
|
|
68
54
|
export declare const DEFAULT_KEEP = 200;
|
|
55
|
+
/** The latest Bundle and the Workspace's name, which a site holds beside its history. */
|
|
56
|
+
export type Latest = Pick<SiteContent, "bundle" | "workspace">;
|
|
69
57
|
export interface PublishResult {
|
|
70
58
|
revisions: number;
|
|
71
59
|
kept: number;
|
|
72
60
|
}
|
|
73
61
|
/**
|
|
74
|
-
* Writes
|
|
75
|
-
* Revision and `bundles/index.json`
|
|
62
|
+
* Writes a site through {@link writeSite}: the latest Bundle and its name,
|
|
63
|
+
* `bundles/<sha>.json` for each kept Revision and `bundles/index.json`
|
|
64
|
+
* listing every Revision. Kept are the
|
|
76
65
|
* latest `keep` Revisions plus every tagged one; the others stay in the
|
|
77
66
|
* index with `bundle: false`. Bundles come from the checkout's cache,
|
|
78
67
|
* backfilled from git first, so nothing is fetched. A Bundle file left in
|
|
79
68
|
* the folder by an earlier build is removed once its Revision is dropped.
|
|
80
69
|
*/
|
|
81
|
-
export declare function publishHistory(h: History, out: string, { keep }?: {
|
|
70
|
+
export declare function publishHistory(h: History, out: string, latest: Latest, { keep }?: {
|
|
82
71
|
keep?: number | "all";
|
|
83
72
|
}): Promise<PublishResult>;
|
|
84
73
|
/** The two sides a preview site Compares: the base branch's latest Revision and the PR head. */
|
|
@@ -97,18 +86,13 @@ export interface PreviewSides {
|
|
|
97
86
|
* yet) and HEAD. It never fetches; a missing `origin/<base>` is an error.
|
|
98
87
|
*/
|
|
99
88
|
export declare function previewSides(h: History, base: string): Promise<PreviewSides>;
|
|
100
|
-
/** What a preview site's `bundles/index.json` adds: the base branch and both sides' shas, so the viewer opens with Compare "base → PR". */
|
|
101
|
-
export interface PreviewMark {
|
|
102
|
-
base: string;
|
|
103
|
-
baseSha: string;
|
|
104
|
-
headSha: string;
|
|
105
|
-
}
|
|
106
89
|
/**
|
|
107
|
-
* Writes a preview site
|
|
90
|
+
* Writes a preview site through {@link writeSite}: the head as the latest
|
|
91
|
+
* Bundle, and in a cleared `bundles/` the base's Bundle, the head's (the
|
|
108
92
|
* checkout as built) and an index of the two, newest first, marked with
|
|
109
93
|
* `preview`. The head's counts are against the base.
|
|
110
94
|
*/
|
|
111
|
-
export declare function publishPreview(h: History, out: string, sides: PreviewSides, head: Bundle): Promise<PreviewMark>;
|
|
95
|
+
export declare function publishPreview(h: History, out: string, sides: PreviewSides, head: Bundle, workspace?: string): Promise<PreviewMark>;
|
|
112
96
|
/** The base branch origin/HEAD names, else `main`. */
|
|
113
97
|
export declare function defaultBaseBranch(repoRoot: string): Promise<string>;
|
|
114
98
|
/** A point in time that names no commit, or history that can't be read. */
|
package/dist/history/index.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, join, relative, sep } from "node:path";
|
|
3
|
-
import { changedIds, countChanges, diff, load
|
|
3
|
+
import { changedIds, countChanges, diff, load } from "../core/index.js";
|
|
4
4
|
import { Bundle, SCHEMA_VERSION } from "../schema/bundle.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { git } from "../git.js";
|
|
6
|
+
import { BUNDLES_DIR, INDEX_PATH, INDEX_VERSION, pastBundleFile, serializeBundle, serializeIndex, timeSpan } from "../revisions/index.js";
|
|
7
|
+
import { commitInfo, defaultBranch, firstParentCommitsTouching, gitFileSystem, joinRepo, tagsByCommit } from "./git.js";
|
|
8
|
+
import { pointMessage, resolvePoint } from "./points.js";
|
|
9
|
+
import { writeSite } from "./site.js";
|
|
10
|
+
export { migrateBundle, migrations } from "../revisions/index.js";
|
|
11
|
+
export {} from "./git.js";
|
|
12
|
+
export { writeSite } from "./site.js";
|
|
13
|
+
export { resolvePoint, pointMessage } from "./points.js";
|
|
8
14
|
/** The cache a checkout keeps past Bundles and their index entries in, under the repo root. */
|
|
9
15
|
export const CACHE_DIR = join(".archidocs", "cache");
|
|
10
16
|
export const history = (repoRoot, workspaceRoot) => ({
|
|
11
17
|
repoRoot,
|
|
12
18
|
workspacePath: relative(repoRoot, workspaceRoot).split(sep).join("/"),
|
|
13
19
|
});
|
|
14
|
-
const bundlesDir = (h) => join(h.repoRoot, CACHE_DIR,
|
|
15
|
-
const bundleFile = (h, sha) => join(bundlesDir(h),
|
|
16
|
-
const indexFile = (h) => join(
|
|
20
|
+
const bundlesDir = (h) => join(h.repoRoot, CACHE_DIR, BUNDLES_DIR);
|
|
21
|
+
const bundleFile = (h, sha) => join(bundlesDir(h), pastBundleFile(sha));
|
|
22
|
+
const indexFile = (h) => join(h.repoRoot, CACHE_DIR, INDEX_PATH);
|
|
17
23
|
/**
|
|
18
24
|
* The Revisions: first-parent default-branch commits that changed something
|
|
19
25
|
* under the Workspace root, newest first.
|
|
@@ -64,13 +70,13 @@ async function readCached(h, sha) {
|
|
|
64
70
|
export async function readIndex(h) {
|
|
65
71
|
try {
|
|
66
72
|
const index = JSON.parse(await readFile(indexFile(h), "utf8"));
|
|
67
|
-
if (index.schemaVersion ===
|
|
73
|
+
if (index.schemaVersion === INDEX_VERSION && Array.isArray(index.revisions))
|
|
68
74
|
return index;
|
|
69
75
|
}
|
|
70
76
|
catch {
|
|
71
77
|
// No index yet, or an unreadable one: start again.
|
|
72
78
|
}
|
|
73
|
-
return { schemaVersion:
|
|
79
|
+
return { schemaVersion: INDEX_VERSION, revisions: [] };
|
|
74
80
|
}
|
|
75
81
|
/**
|
|
76
82
|
* Backfills cached Bundles and index entries for every Revision, or those
|
|
@@ -115,47 +121,40 @@ export async function buildHistory(h, options = {}) {
|
|
|
115
121
|
.sort((a, b) => order.get(a.sha) - order.get(b.sha))
|
|
116
122
|
.map(({ sha, date, subject, author, tags: t, counts, changedIds: ids, bundle }) => ({ sha, date, subject, author, tags: t, counts, changedIds: ids, bundle }));
|
|
117
123
|
await mkdir(dirname(indexFile(h)), { recursive: true });
|
|
118
|
-
await writeFile(indexFile(h),
|
|
124
|
+
await writeFile(indexFile(h), serializeIndex({ schemaVersion: INDEX_VERSION, revisions: revisionsOut }));
|
|
119
125
|
}
|
|
120
126
|
return { revisions: inScope.length, built };
|
|
121
127
|
}
|
|
128
|
+
/** Where `--since` starts: a day's start, a time as given (UTC without a zone), else the commit date of the commit the point names. */
|
|
122
129
|
async function sinceTime(h, since) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return Date.parse((await commitInfo(h.repoRoot, sha)).date);
|
|
130
|
+
const own = timeSpan(since);
|
|
131
|
+
if (own)
|
|
132
|
+
return own.start;
|
|
133
|
+
const point = await resolvePoint(h, since);
|
|
134
|
+
if (!point.ok)
|
|
135
|
+
throw new HistoryError(pointMessage(since, point));
|
|
136
|
+
return Date.parse((await commitInfo(h.repoRoot, point.sha)).date);
|
|
131
137
|
}
|
|
132
138
|
/** Past Bundles a published site keeps by default: the latest 200 Revisions, plus every tagged one. */
|
|
133
139
|
export const DEFAULT_KEEP = 200;
|
|
134
140
|
/**
|
|
135
|
-
* Writes
|
|
136
|
-
* Revision and `bundles/index.json`
|
|
141
|
+
* Writes a site through {@link writeSite}: the latest Bundle and its name,
|
|
142
|
+
* `bundles/<sha>.json` for each kept Revision and `bundles/index.json`
|
|
143
|
+
* listing every Revision. Kept are the
|
|
137
144
|
* latest `keep` Revisions plus every tagged one; the others stay in the
|
|
138
145
|
* index with `bundle: false`. Bundles come from the checkout's cache,
|
|
139
146
|
* backfilled from git first, so nothing is fetched. A Bundle file left in
|
|
140
147
|
* the folder by an earlier build is removed once its Revision is dropped.
|
|
141
148
|
*/
|
|
142
|
-
export async function publishHistory(h, out, { keep = DEFAULT_KEEP } = {}) {
|
|
143
|
-
const dir = join(out, "bundles");
|
|
149
|
+
export async function publishHistory(h, out, latest, { keep = DEFAULT_KEEP } = {}) {
|
|
144
150
|
const hasCommits = await gitHasCommits(h.repoRoot);
|
|
145
151
|
if (hasCommits)
|
|
146
152
|
await buildHistory(h);
|
|
147
|
-
const
|
|
148
|
-
const revisionsOut =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (/^[0-9a-f]{40,64}\.json$/.test(file) && !keptFiles.has(file))
|
|
153
|
-
await rm(join(dir, file));
|
|
154
|
-
}
|
|
155
|
-
for (const file of keptFiles)
|
|
156
|
-
await copyFile(join(bundlesDir(h), file), join(dir, file));
|
|
157
|
-
await writeFile(join(dir, "index.json"), JSON.stringify({ schemaVersion: SCHEMA_VERSION, revisions: revisionsOut }, null, 2) + "\n");
|
|
158
|
-
return { revisions: revisionsOut.length, kept: keptFiles.size };
|
|
153
|
+
const cached = hasCommits ? await readIndex(h) : { schemaVersion: INDEX_VERSION, revisions: [] };
|
|
154
|
+
const revisionsOut = cached.revisions.map((entry, i) => ({ ...entry, bundle: keep === "all" || i < keep || entry.tags.length > 0 }));
|
|
155
|
+
const past = revisionsOut.filter((e) => e.bundle).map((e) => ({ sha: e.sha, from: bundleFile(h, e.sha) }));
|
|
156
|
+
await writeSite(out, { ...latest, index: { schemaVersion: INDEX_VERSION, revisions: revisionsOut }, past });
|
|
157
|
+
return { revisions: revisionsOut.length, kept: past.length };
|
|
159
158
|
}
|
|
160
159
|
/**
|
|
161
160
|
* Finds a preview's sides from what the checkout already has: the latest
|
|
@@ -182,12 +181,12 @@ export async function previewSides(h, base) {
|
|
|
182
181
|
};
|
|
183
182
|
}
|
|
184
183
|
/**
|
|
185
|
-
* Writes a preview site
|
|
184
|
+
* Writes a preview site through {@link writeSite}: the head as the latest
|
|
185
|
+
* Bundle, and in a cleared `bundles/` the base's Bundle, the head's (the
|
|
186
186
|
* checkout as built) and an index of the two, newest first, marked with
|
|
187
187
|
* `preview`. The head's counts are against the base.
|
|
188
188
|
*/
|
|
189
|
-
export async function publishPreview(h, out, sides, head) {
|
|
190
|
-
const dir = join(out, "bundles");
|
|
189
|
+
export async function publishPreview(h, out, sides, head, workspace) {
|
|
191
190
|
const tags = await tagsByCommit(h.repoRoot);
|
|
192
191
|
const entry = (rev, before, after) => {
|
|
193
192
|
const changes = diff(before, after);
|
|
@@ -199,11 +198,16 @@ export async function publishPreview(h, out, sides, head) {
|
|
|
199
198
|
if (sides.head.sha !== baseRevision.sha)
|
|
200
199
|
revisionsOut.push(entry(baseRevision, sides.beforeBase, baseBundle));
|
|
201
200
|
const preview = { base: sides.base, baseSha: baseRevision.sha, headSha: sides.head.sha };
|
|
202
|
-
await
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
201
|
+
await writeSite(out, {
|
|
202
|
+
bundle: head,
|
|
203
|
+
...(workspace === undefined ? {} : { workspace }),
|
|
204
|
+
index: { schemaVersion: INDEX_VERSION, preview, revisions: revisionsOut },
|
|
205
|
+
past: [
|
|
206
|
+
{ sha: baseRevision.sha, bundle: baseBundle },
|
|
207
|
+
{ sha: sides.head.sha, bundle: head },
|
|
208
|
+
],
|
|
209
|
+
clear: true,
|
|
210
|
+
});
|
|
207
211
|
return preview;
|
|
208
212
|
}
|
|
209
213
|
/** The base branch origin/HEAD names, else `main`. */
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Dated, type Found } from "../revisions/index.ts";
|
|
2
|
+
import type { History } from "./index.ts";
|
|
3
|
+
/** Why a point names no commit on a checkout: `find`'s failure over the default branch's Revisions. */
|
|
4
|
+
export type PointFailure = Exclude<Found<Dated>, {
|
|
5
|
+
ok: true;
|
|
6
|
+
}>;
|
|
7
|
+
/** The commit a point names; `ref` is true when git resolved it as a ref, false when it named a Revision by date or sha prefix. */
|
|
8
|
+
export type ResolvedPoint = {
|
|
9
|
+
ok: true;
|
|
10
|
+
sha: string;
|
|
11
|
+
ref: boolean;
|
|
12
|
+
} | PointFailure;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves a point on a checkout to a commit, in this order:
|
|
15
|
+
* 1. a git ref (tag, branch, sha, `HEAD~1`), to its commit, Revision or not;
|
|
16
|
+
* 2. a date or a time, to the last Revision on the default branch at or before it;
|
|
17
|
+
* 3. hex, to the one Revision whose sha starts with it (several are `ambiguous`).
|
|
18
|
+
* Anything else is `not_found`, suggesting up to 5 tags. Dates and hex go
|
|
19
|
+
* through the point grammar's `find`, so they name what they name on a site.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolvePoint(h: History, point: string): Promise<ResolvedPoint>;
|
|
22
|
+
/** The CLI's words for a point that names no commit, after `archidocs: `. */
|
|
23
|
+
export declare function pointMessage(point: string, failure: PointFailure): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { git } from "../git.js";
|
|
2
|
+
import { find } from "../revisions/index.js";
|
|
3
|
+
import { defaultBranch, firstParentCommitsTouching, tagsByCommit } from "./git.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a point on a checkout to a commit, in this order:
|
|
6
|
+
* 1. a git ref (tag, branch, sha, `HEAD~1`), to its commit, Revision or not;
|
|
7
|
+
* 2. a date or a time, to the last Revision on the default branch at or before it;
|
|
8
|
+
* 3. hex, to the one Revision whose sha starts with it (several are `ambiguous`).
|
|
9
|
+
* Anything else is `not_found`, suggesting up to 5 tags. Dates and hex go
|
|
10
|
+
* through the point grammar's `find`, so they name what they name on a site.
|
|
11
|
+
*/
|
|
12
|
+
export async function resolvePoint(h, point) {
|
|
13
|
+
const sha = await revParse(h.repoRoot, point);
|
|
14
|
+
if (sha)
|
|
15
|
+
return { ok: true, sha, ref: true };
|
|
16
|
+
const [commits, tags] = await Promise.all([defaultBranch(h.repoRoot).then((branch) => firstParentCommitsTouching(h.repoRoot, branch, h.workspacePath)), tagsByCommit(h.repoRoot)]);
|
|
17
|
+
const revisions = commits.map(({ sha, date }) => ({ sha, date, tags: tags.get(sha) ?? [] }));
|
|
18
|
+
const found = find(revisions, point);
|
|
19
|
+
return found.ok ? { ok: true, sha: found.revision.sha, ref: false } : found;
|
|
20
|
+
}
|
|
21
|
+
/** The CLI's words for a point that names no commit, after `archidocs: `. */
|
|
22
|
+
export function pointMessage(point, failure) {
|
|
23
|
+
if (failure.kind === "ambiguous")
|
|
24
|
+
return `"${point}" is the start of ${failure.count} Revisions' shas; give more of it.`;
|
|
25
|
+
const message = `Unknown ref or date "${point}"; a date names the last Revision at or before it.`;
|
|
26
|
+
return failure.first ? `${message} The first Revision is ${failure.first.sha.slice(0, 7)}, ${failure.first.date}.` : message;
|
|
27
|
+
}
|
|
28
|
+
const revParse = async (repoRoot, point) => (await git(repoRoot, "rev-parse", "--verify", "--quiet", "--end-of-options", `${point}^{commit}`).catch(() => "")).trim() || undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Bundle } from "../schema/bundle.ts";
|
|
2
|
+
import { type RevisionIndex } from "../revisions/index.ts";
|
|
3
|
+
/** A past Bundle to place in `bundles/`: copied from a file (the checkout's cache) or serialized from a Bundle. */
|
|
4
|
+
export type PastBundle = {
|
|
5
|
+
sha: string;
|
|
6
|
+
from: string;
|
|
7
|
+
} | {
|
|
8
|
+
sha: string;
|
|
9
|
+
bundle: Bundle;
|
|
10
|
+
};
|
|
11
|
+
export interface SiteContent {
|
|
12
|
+
/** The latest Bundle, `workspace.bundle.json`. */
|
|
13
|
+
bundle: Bundle;
|
|
14
|
+
/** The Workspace's name for `site.json`; none for `--bundle-only`. */
|
|
15
|
+
workspace?: string;
|
|
16
|
+
/** The Revision index, `bundles/index.json`; none for `--bundle-only`. */
|
|
17
|
+
index?: RevisionIndex;
|
|
18
|
+
/** The past Bundles the index keeps. */
|
|
19
|
+
past?: PastBundle[];
|
|
20
|
+
/** Clear `bundles/` before writing, as a preview does, instead of removing only the past Bundles no longer kept. */
|
|
21
|
+
clear?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Writes a site to `out`: the latest Bundle, `site.json` when there is a
|
|
25
|
+
* name, the Revision index and each past Bundle. With an index, a past
|
|
26
|
+
* Bundle file left in `bundles/` by an earlier build is removed once it is
|
|
27
|
+
* no longer kept. The only code that writes a site's files; the viewer's
|
|
28
|
+
* own files are copied in by `build`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeSite(out: string, { bundle, workspace, index, past, clear }: SiteContent): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { copyFile, mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { BUNDLES_DIR, INDEX_PATH, isPastBundleFile, LATEST_BUNDLE_PATH, pastBundleFile, pastBundlePath, serializeBundle, serializeIndex, serializeSiteFile, SITE_FILE_PATH, } from "../revisions/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Writes a site to `out`: the latest Bundle, `site.json` when there is a
|
|
6
|
+
* name, the Revision index and each past Bundle. With an index, a past
|
|
7
|
+
* Bundle file left in `bundles/` by an earlier build is removed once it is
|
|
8
|
+
* no longer kept. The only code that writes a site's files; the viewer's
|
|
9
|
+
* own files are copied in by `build`.
|
|
10
|
+
*/
|
|
11
|
+
export async function writeSite(out, { bundle, workspace, index, past = [], clear = false }) {
|
|
12
|
+
await mkdir(out, { recursive: true });
|
|
13
|
+
if (workspace !== undefined)
|
|
14
|
+
await writeFile(join(out, SITE_FILE_PATH), serializeSiteFile(workspace));
|
|
15
|
+
await writeFile(join(out, LATEST_BUNDLE_PATH), serializeBundle(bundle));
|
|
16
|
+
if (!index)
|
|
17
|
+
return;
|
|
18
|
+
const dir = join(out, BUNDLES_DIR);
|
|
19
|
+
if (clear)
|
|
20
|
+
await rm(dir, { recursive: true, force: true });
|
|
21
|
+
await mkdir(dir, { recursive: true });
|
|
22
|
+
const kept = new Set(past.map((p) => pastBundleFile(p.sha)));
|
|
23
|
+
if (!clear) {
|
|
24
|
+
for (const file of await readdir(dir)) {
|
|
25
|
+
if (isPastBundleFile(file) && !kept.has(file))
|
|
26
|
+
await rm(join(dir, file));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
for (const p of past) {
|
|
30
|
+
const to = join(out, pastBundlePath(p.sha));
|
|
31
|
+
if ("from" in p)
|
|
32
|
+
await copyFile(p.from, to);
|
|
33
|
+
else
|
|
34
|
+
await writeFile(to, serializeBundle(p.bundle));
|
|
35
|
+
}
|
|
36
|
+
await writeFile(join(out, INDEX_PATH), serializeIndex(index));
|
|
37
|
+
}
|
package/dist/mcp/history.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RevisionEntry } from "../
|
|
1
|
+
import { type RevisionEntry, type Span } from "../revisions/index.ts";
|
|
2
2
|
import type { Snapshot, Source } from "./source.ts";
|
|
3
3
|
/** Why a point in time can't be answered: it names no commit, or its Bundle can't be had. */
|
|
4
4
|
export type PastFailure = {
|
|
@@ -27,10 +27,10 @@ export interface Past {
|
|
|
27
27
|
ok: true;
|
|
28
28
|
revisions: RevisionEntry[];
|
|
29
29
|
} | PastFailure>;
|
|
30
|
-
/** The time a
|
|
31
|
-
|
|
30
|
+
/** The time a point spans: a commit's one instant, a whole UTC day, or a time's instant. */
|
|
31
|
+
span(point: string): Promise<{
|
|
32
32
|
ok: true;
|
|
33
|
-
|
|
33
|
+
span: Span;
|
|
34
34
|
} | PastFailure>;
|
|
35
35
|
}
|
|
36
36
|
export declare function pastOf(source: Source): Past;
|