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.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/bin/linopress.js +3 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +627 -0
- package/dist/config-BsoZ23gK.js +152 -0
- package/dist/config.d.ts +72 -0
- package/dist/config.js +1 -0
- package/dist/index.d.ts +263 -0
- package/dist/index.js +3 -0
- package/dist/linear.d.ts +70 -0
- package/dist/linear.js +1 -0
- package/dist/markdown.d.ts +118 -0
- package/dist/markdown.js +1 -0
- package/dist/model-CJlOLfea.js +185 -0
- package/dist/model-CgSIC_VE.d.ts +42 -0
- package/dist/src-BU0LDvW9.js +593 -0
- package/dist/src-Bm80C3HE.js +170 -0
- package/dist/src-D8wnsQ43.js +226 -0
- package/dist/src-zk0Kzn3v.js +249 -0
- package/dist/target-Cb9cQbDZ.d.ts +48 -0
- package/dist/transforms-BBEyouxz.d.ts +81 -0
- package/dist/typedoc.d.ts +43 -0
- package/dist/typedoc.js +1 -0
- package/package.json +86 -3
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { access } from "node:fs/promises";
|
|
2
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
// src/config.ts
|
|
5
|
+
/**
|
|
6
|
+
* `defineConfig` and the types of `linopress.config.ts`, plus `validateConfig` and `loadConfig`.
|
|
7
|
+
*
|
|
8
|
+
* @module linopress-cli/config
|
|
9
|
+
*/
|
|
10
|
+
/** Identity helper that gives `linopress.config.ts` type checking. */
|
|
11
|
+
function defineConfig(config) {
|
|
12
|
+
return config;
|
|
13
|
+
}
|
|
14
|
+
const CONFIG_FILES = [
|
|
15
|
+
"linopress.config.ts",
|
|
16
|
+
"linopress.config.mts",
|
|
17
|
+
"linopress.config.js",
|
|
18
|
+
"linopress.config.mjs"
|
|
19
|
+
];
|
|
20
|
+
const TOP_KEYS = [
|
|
21
|
+
"editions",
|
|
22
|
+
"manifest",
|
|
23
|
+
"repository"
|
|
24
|
+
];
|
|
25
|
+
const SOURCE_KEYS = [
|
|
26
|
+
"typedoc",
|
|
27
|
+
"typedocOptions",
|
|
28
|
+
"dir",
|
|
29
|
+
"title",
|
|
30
|
+
"target"
|
|
31
|
+
];
|
|
32
|
+
const TARGET_KEYS = {
|
|
33
|
+
linear: [
|
|
34
|
+
"team",
|
|
35
|
+
"project",
|
|
36
|
+
"layout"
|
|
37
|
+
],
|
|
38
|
+
markdown: ["out"]
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* True when `a` and `b` are the same folder or one is inside the other.
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
function overlaps(a, b) {
|
|
46
|
+
const inside = (x, y) => {
|
|
47
|
+
const rel = relative(y, x);
|
|
48
|
+
return !rel.startsWith("..") && !isAbsolute(rel);
|
|
49
|
+
};
|
|
50
|
+
return inside(a, b) || inside(b, a);
|
|
51
|
+
}
|
|
52
|
+
function isRecord(value) {
|
|
53
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Checks a config's shape and returns it typed. Throws one error listing every problem, with the
|
|
57
|
+
* path to each (`editions.public.out`), so typos and leftovers don't silently do nothing.
|
|
58
|
+
* `dir` is the config file's folder, which relative `out` folders resolve against.
|
|
59
|
+
*/
|
|
60
|
+
function validateConfig(raw, dir = process.cwd()) {
|
|
61
|
+
const problems = [];
|
|
62
|
+
const fail = (path, message) => problems.push(`${path}: ${message}`);
|
|
63
|
+
const optionalString = (obj, key, path) => {
|
|
64
|
+
const v = obj[key];
|
|
65
|
+
if (v !== void 0 && (typeof v !== "string" || v.trim() === "")) fail(`${path}.${key}`, "must be a non-empty string");
|
|
66
|
+
};
|
|
67
|
+
if (!isRecord(raw)) throw new Error("The config must export an object: defineConfig({ editions })");
|
|
68
|
+
for (const key of Object.keys(raw)) if (!TOP_KEYS.includes(key)) fail(key, `unknown option (expected ${TOP_KEYS.join(", ")})`);
|
|
69
|
+
optionalString(raw, "manifest", "config");
|
|
70
|
+
optionalString(raw, "repository", "config");
|
|
71
|
+
const editions = raw["editions"];
|
|
72
|
+
const outs = [];
|
|
73
|
+
if (!isRecord(editions)) fail("editions", "must be an object of named editions");
|
|
74
|
+
else for (const [name, edition] of Object.entries(editions)) {
|
|
75
|
+
const at = `editions.${name}`;
|
|
76
|
+
if (!/^[\w.-]+$/.test(name)) fail(at, "edition names may only use letters, digits, _ . -");
|
|
77
|
+
if (!isRecord(edition)) {
|
|
78
|
+
fail(at, "must be an object");
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if ("linear" in edition) fail(`${at}.linear`, "replaced by target: \"linear\" with team / project on the edition");
|
|
82
|
+
const target = edition["target"];
|
|
83
|
+
if (target !== "linear" && target !== "markdown") {
|
|
84
|
+
fail(`${at}.target`, "must be \"linear\" or \"markdown\"");
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const allowed = [
|
|
88
|
+
...SOURCE_KEYS,
|
|
89
|
+
...TARGET_KEYS[target],
|
|
90
|
+
"linear"
|
|
91
|
+
];
|
|
92
|
+
for (const key of Object.keys(edition)) {
|
|
93
|
+
if (allowed.includes(key)) continue;
|
|
94
|
+
const other = target === "linear" ? "markdown" : "linear";
|
|
95
|
+
fail(`${at}.${key}`, TARGET_KEYS[other].includes(key) ? `only applies to target: "${other}"` : "unknown option");
|
|
96
|
+
}
|
|
97
|
+
for (const key of [
|
|
98
|
+
"typedoc",
|
|
99
|
+
"dir",
|
|
100
|
+
"title",
|
|
101
|
+
"team",
|
|
102
|
+
"project",
|
|
103
|
+
"out"
|
|
104
|
+
]) optionalString(edition, key, at);
|
|
105
|
+
if (edition["typedoc"] !== void 0 && edition["dir"] !== void 0) fail(at, "set typedoc or dir, not both");
|
|
106
|
+
if (edition["typedocOptions"] !== void 0 && !isRecord(edition["typedocOptions"])) fail(`${at}.typedocOptions`, "must be an object of TypeDoc options");
|
|
107
|
+
if (target === "linear") {
|
|
108
|
+
if (edition["team"] !== void 0 && edition["project"] !== void 0) fail(at, "set team or project, not both");
|
|
109
|
+
const layout = edition["layout"];
|
|
110
|
+
if (layout !== void 0 && layout !== "nested" && layout !== "flat") fail(`${at}.layout`, "must be \"nested\" or \"flat\"");
|
|
111
|
+
} else if (edition["out"] === void 0) fail(`${at}.out`, "is required for target: \"markdown\"");
|
|
112
|
+
else if (typeof edition["out"] === "string" && edition["out"].trim() !== "") {
|
|
113
|
+
const out = resolve(dir, edition["out"]);
|
|
114
|
+
const other = outs.find((o) => overlaps(o.out, out));
|
|
115
|
+
if (other) fail(`${at}.out`, `overlaps editions.${other.name}.out; each Markdown edition needs its own folder, or they would delete each other's files`);
|
|
116
|
+
outs.push({
|
|
117
|
+
name,
|
|
118
|
+
out
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (problems.length > 0) throw new Error(`Invalid config:\n${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
123
|
+
return raw;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Loads `linopress.config.*` from `cwd` (or `file`). TypeScript configs are imported with
|
|
127
|
+
* Node's built-in type stripping (Node ≥ 22.18), so they must use erasable syntax only.
|
|
128
|
+
* Returns `null` when there is no config file.
|
|
129
|
+
*/
|
|
130
|
+
async function loadConfig(cwd, file) {
|
|
131
|
+
const candidates = file ? [resolve(cwd, file)] : CONFIG_FILES.map((f) => resolve(cwd, f));
|
|
132
|
+
for (const candidate of candidates) {
|
|
133
|
+
try {
|
|
134
|
+
await access(candidate);
|
|
135
|
+
} catch {
|
|
136
|
+
if (file) throw new Error(`Config file not found: ${candidate}`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const mod = await import(pathToFileURL(candidate).href);
|
|
140
|
+
if (mod.default === void 0) throw new Error(`${candidate} must default-export defineConfig({ editions })`);
|
|
141
|
+
try {
|
|
142
|
+
return {
|
|
143
|
+
config: validateConfig(mod.default, dirname(candidate)),
|
|
144
|
+
dir: dirname(candidate)
|
|
145
|
+
};
|
|
146
|
+
} catch (error) {
|
|
147
|
+
throw new Error(`${candidate}: ${error.message}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
export { validateConfig as a, overlaps as i, defineConfig as n, loadConfig as r, CONFIG_FILES as t };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { r as LayoutMode } from "./model-CgSIC_VE.js";
|
|
2
|
+
interface EditionSource {
|
|
3
|
+
/** A TypeDoc options file; Linopress runs TypeDoc with typedoc-plugin-markdown. */
|
|
4
|
+
readonly typedoc?: string;
|
|
5
|
+
/**
|
|
6
|
+
* TypeDoc options applied over the `typedoc` file, so one file can serve several editions:
|
|
7
|
+
* `{ excludeInternal: true }` for the public one. Ignored with `dir`.
|
|
8
|
+
*/
|
|
9
|
+
readonly typedocOptions?: Readonly<Record<string, unknown>>;
|
|
10
|
+
/** Or: a folder of already-generated Markdown. */
|
|
11
|
+
readonly dir?: string;
|
|
12
|
+
/** Title of the index page (and the title prefix in flat layout). Defaults to "API Reference". */
|
|
13
|
+
readonly title?: string;
|
|
14
|
+
}
|
|
15
|
+
/** An edition synced to Linear Documents. Without `team` or `project` it can be planned, not pushed. */
|
|
16
|
+
export interface LinearEditionConfig extends EditionSource {
|
|
17
|
+
readonly target: "linear";
|
|
18
|
+
readonly team?: string | undefined;
|
|
19
|
+
readonly project?: string | undefined;
|
|
20
|
+
/** `nested` (default) puts docs under the index doc; `flat` keeps them top-level. */
|
|
21
|
+
readonly layout?: LayoutMode;
|
|
22
|
+
}
|
|
23
|
+
/** An edition written as Markdown files, for VitePress or any other static site generator. */
|
|
24
|
+
export interface MarkdownEditionConfig extends EditionSource {
|
|
25
|
+
readonly target: "markdown";
|
|
26
|
+
/**
|
|
27
|
+
* Folder to write to. Linopress only deletes files it wrote there (listed in its
|
|
28
|
+
* `.linopress.json`), so it can share the folder with a site's config and hand-written pages.
|
|
29
|
+
*/
|
|
30
|
+
readonly out: string;
|
|
31
|
+
}
|
|
32
|
+
/** One edition of the docs, e.g. `internal` (with `@internal`, to Linear) or `public` (to files). */
|
|
33
|
+
export type EditionConfig = LinearEditionConfig | MarkdownEditionConfig;
|
|
34
|
+
export interface LinopressConfig {
|
|
35
|
+
readonly editions: Readonly<Record<string, EditionConfig>>;
|
|
36
|
+
/** Linear sync state. Defaults to `.linopress-manifest.json`. */
|
|
37
|
+
readonly manifest?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Repository that doc footers link to, at the synced commit: a web URL
|
|
40
|
+
* (`https://github.com/acme/billing`, `github.com/acme/billing`), an SSH remote, or GitHub
|
|
41
|
+
* shorthand (`acme/billing`). Defaults to the git `origin` remote. Without either, or when the
|
|
42
|
+
* commit isn't on a remote branch, footers name the files without links.
|
|
43
|
+
*/
|
|
44
|
+
readonly repository?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Identity helper that gives `linopress.config.ts` type checking. */
|
|
47
|
+
export declare function defineConfig(config: LinopressConfig): LinopressConfig;
|
|
48
|
+
export declare const CONFIG_FILES: readonly string[];
|
|
49
|
+
export interface LoadedConfig {
|
|
50
|
+
readonly config: LinopressConfig;
|
|
51
|
+
/** Directory of the config file; relative paths in the config resolve against it. */
|
|
52
|
+
readonly dir: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* True when `a` and `b` are the same folder or one is inside the other.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export declare function overlaps(a: string, b: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Checks a config's shape and returns it typed. Throws one error listing every problem, with the
|
|
62
|
+
* path to each (`editions.public.out`), so typos and leftovers don't silently do nothing.
|
|
63
|
+
* `dir` is the config file's folder, which relative `out` folders resolve against.
|
|
64
|
+
*/
|
|
65
|
+
export declare function validateConfig(raw: unknown, dir?: string): LinopressConfig;
|
|
66
|
+
/**
|
|
67
|
+
* Loads `linopress.config.*` from `cwd` (or `file`). TypeScript configs are imported with
|
|
68
|
+
* Node's built-in type stripping (Node ≥ 22.18), so they must use erasable syntax only.
|
|
69
|
+
* Returns `null` when there is no config file.
|
|
70
|
+
*/
|
|
71
|
+
export declare function loadConfig(cwd: string, file?: string): Promise<LoadedConfig | null>;
|
|
72
|
+
export {};
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as CONFIG_FILES, n as defineConfig, r as loadConfig, i as overlaps, a as validateConfig } from "./config-BsoZ23gK.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic API: the sync engine (layout, plan, apply, manifest, link rewriting).
|
|
3
|
+
* Targets and sources live in `linopress-cli/linear` and `linopress-cli/typedoc`.
|
|
4
|
+
*
|
|
5
|
+
* @module linopress-cli
|
|
6
|
+
*/
|
|
7
|
+
import { _ as rewriteImages, a as unlinkInPageLinks, c as AssetEntry, d as ReadAsset, f as assetHash, g as pendingAssetUrl, h as findImages, i as stripHtmlAnchors, l as CollectedAssets, m as contentTypeFor, n as applyTransforms, o as Asset, p as collectAssets, r as defaultTransforms, s as AssetEntries, t as MarkdownTransform, u as ImageRewriteResult, v as uploadedUrl } from "./transforms-BBEyouxz.js";
|
|
8
|
+
import { a as containerKey, i as Page, n as DocNode, o as parseContainerKey, r as LayoutMode, t as Container } from "./model-CgSIC_VE.js";
|
|
9
|
+
import { a as RemoteDoc, i as DocumentTarget, n as DocNotFoundError, o as UpdateDocInput, r as DocPosition, t as CreateDocInput } from "./target-Cb9cQbDZ.js";
|
|
10
|
+
/**
|
|
11
|
+
* What Linopress knows about a doc it created: identity, last-synced position and content hash.
|
|
12
|
+
*/
|
|
13
|
+
interface ManifestEntry {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly url: string;
|
|
16
|
+
readonly title: string;
|
|
17
|
+
readonly parentPath: string | null;
|
|
18
|
+
readonly sortOrder: number;
|
|
19
|
+
/** Hash of the last content pushed; `null` right after creation (body is a placeholder). */
|
|
20
|
+
readonly hash: string | null;
|
|
21
|
+
}
|
|
22
|
+
/** Entries for one container, keyed by page path. */
|
|
23
|
+
type ManifestEntries = Record<string, ManifestEntry>;
|
|
24
|
+
interface Manifest {
|
|
25
|
+
readonly version: 1;
|
|
26
|
+
/** Keyed by container key (`team:<id>` / `project:<id>`). */
|
|
27
|
+
readonly containers: Record<string, ManifestEntries>;
|
|
28
|
+
/** Uploaded images, keyed like `containers`, then by edition-relative asset path. */
|
|
29
|
+
readonly assets: Record<string, AssetEntries>;
|
|
30
|
+
}
|
|
31
|
+
export declare function emptyManifest(): Manifest;
|
|
32
|
+
/**
|
|
33
|
+
* Parses a manifest file. Also accepts the original unversioned format
|
|
34
|
+
* (`{ "team:<id>": { "<path>": { id, url, hash } } }`).
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseManifest(json: string): Manifest;
|
|
37
|
+
export declare function serializeManifest(manifest: Manifest): string;
|
|
38
|
+
type Change = "content" | "title" | "parent" | "order";
|
|
39
|
+
interface ActionBase {
|
|
40
|
+
readonly path: string;
|
|
41
|
+
readonly title: string;
|
|
42
|
+
}
|
|
43
|
+
type PlanAction = (ActionBase & {
|
|
44
|
+
readonly kind: "create";
|
|
45
|
+
readonly parentPath: string | null;
|
|
46
|
+
readonly sortOrder: number;
|
|
47
|
+
}) | (ActionBase & {
|
|
48
|
+
readonly kind: "update" | "move";
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly url: string;
|
|
51
|
+
readonly changes: readonly Change[];
|
|
52
|
+
readonly from: {
|
|
53
|
+
readonly title: string;
|
|
54
|
+
readonly parentPath: string | null;
|
|
55
|
+
readonly sortOrder: number;
|
|
56
|
+
};
|
|
57
|
+
readonly parentPath: string | null;
|
|
58
|
+
readonly sortOrder: number;
|
|
59
|
+
}) | (ActionBase & {
|
|
60
|
+
readonly kind: "archive";
|
|
61
|
+
readonly id: string;
|
|
62
|
+
readonly url: string;
|
|
63
|
+
}) | (ActionBase & {
|
|
64
|
+
readonly kind: "unchanged";
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly url: string;
|
|
67
|
+
});
|
|
68
|
+
type ActionKind = PlanAction["kind"];
|
|
69
|
+
interface Plan {
|
|
70
|
+
/** In execution order: creates (parents first), updates/moves, archives (children first). */
|
|
71
|
+
readonly actions: readonly PlanAction[];
|
|
72
|
+
readonly counts: Readonly<Record<ActionKind, number>>;
|
|
73
|
+
/** page path → edition-relative link targets that don't exist in this edition. */
|
|
74
|
+
readonly unresolvedLinks: Readonly<Record<string, readonly string[]>>;
|
|
75
|
+
/** page path → local images it embeds that don't exist (left as written). */
|
|
76
|
+
readonly missingImages: Readonly<Record<string, readonly string[]>>;
|
|
77
|
+
/** Edition-relative paths of images to upload (new or changed bytes), one per distinct file. */
|
|
78
|
+
readonly uploads: readonly string[];
|
|
79
|
+
}
|
|
80
|
+
/** The images an edition embeds, and what was uploaded before. */
|
|
81
|
+
interface SyncAssets {
|
|
82
|
+
/** Images that exist, keyed by edition-relative path (see `collectAssets`). */
|
|
83
|
+
readonly files: ReadonlyMap<string, Asset>;
|
|
84
|
+
/** Uploaded assets from the manifest. */
|
|
85
|
+
readonly entries: AssetEntries;
|
|
86
|
+
}
|
|
87
|
+
interface PlanOptions {
|
|
88
|
+
readonly footer?: (node: DocNode) => string;
|
|
89
|
+
/** Images to resolve. When omitted, images are left as written and not reported. */
|
|
90
|
+
readonly assets?: SyncAssets;
|
|
91
|
+
/** Markdown clean-up before link rewriting. Defaults to Linear's (`defaultTransforms`). */
|
|
92
|
+
readonly transforms?: readonly MarkdownTransform[];
|
|
93
|
+
}
|
|
94
|
+
/** URL used in dry runs for docs that don't exist yet. */
|
|
95
|
+
export declare const pendingUrl: (path: string) => string;
|
|
96
|
+
/**
|
|
97
|
+
* Diffs the desired docs against the manifest. Pure: no I/O, safe for dry runs.
|
|
98
|
+
*
|
|
99
|
+
* - not in the manifest → **create**
|
|
100
|
+
* - content or title hash differs → **update** (may also move)
|
|
101
|
+
* - only parent / sort order differs → **move**
|
|
102
|
+
* - in the manifest but no longer produced → **archive**
|
|
103
|
+
*/
|
|
104
|
+
export declare function plan(nodes: readonly DocNode[], entries: ManifestEntries, options?: PlanOptions): Plan;
|
|
105
|
+
/** Assets with no uploaded copy, one per distinct content hash. */
|
|
106
|
+
export declare function pendingUploads(assets: SyncAssets | undefined): string[];
|
|
107
|
+
/** True when applying the plan would change nothing. */
|
|
108
|
+
export declare function isEmptyPlan(p: Plan): boolean;
|
|
109
|
+
/** Body written in pass 1, replaced in pass 2 once every doc has a URL. */
|
|
110
|
+
export declare const PLACEHOLDER_CONTENT = "_Generating…_";
|
|
111
|
+
type ApplyEvent = {
|
|
112
|
+
readonly kind: "created" | "updated" | "moved" | "archived" | "uploaded";
|
|
113
|
+
readonly path: string;
|
|
114
|
+
readonly url: string;
|
|
115
|
+
} | {
|
|
116
|
+
readonly kind: "unchanged";
|
|
117
|
+
readonly path: string;
|
|
118
|
+
readonly url: string;
|
|
119
|
+
};
|
|
120
|
+
interface ApplyOptions {
|
|
121
|
+
readonly nodes: readonly DocNode[];
|
|
122
|
+
/** Current entries for the target's container; not mutated. */
|
|
123
|
+
readonly entries: ManifestEntries;
|
|
124
|
+
readonly target: DocumentTarget;
|
|
125
|
+
readonly footer?: (node: DocNode) => string;
|
|
126
|
+
/** Markdown clean-up before link rewriting. Defaults to Linear's (`defaultTransforms`). */
|
|
127
|
+
readonly transforms?: readonly MarkdownTransform[];
|
|
128
|
+
/**
|
|
129
|
+
* Images the docs embed, and the manifest's uploaded assets. New or changed files are uploaded
|
|
130
|
+
* through `target.uploadAsset`. When omitted, images are left as written.
|
|
131
|
+
*/
|
|
132
|
+
readonly assets?: SyncAssets;
|
|
133
|
+
/**
|
|
134
|
+
* Called with the up-to-date asset entries after every upload, and once at the end when entries
|
|
135
|
+
* for images no longer embedded are dropped.
|
|
136
|
+
*/
|
|
137
|
+
readonly onAssetEntriesChange?: (entries: AssetEntries) => Promise<void> | void;
|
|
138
|
+
/**
|
|
139
|
+
* Called with the up-to-date entries after every successful mutation, so a run that stops
|
|
140
|
+
* halfway can resume from what was saved. A doc can still be orphaned if the process dies
|
|
141
|
+
* after the target created it but before this callback persisted the entry (or if this
|
|
142
|
+
* callback throws); the next run then creates a duplicate.
|
|
143
|
+
*/
|
|
144
|
+
readonly onEntriesChange?: (entries: ManifestEntries) => Promise<void> | void;
|
|
145
|
+
readonly onEvent?: (event: ApplyEvent) => void;
|
|
146
|
+
}
|
|
147
|
+
interface ApplyResult {
|
|
148
|
+
readonly entries: ManifestEntries;
|
|
149
|
+
/** Asset entries for exactly the images the docs embed (empty when `assets` was omitted). */
|
|
150
|
+
readonly assets: AssetEntries;
|
|
151
|
+
readonly events: readonly ApplyEvent[];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Syncs `nodes` into `target`.
|
|
155
|
+
*
|
|
156
|
+
* 0. **Upload** images whose bytes weren't uploaded before, so a failed upload changes no doc.
|
|
157
|
+
* 1. **Ensure:** create every missing doc (parents first) with a placeholder body, so every
|
|
158
|
+
* page has a URL.
|
|
159
|
+
* 2. **Write:** render every doc with links rewritten to those URLs; update the ones whose
|
|
160
|
+
* hash, title or position changed.
|
|
161
|
+
* 3. **Archive** docs that are no longer produced (children first). Never hard-deletes.
|
|
162
|
+
*/
|
|
163
|
+
export declare function apply(options: ApplyOptions): Promise<ApplyResult>;
|
|
164
|
+
interface FormatPlanOptions {
|
|
165
|
+
/** Include unchanged docs. Defaults to `false`. */
|
|
166
|
+
readonly verbose?: boolean;
|
|
167
|
+
}
|
|
168
|
+
/** Human-readable plan, one line per action, terraform-style. */
|
|
169
|
+
export declare function formatPlan(p: Plan, options?: FormatPlanOptions): string;
|
|
170
|
+
/**
|
|
171
|
+
* Normalizes Markdown so that cosmetic differences (CRLF checkouts, trailing blank lines)
|
|
172
|
+
* don't count as content changes. Leading indentation and trailing spaces inside the document
|
|
173
|
+
* are kept: they can be meaningful (indented code, two-space hard line breaks).
|
|
174
|
+
*/
|
|
175
|
+
export declare function normalizeMarkdown(markdown: string): string;
|
|
176
|
+
/**
|
|
177
|
+
* Short, stable hash of a document body. Title and position are tracked separately in the
|
|
178
|
+
* manifest, so a rename shows up as a title change, not a content change.
|
|
179
|
+
*/
|
|
180
|
+
export declare function contentHash(body: string): string;
|
|
181
|
+
interface LayoutOptions {
|
|
182
|
+
readonly mode: LayoutMode;
|
|
183
|
+
/** Title of the index doc, and the title prefix in flat mode. */
|
|
184
|
+
readonly rootTitle: string;
|
|
185
|
+
/** Path of the index page. Defaults to `README.md` (TypeDoc's entry page). */
|
|
186
|
+
readonly indexPath?: string;
|
|
187
|
+
/** Separator between the root title and page titles in flat mode. Defaults to ` · `. */
|
|
188
|
+
readonly separator?: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Places pages in the target's tree.
|
|
192
|
+
*
|
|
193
|
+
* - **nested** (default): the index doc is the root; every other page is its child.
|
|
194
|
+
* - **flat**: every doc is top-level; titles get a `rootTitle · ` prefix so they group together.
|
|
195
|
+
*
|
|
196
|
+
* Order is deterministic: the index first, then pages by path.
|
|
197
|
+
*/
|
|
198
|
+
export declare function layoutPages(pages: readonly Page[], options: LayoutOptions): DocNode[];
|
|
199
|
+
interface RewriteResult {
|
|
200
|
+
readonly content: string;
|
|
201
|
+
/** Edition-relative paths that were linked but could not be resolved to a URL. */
|
|
202
|
+
readonly unresolved: readonly string[];
|
|
203
|
+
}
|
|
204
|
+
interface RewriteOptions {
|
|
205
|
+
/**
|
|
206
|
+
* Keep `#fragment`s on rewritten links. Defaults to `false`, because Linear ignores fragments
|
|
207
|
+
* on document URLs (its heading ids are UUIDs, not TypeDoc slugs).
|
|
208
|
+
*/
|
|
209
|
+
readonly keepFragments?: boolean;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Resolves a relative link `target` written in `fromPath` to an edition-relative path.
|
|
213
|
+
* Returns `null` for absolute URLs, root-relative paths and paths escaping the edition.
|
|
214
|
+
*/
|
|
215
|
+
export declare function resolveLinkPath(fromPath: string, target: string): string | null;
|
|
216
|
+
/**
|
|
217
|
+
* Rewrites relative `.md` links (`[x](./money.md#anchor)`) to target URLs, dropping the fragment
|
|
218
|
+
* unless `keepFragments` is set. Links in code are left untouched, as are links that `urlFor`
|
|
219
|
+
* can't resolve (they are reported in `unresolved`).
|
|
220
|
+
*/
|
|
221
|
+
export declare function rewriteLinks(markdown: string, fromPath: string, urlFor: (path: string) => string | undefined, options?: RewriteOptions): RewriteResult;
|
|
222
|
+
/**
|
|
223
|
+
* Applies `fn` to the prose of a Markdown document, line by line. Fenced code blocks are skipped,
|
|
224
|
+
* and inline code spans are masked with opaque tokens. That way a transform can still match
|
|
225
|
+
* across them (e.g. a link whose text is `` `Money` ``) but can't change what's inside.
|
|
226
|
+
*/
|
|
227
|
+
export declare function mapProse(markdown: string, fn: (line: string) => string): string;
|
|
228
|
+
interface RenderOptions {
|
|
229
|
+
/** URL of the doc for an edition-relative path, if one exists (or is about to). */
|
|
230
|
+
readonly urlFor: (path: string) => string | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* URL of an uploaded image for an edition-relative path; `undefined` when the file is missing.
|
|
233
|
+
* When omitted, images are left as written.
|
|
234
|
+
*/
|
|
235
|
+
readonly assetUrlFor?: (path: string) => string | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* Appended to every body, e.g. "generated from commit abc123, don't edit here".
|
|
238
|
+
* The footer is **not** part of the hash, so a new commit sha alone doesn't re-push every doc.
|
|
239
|
+
*/
|
|
240
|
+
readonly footer?: (node: DocNode) => string;
|
|
241
|
+
/**
|
|
242
|
+
* Markdown clean-up applied before link rewriting. Defaults to Linear's (`defaultTransforms`);
|
|
243
|
+
* pass `[]` for none.
|
|
244
|
+
*/
|
|
245
|
+
readonly transforms?: readonly MarkdownTransform[];
|
|
246
|
+
}
|
|
247
|
+
interface RenderedDoc {
|
|
248
|
+
readonly content: string;
|
|
249
|
+
readonly hash: string;
|
|
250
|
+
readonly unresolvedLinks: readonly string[];
|
|
251
|
+
/** Local images the page embeds that don't exist. */
|
|
252
|
+
readonly missingImages: readonly string[];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Produces the final body for a doc: transforms applied, links and images rewritten, footer appended.
|
|
256
|
+
*
|
|
257
|
+
* The hash is computed here, over exactly the body we send. Never hash or diff the content a target
|
|
258
|
+
* returns: Linear's `document.content` is a lossy re-serialization (it unescapes `\|` in table
|
|
259
|
+
* cells and shortens `| ------ |` separators), so it would never match. Image URLs are part of the
|
|
260
|
+
* body, and a changed image gets a new URL, so it counts as a content change.
|
|
261
|
+
*/
|
|
262
|
+
export declare function renderDoc(node: DocNode, options: RenderOptions): RenderedDoc;
|
|
263
|
+
export { type ActionKind, type ApplyEvent, type ApplyOptions, type ApplyResult, type Asset, type AssetEntries, type AssetEntry, type Change, type CollectedAssets, type Container, type CreateDocInput, type DocNode, DocNotFoundError, type DocPosition, type DocumentTarget, type FormatPlanOptions, type ImageRewriteResult, type LayoutMode, type LayoutOptions, type Manifest, type ManifestEntries, type ManifestEntry, type MarkdownTransform, type Page, type Plan, type PlanAction, type PlanOptions, type ReadAsset, type RemoteDoc, type RenderOptions, type RenderedDoc, type RewriteOptions, type RewriteResult, type SyncAssets, type UpdateDocInput, applyTransforms, assetHash, collectAssets, containerKey, contentTypeFor, defaultTransforms, findImages, parseContainerKey, pendingAssetUrl, rewriteImages, stripHtmlAnchors, unlinkInPageLinks, uploadedUrl };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { C as rewriteLinks, S as resolveLinkPath, _ as contentTypeFor, a as pendingUploads, b as rewriteImages, c as renderDoc, d as stripHtmlAnchors, f as unlinkInPageLinks, g as collectAssets, h as assetHash, i as isEmptyPlan, l as applyTransforms, m as normalizeMarkdown, n as apply, o as pendingUrl, p as contentHash, r as DocNotFoundError, s as plan, t as PLACEHOLDER_CONTENT, u as defaultTransforms, v as findImages, w as mapProse, x as uploadedUrl, y as pendingAssetUrl } from "./src-BU0LDvW9.js";
|
|
2
|
+
import { a as serializeManifest, i as parseManifest, n as parseContainerKey, o as layoutPages, r as emptyManifest, s as formatPlan, t as containerKey } from "./model-CJlOLfea.js";
|
|
3
|
+
export { DocNotFoundError, PLACEHOLDER_CONTENT, apply, applyTransforms, assetHash, collectAssets, containerKey, contentHash, contentTypeFor, defaultTransforms, emptyManifest, findImages, formatPlan, isEmptyPlan, layoutPages, mapProse, normalizeMarkdown, parseContainerKey, parseManifest, pendingAssetUrl, pendingUploads, pendingUrl, plan, renderDoc, resolveLinkPath, rewriteImages, rewriteLinks, serializeManifest, stripHtmlAnchors, unlinkInPageLinks, uploadedUrl };
|
package/dist/linear.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Linear Documents target: the GraphQL client and `LinearTarget`.
|
|
3
|
+
*
|
|
4
|
+
* @module linopress-cli/linear
|
|
5
|
+
*/
|
|
6
|
+
import { o as Asset, t as MarkdownTransform } from "./transforms-BBEyouxz.js";
|
|
7
|
+
import { t as Container } from "./model-CgSIC_VE.js";
|
|
8
|
+
import { a as RemoteDoc, i as DocumentTarget, o as UpdateDocInput, t as CreateDocInput } from "./target-Cb9cQbDZ.js";
|
|
9
|
+
export declare const LINEAR_ENDPOINT = "https://api.linear.app/graphql";
|
|
10
|
+
interface GraphQLClientOptions {
|
|
11
|
+
/** Personal API key (`lin_api_…`) or OAuth access token. */
|
|
12
|
+
readonly apiKey: string;
|
|
13
|
+
readonly endpoint?: string;
|
|
14
|
+
/** Injectable for tests. Defaults to the global `fetch`. */
|
|
15
|
+
readonly fetch?: typeof fetch;
|
|
16
|
+
/** Retries after a rate-limit rejection (HTTP 429 or `RATELIMITED`). Default 3. */
|
|
17
|
+
readonly maxRetries?: number;
|
|
18
|
+
/** First backoff delay in ms, doubled per retry; `Retry-After` wins when present. Default 1000. */
|
|
19
|
+
readonly retryDelayMs?: number;
|
|
20
|
+
/** Per-request timeout in ms. Default 30000. */
|
|
21
|
+
readonly timeoutMs?: number;
|
|
22
|
+
}
|
|
23
|
+
interface GraphQLErrorEntry {
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly extensions?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export declare class LinearApiError extends Error {
|
|
28
|
+
readonly status: number;
|
|
29
|
+
readonly errors: readonly GraphQLErrorEntry[];
|
|
30
|
+
constructor(message: string, status: number, errors?: readonly GraphQLErrorEntry[]);
|
|
31
|
+
}
|
|
32
|
+
type GraphQLRequest = <T>(query: string, variables?: Record<string, unknown>) => Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Minimal Linear GraphQL client. We don't use `@linear/sdk` for document mutations because its
|
|
35
|
+
* published schema lacks `parentDocumentId`, `subDocumentSortOrder` and `teamId`, which the live
|
|
36
|
+
* API accepts (check with `pnpm linear:introspect`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function createGraphQLClient(options: GraphQLClientOptions): GraphQLRequest;
|
|
39
|
+
interface LinearTargetOptions extends Omit<GraphQLClientOptions, "apiKey"> {
|
|
40
|
+
readonly container: Container;
|
|
41
|
+
/** Either a key (a client is created) or a ready request function (tests, custom transport). */
|
|
42
|
+
readonly apiKey?: string;
|
|
43
|
+
readonly request?: GraphQLRequest;
|
|
44
|
+
}
|
|
45
|
+
/** Linear Documents as a Linopress target, scoped to one team or project. */
|
|
46
|
+
export declare class LinearTarget implements DocumentTarget {
|
|
47
|
+
#private;
|
|
48
|
+
readonly container: Container;
|
|
49
|
+
constructor(options: LinearTargetOptions);
|
|
50
|
+
create(input: CreateDocInput): Promise<RemoteDoc>;
|
|
51
|
+
/** Throws `DocNotFoundError` when the doc is deleted, or trashed/archived outside Linopress. */
|
|
52
|
+
update(id: string, input: UpdateDocInput): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Moves the doc to Linear's trash, which is recoverable from the UI. Linear rejects
|
|
55
|
+
* `documentUpdate` with `trashed: true` ("invalid trashed state"); `documentDelete` is its trash
|
|
56
|
+
* action, and calling it on an already-trashed doc succeeds.
|
|
57
|
+
*/
|
|
58
|
+
archive(id: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Uploads a file to Linear's storage: `fileUpload` returns a signed URL, the bytes go there with
|
|
61
|
+
* a PUT, and docs reference the returned asset URL (visible to workspace members).
|
|
62
|
+
*/
|
|
63
|
+
uploadAsset(asset: Asset): Promise<string>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The Markdown clean-up Linear needs: Linear shows `<a id>` anchors as literal text, and its heading
|
|
67
|
+
* ids are UUIDs, so `#slug` links are dead. Pass these to `plan` / `apply` when the target is a `LinearTarget`.
|
|
68
|
+
*/
|
|
69
|
+
export declare const linearTransforms: readonly MarkdownTransform[];
|
|
70
|
+
export type { GraphQLClientOptions, GraphQLErrorEntry, GraphQLRequest, LinearTargetOptions };
|
package/dist/linear.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { r as LINEAR_ENDPOINT, i as LinearApiError, n as LinearTarget, a as createGraphQLClient, t as linearTransforms } from "./src-D8wnsQ43.js";
|