linopress-cli 0.0.0-stage → 0.2.0

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.
@@ -0,0 +1,118 @@
1
+ /**
2
+ * The Markdown files target, for VitePress or any other static site generator.
3
+ *
4
+ * @module linopress-cli/markdown
5
+ */
6
+ import { o as Asset, t as MarkdownTransform } from "./transforms-BBEyouxz.js";
7
+ import { n as DocNode } from "./model-CgSIC_VE.js";
8
+ /**
9
+ * Transforms for a Markdown docs site: none. TypeDoc's `<a id>` anchors and `#fragment` links work
10
+ * on a normal site, so they are kept.
11
+ */
12
+ export declare const markdownTransforms: readonly MarkdownTransform[];
13
+ /** A file the edition writes: a page or an asset it embeds, at its edition-relative path. */
14
+ interface OutputFile {
15
+ readonly path: string;
16
+ readonly kind: "page" | "asset";
17
+ readonly data: Uint8Array;
18
+ }
19
+ interface RenderMarkdownOptions {
20
+ /** Defaults to `markdownTransforms` (none). */
21
+ readonly transforms?: readonly MarkdownTransform[];
22
+ /** Put at the top of every page, e.g. an HTML comment saying the file is generated. */
23
+ readonly header?: (node: DocNode) => string;
24
+ }
25
+ interface MarkdownEdition {
26
+ /** Pages first (in layout order), then assets by path. */
27
+ readonly files: readonly OutputFile[];
28
+ /** page path → edition-relative `.md` link targets that aren't pages of this edition. */
29
+ readonly unresolvedLinks: Readonly<Record<string, readonly string[]>>;
30
+ /** page path → local images and files it references that don't exist. */
31
+ readonly missingImages: Readonly<Record<string, readonly string[]>>;
32
+ }
33
+ /**
34
+ * Renders an edition as files: each page gets its title back as an H1 (sources split it off for
35
+ * Linear), links stay relative with their `#fragment`s, and every embedded image that exists is
36
+ * copied to the same relative path, so references keep working.
37
+ */
38
+ export declare function renderMarkdownEdition(nodes: readonly DocNode[], assets: ReadonlyMap<string, Asset>, options?: RenderMarkdownOptions): MarkdownEdition;
39
+ /**
40
+ * The file in the output folder that lists what Linopress wrote there. Only those files are ever
41
+ * deleted; anything else in the folder (a VitePress config, hand-written guides) is left alone.
42
+ */
43
+ export declare const RECORD_FILE = ".linopress.json";
44
+ type FileActionKind = "create" | "update" | "delete" | "unchanged";
45
+ interface FileAction {
46
+ readonly kind: FileActionKind;
47
+ readonly path: string;
48
+ /**
49
+ * `update` only: the file exists but Linopress didn't write it (it isn't in the record), so a
50
+ * hand-written file would be replaced. `applyFiles` refuses this unless `force` is set.
51
+ */
52
+ readonly adopted?: boolean;
53
+ }
54
+ interface FilePlan {
55
+ /** Creates and updates in output order, then deletes, then unchanged files. */
56
+ readonly actions: readonly FileAction[];
57
+ readonly counts: Readonly<Record<FileActionKind, number>>;
58
+ /** The record after applying: every file the edition writes. */
59
+ readonly owned: readonly string[];
60
+ }
61
+ /** What's in the output folder now, as far as the plan needs to know. */
62
+ interface OutputState {
63
+ /** Files listed in the record (written by an earlier run). */
64
+ readonly owned: readonly string[];
65
+ /** Current bytes of the files the plan looked at; missing files are absent. */
66
+ readonly existing: ReadonlyMap<string, Uint8Array>;
67
+ }
68
+ /**
69
+ * Diffs the files an edition writes against the output folder. Pure.
70
+ *
71
+ * - not on disk → **create**; different bytes on disk → **update**; same bytes → **unchanged**.
72
+ * Compared with the disk, not a stored hash, so a file edited by hand is put back.
73
+ * - in the record, no longer written, still on disk → **delete**.
74
+ */
75
+ export declare function planFiles(files: readonly OutputFile[], state: OutputState): FilePlan;
76
+ /** True when applying the plan would write or delete nothing. */
77
+ export declare function isEmptyFilePlan(p: FilePlan): boolean;
78
+ /**
79
+ * Absolute path of an edition-relative `path` inside `out`. Throws for paths that would land
80
+ * outside it (a tampered record must not make Linopress delete files elsewhere).
81
+ */
82
+ export declare function outputPath(out: string, path: string): string;
83
+ /** Reads the record; an empty list when there is none yet. */
84
+ export declare function readRecord(out: string): Promise<string[]>;
85
+ /** Reads the record and the current bytes of every file `files` writes or the record lists. */
86
+ export declare function readOutputState(out: string, files: readonly OutputFile[]): Promise<OutputState>;
87
+ type FileEvent = {
88
+ readonly kind: "created" | "updated" | "deleted";
89
+ readonly path: string;
90
+ };
91
+ interface ApplyFilesOptions {
92
+ /** The output folder. Created if missing. */
93
+ readonly out: string;
94
+ readonly files: readonly OutputFile[];
95
+ /** The plan to carry out, from `planFiles` over `readOutputState(out, files)`. */
96
+ readonly plan: FilePlan;
97
+ /** The record the plan was made from (`OutputState.owned`). */
98
+ readonly owned: readonly string[];
99
+ /**
100
+ * Replace files Linopress didn't write (`adopted` updates) and take them over. Without it,
101
+ * `applyFiles` throws before writing anything when the plan has any.
102
+ */
103
+ readonly force?: boolean;
104
+ readonly onEvent?: (event: FileEvent) => void;
105
+ }
106
+ /** Paths of files the plan would replace although Linopress didn't write them. */
107
+ export declare function adoptedPaths(p: FilePlan): string[];
108
+ /**
109
+ * Writes created and updated files, deletes files of removed pages (and directories that become
110
+ * empty), and updates the record. The record is widened before the first write, so a run that
111
+ * stops halfway still knows which files are its own.
112
+ */
113
+ export declare function applyFiles(options: ApplyFilesOptions): Promise<void>;
114
+ /** Human-readable file plan, one line per file, in the style of `formatPlan`. */
115
+ export declare function formatFilePlan(p: FilePlan, options?: {
116
+ readonly verbose?: boolean;
117
+ }): string;
118
+ export type { ApplyFilesOptions, FileAction, FileActionKind, FileEvent, FilePlan, MarkdownEdition, OutputFile, OutputState, RenderMarkdownOptions };
@@ -0,0 +1 @@
1
+ export { r as RECORD_FILE, i as adoptedPaths, a as applyFiles, o as formatFilePlan, s as isEmptyFilePlan, t as markdownTransforms, c as outputPath, l as planFiles, u as readOutputState, d as readRecord, n as renderMarkdownEdition } from "./src-zk0Kzn3v.js";
@@ -0,0 +1,185 @@
1
+ import { posix } from "node:path";
2
+ // ../core/src/format.ts
3
+ const SYMBOL = {
4
+ create: "+",
5
+ update: "~",
6
+ move: ">",
7
+ archive: "-",
8
+ unchanged: "="
9
+ };
10
+ function where(parentPath, sortOrder) {
11
+ return `${parentPath ?? "(top level)"} #${sortOrder}`;
12
+ }
13
+ function detail(action) {
14
+ switch (action.kind) {
15
+ case "create": return `under ${where(action.parentPath, action.sortOrder)}`;
16
+ case "update":
17
+ case "move": {
18
+ const parts = [];
19
+ if (action.changes.includes("content")) parts.push("content");
20
+ if (action.changes.includes("title")) parts.push(`title "${action.from.title}"`);
21
+ if (action.changes.includes("parent") || action.changes.includes("order")) parts.push(`${where(action.from.parentPath, action.from.sortOrder)} → ${where(action.parentPath, action.sortOrder)}`);
22
+ return parts.join(", ");
23
+ }
24
+ case "archive":
25
+ case "unchanged": return action.url;
26
+ }
27
+ }
28
+ /** Human-readable plan, one line per action, terraform-style. */
29
+ function formatPlan(p, options = {}) {
30
+ const { create, update, move, archive, unchanged } = p.counts;
31
+ const lines = [`${create} to create, ${update} to update, ${move} to move, ${archive} to archive, ${unchanged} unchanged`];
32
+ const shown = p.actions.filter((a) => options.verbose || a.kind !== "unchanged");
33
+ if (shown.length > 0) lines.push("");
34
+ const titleWidth = Math.max(0, ...shown.map((a) => a.title.length));
35
+ const pathWidth = Math.max(0, ...shown.map((a) => a.path.length + 2));
36
+ for (const a of shown) {
37
+ const title = a.title.padEnd(titleWidth);
38
+ const path = `(${a.path})`.padEnd(pathWidth);
39
+ lines.push(` ${SYMBOL[a.kind]} ${a.kind.padEnd(9)} ${title} ${path} ${detail(a)}`);
40
+ }
41
+ if (p.uploads.length > 0) {
42
+ lines.push("", `Images to upload (${p.uploads.length}):`);
43
+ for (const path of p.uploads) lines.push(` ↑ ${path}`);
44
+ }
45
+ const unresolved = Object.entries(p.unresolvedLinks);
46
+ if (unresolved.length > 0) {
47
+ lines.push("", "Unresolved links (left as-is):");
48
+ for (const [path, targets] of unresolved) lines.push(` ${path} → ${targets.join(", ")}`);
49
+ }
50
+ const missing = Object.entries(p.missingImages);
51
+ if (missing.length > 0) {
52
+ lines.push("", "Missing images and files (left as-is):");
53
+ for (const [path, images] of missing) lines.push(` ${path} → ${images.join(", ")}`);
54
+ }
55
+ return lines.join("\n");
56
+ }
57
+ // ../core/src/layout.ts
58
+ /** Placeholder index body used when the source has no index page. */
59
+ function synthesizeIndex(path, pages) {
60
+ const dir = posix.dirname(path);
61
+ const href = (target) => encodeURI(posix.relative(dir, target)).replace(/[()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
62
+ const items = pages.map((p) => `- [${p.title}](${href(p.path)})`).join("\n");
63
+ return {
64
+ path,
65
+ title: "Index",
66
+ content: items ? `${items}\n` : "_No pages._\n"
67
+ };
68
+ }
69
+ /**
70
+ * Places pages in the target's tree.
71
+ *
72
+ * - **nested** (default): the index doc is the root; every other page is its child.
73
+ * - **flat**: every doc is top-level; titles get a `rootTitle · ` prefix so they group together.
74
+ *
75
+ * Order is deterministic: the index first, then pages by path.
76
+ */
77
+ function layoutPages(pages, options) {
78
+ const indexPath = options.indexPath ?? "README.md";
79
+ const separator = options.separator ?? " · ";
80
+ const seen = /* @__PURE__ */ new Set();
81
+ for (const page of pages) {
82
+ if (seen.has(page.path)) throw new Error(`Duplicate page path "${page.path}"`);
83
+ seen.add(page.path);
84
+ }
85
+ const children = pages.filter((p) => p.path !== indexPath).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
86
+ const index = pages.find((p) => p.path === indexPath) ?? synthesizeIndex(indexPath, children);
87
+ return [{
88
+ path: index.path,
89
+ title: options.rootTitle,
90
+ content: index.content,
91
+ parentPath: null,
92
+ sortOrder: 0,
93
+ ...index.sources && { sources: index.sources }
94
+ }, ...children.map((page, i) => {
95
+ const sortOrder = i + 1;
96
+ return options.mode === "nested" ? {
97
+ path: page.path,
98
+ title: page.title,
99
+ content: page.content,
100
+ parentPath: index.path,
101
+ sortOrder,
102
+ ...page.sources && { sources: page.sources }
103
+ } : {
104
+ path: page.path,
105
+ title: `${options.rootTitle}${separator}${page.title}`,
106
+ content: page.content,
107
+ parentPath: null,
108
+ sortOrder,
109
+ ...page.sources && { sources: page.sources }
110
+ };
111
+ })];
112
+ }
113
+ // ../core/src/manifest.ts
114
+ function emptyManifest() {
115
+ return {
116
+ version: 1,
117
+ containers: {},
118
+ assets: {}
119
+ };
120
+ }
121
+ function isRecord(value) {
122
+ return typeof value === "object" && value !== null && !Array.isArray(value);
123
+ }
124
+ function parseEntry(path, raw) {
125
+ if (!isRecord(raw) || typeof raw["id"] !== "string" || typeof raw["url"] !== "string") throw new Error(`Manifest entry "${path}" needs string "id" and "url"`);
126
+ return {
127
+ id: raw["id"],
128
+ url: raw["url"],
129
+ title: typeof raw["title"] === "string" ? raw["title"] : "",
130
+ parentPath: typeof raw["parentPath"] === "string" ? raw["parentPath"] : null,
131
+ sortOrder: typeof raw["sortOrder"] === "number" ? raw["sortOrder"] : -1,
132
+ hash: typeof raw["hash"] === "string" ? raw["hash"] : null
133
+ };
134
+ }
135
+ function parseAssetEntries(raw) {
136
+ if (!isRecord(raw)) throw new Error("Manifest assets must be an object");
137
+ return Object.fromEntries(Object.entries(raw).map(([path, e]) => {
138
+ if (!isRecord(e) || typeof e["hash"] !== "string" || typeof e["url"] !== "string") throw new Error(`Manifest asset "${path}" needs string "hash" and "url"`);
139
+ return [path, {
140
+ hash: e["hash"],
141
+ url: e["url"]
142
+ }];
143
+ }));
144
+ }
145
+ function parseEntries(raw) {
146
+ if (!isRecord(raw)) throw new Error("Manifest container must be an object");
147
+ return Object.fromEntries(Object.entries(raw).map(([path, e]) => [path, parseEntry(path, e)]));
148
+ }
149
+ /**
150
+ * Parses a manifest file. Also accepts the original unversioned format
151
+ * (`{ "team:<id>": { "<path>": { id, url, hash } } }`).
152
+ */
153
+ function parseManifest(json) {
154
+ const raw = JSON.parse(json);
155
+ if (!isRecord(raw)) throw new Error("Manifest must be a JSON object");
156
+ const containers = raw["version"] === 1 ? raw["containers"] : raw;
157
+ if (raw["version"] !== void 0 && raw["version"] !== 1) throw new Error(`Unsupported manifest version ${String(raw["version"])}`);
158
+ if (!isRecord(containers)) throw new Error("Manifest is missing \"containers\"");
159
+ const assets = raw["version"] === 1 ? raw["assets"] ?? {} : {};
160
+ if (!isRecord(assets)) throw new Error("Manifest \"assets\" must be an object");
161
+ return {
162
+ version: 1,
163
+ containers: Object.fromEntries(Object.entries(containers).map(([key, entries]) => [key, parseEntries(entries)])),
164
+ assets: Object.fromEntries(Object.entries(assets).map(([key, entries]) => [key, parseAssetEntries(entries)]))
165
+ };
166
+ }
167
+ function serializeManifest(manifest) {
168
+ return `${JSON.stringify(manifest, null, 2)}\n`;
169
+ }
170
+ // ../core/src/model.ts
171
+ /** Stable string key for a container, used to scope the manifest. */
172
+ function containerKey(container) {
173
+ return `${container.type}:${container.id}`;
174
+ }
175
+ /** Parses `team:<id>` / `project:<id>`. */
176
+ function parseContainerKey(key) {
177
+ const [type, ...rest] = key.split(":");
178
+ const id = rest.join(":");
179
+ if (type !== "team" && type !== "project" || !id) throw new Error(`Invalid container key "${key}", expected "team:<id>" or "project:<id>"`);
180
+ return {
181
+ type,
182
+ id
183
+ };
184
+ }
185
+ export { serializeManifest as a, parseManifest as i, parseContainerKey as n, layoutPages as o, emptyManifest as r, formatPlan as s, containerKey as t };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A single Markdown page produced by a source (for TypeDoc: one module).
3
+ * Its `path` is its identity across runs, so keep it stable.
4
+ */
5
+ interface Page {
6
+ /** POSIX path relative to the edition root, e.g. `client.md` or `internal/retry.md`. */
7
+ readonly path: string;
8
+ /** Human title, without any edition prefix. */
9
+ readonly title: string;
10
+ /** Markdown body. Relative `.md` links are rewritten to document URLs at sync time. */
11
+ readonly content: string;
12
+ /** Absolute paths of the source files the page documents (for TypeDoc: the module's file). */
13
+ readonly sources?: readonly string[];
14
+ }
15
+ /** Where documents live in the target. Linear accepts both teams and projects. */
16
+ type Container = {
17
+ readonly type: "team";
18
+ readonly id: string;
19
+ } | {
20
+ readonly type: "project";
21
+ readonly id: string;
22
+ };
23
+ /** How pages are arranged in the target. */
24
+ type LayoutMode = "nested" | "flat";
25
+ /**
26
+ * A page placed in the target's tree: the unit the engine plans and applies.
27
+ * `parentPath` points at another node's `path` (or `null` for a top-level doc).
28
+ */
29
+ interface DocNode {
30
+ readonly path: string;
31
+ readonly title: string;
32
+ readonly content: string;
33
+ readonly parentPath: string | null;
34
+ readonly sortOrder: number;
35
+ /** The page's source files, if the source knows them. Used by footers, never hashed. */
36
+ readonly sources?: readonly string[];
37
+ }
38
+ /** Stable string key for a container, used to scope the manifest. */
39
+ declare function containerKey(container: Container): string;
40
+ /** Parses `team:<id>` / `project:<id>`. */
41
+ declare function parseContainerKey(key: string): Container;
42
+ export { containerKey as a, Page as i, DocNode as n, parseContainerKey as o, LayoutMode as r, Container as t };