linopress-cli
Programmatic API: the sync engine (layout, plan, apply, manifest, link rewriting). Targets and sources live in linopress-cli/linear and linopress-cli/typedoc.
Classes
DocNotFoundError
Thrown by a target when a doc is gone: deleted, or archived outside Linopress. apply treats it as recoverable (re-creates the doc, or skips an archive that already happened).
Extends
Error
Constructors
Constructor
new DocNotFoundError(docId, message?): DocNotFoundError;Parameters
| Parameter | Type |
|---|---|
docId | string |
message? | string |
Returns
Overrides
Error.constructor
Properties
| Property | Type |
|---|---|
docId | string |
Interfaces
ApplyOptions
Properties
| Property | Type | Description |
|---|---|---|
assets? | SyncAssets | Images the docs embed, and the manifest's uploaded assets. New or changed files are uploaded through target.uploadAsset. When omitted, images are left as written. |
entries | ManifestEntries | Current entries for the target's container; not mutated. |
footer? | (node) => string | - |
nodes | readonly DocNode[] | - |
onAssetEntriesChange? | (entries) => void | Promise<void> | Called with the up-to-date asset entries after every upload, and once at the end when entries for images no longer embedded are dropped. |
onEntriesChange? | (entries) => void | Promise<void> | Called with the up-to-date entries after every successful mutation, so a run that stops halfway can resume from what was saved. A doc can still be orphaned if the process dies after the target created it but before this callback persisted the entry (or if this callback throws); the next run then creates a duplicate. |
onEvent? | (event) => void | - |
target | DocumentTarget | - |
transforms? | readonly MarkdownTransform[] | Markdown clean-up before link rewriting. Defaults to Linear's (defaultTransforms). |
ApplyResult
Properties
| Property | Type | Description |
|---|---|---|
assets | AssetEntries | Asset entries for exactly the images the docs embed (empty when assets was omitted). |
entries | ManifestEntries | - |
events | readonly ApplyEvent[] | - |
Asset
A local file a page embeds (an image), read and hashed so it can be uploaded once.
Properties
AssetEntry
What Linopress knows about an uploaded asset: the bytes it uploaded (hash) and where they live.
Properties
| Property | Type |
|---|---|
hash | string |
url | string |
CollectedAssets
Properties
| Property | Type | Description |
|---|---|---|
assets | ReadonlyMap<string, Asset> | Every image that exists, keyed by edition-relative path. |
missing | readonly string[] | Image paths that were referenced but couldn't be read. |
CreateDocInput
Where a doc sits: under parentId (or top-level when null), at sortOrder.
Extends
Properties
| Property | Type |
|---|---|
content | string |
parentId | string | null |
sortOrder | number |
title | string |
DocNode
A page placed in the target's tree: the unit the engine plans and applies. parentPath points at another node's path (or null for a top-level doc).
Properties
DocPosition
Where a doc sits: under parentId (or top-level when null), at sortOrder.
Extended by
Properties
| Property | Type |
|---|---|
parentId | string | null |
sortOrder | number |
DocumentTarget
A place that stores documents (Linear, a fake in tests, ...). A target is bound to one container; the engine never deletes, it archives.
Methods
archive()
archive(id): Promise<void>;Soft-removes a doc (recoverable in the target's UI). Throws DocNotFoundError (or resolves) when the doc is already deleted or archived.
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<void>
create()
create(input): Promise<RemoteDoc>;Parameters
| Parameter | Type |
|---|---|
input | CreateDocInput |
Returns
Promise<RemoteDoc>
update()
update(id, input): Promise<void>;Throws DocNotFoundError when the doc is deleted or archived.
Parameters
| Parameter | Type |
|---|---|
id | string |
input | UpdateDocInput |
Returns
Promise<void>
uploadAsset()?
uploadAsset?(asset): Promise<string>;Stores a file (an image a doc embeds) and returns the URL docs should reference. Optional: without it, apply fails when there is an image to upload.
Parameters
| Parameter | Type |
|---|---|
asset | Asset |
Returns
Promise<string>
FormatPlanOptions
Properties
| Property | Type | Description |
|---|---|---|
verbose? | boolean | Include unchanged docs. Defaults to false. |
ImageRewriteResult
Properties
| Property | Type | Description |
|---|---|---|
content | string | - |
missing | readonly string[] | Edition-relative file paths that urlFor couldn't resolve (left as written). |
LayoutOptions
Properties
| Property | Type | Description |
|---|---|---|
indexPath? | string | Path of the index page. Defaults to README.md (TypeDoc's entry page). |
mode | LayoutMode | - |
rootTitle | string | Title of the index doc, and the title prefix in flat mode. |
separator? | string | Separator between the root title and page titles in flat mode. Defaults to ·. |
Manifest
Properties
| Property | Type | Description |
|---|---|---|
assets | Record<string, AssetEntries> | Uploaded images, keyed like containers, then by edition-relative asset path. |
containers | Record<string, ManifestEntries> | Keyed by container key (team:<id> / project:<id>). |
version | 1 | - |
ManifestEntry
What Linopress knows about a doc it created: identity, last-synced position and content hash.
Properties
Page
A single Markdown page produced by a source (for TypeDoc: one module). Its path is its identity across runs, so keep it stable.
Properties
Plan
Properties
| Property | Type | Description |
|---|---|---|
actions | readonly PlanAction[] | In execution order: creates (parents first), updates/moves, archives (children first). |
counts | Readonly<Record<ActionKind, number>> | - |
missingImages | Readonly<Record<string, readonly string[]>> | page path → local images it embeds that don't exist (left as written). |
unresolvedLinks | Readonly<Record<string, readonly string[]>> | page path → edition-relative link targets that don't exist in this edition. |
uploads | readonly string[] | Edition-relative paths of images to upload (new or changed bytes), one per distinct file. |
PlanOptions
Properties
| Property | Type | Description |
|---|---|---|
assets? | SyncAssets | Images to resolve. When omitted, images are left as written and not reported. |
footer? | (node) => string | - |
transforms? | readonly MarkdownTransform[] | Markdown clean-up before link rewriting. Defaults to Linear's (defaultTransforms). |
RemoteDoc
Properties
| Property | Type |
|---|---|
id | string |
url | string |
RenderedDoc
Properties
| Property | Type | Description |
|---|---|---|
content | string | - |
hash | string | - |
missingImages | readonly string[] | Local images the page embeds that don't exist. |
unresolvedLinks | readonly string[] | - |
RenderOptions
Properties
| Property | Type | Description |
|---|---|---|
assetUrlFor? | (path) => string | undefined | URL of an uploaded image for an edition-relative path; undefined when the file is missing. When omitted, images are left as written. |
footer? | (node) => string | Appended to every body, e.g. "generated from commit abc123, don't edit here". The footer is not part of the hash, so a new commit sha alone doesn't re-push every doc. |
transforms? | readonly MarkdownTransform[] | Markdown clean-up applied before link rewriting. Defaults to Linear's (defaultTransforms); pass [] for none. |
urlFor | (path) => string | undefined | URL of the doc for an edition-relative path, if one exists (or is about to). |
RewriteOptions
Properties
| Property | Type | Description |
|---|---|---|
keepFragments? | boolean | Keep #fragments on rewritten links. Defaults to false, because Linear ignores fragments on document URLs (its heading ids are UUIDs, not TypeDoc slugs). |
RewriteResult
Properties
| Property | Type | Description |
|---|---|---|
content | string | - |
unresolved | readonly string[] | Edition-relative paths that were linked but could not be resolved to a URL. |
SyncAssets
The images an edition embeds, and what was uploaded before.
Properties
| Property | Type | Description |
|---|---|---|
entries | AssetEntries | Uploaded assets from the manifest. |
files | ReadonlyMap<string, Asset> | Images that exist, keyed by edition-relative path (see collectAssets). |
UpdateDocInput
Only the fields present are changed.
Properties
| Property | Type |
|---|---|
content? | string |
position? | DocPosition |
title? | string |
Type Aliases
ActionKind
type ActionKind = PlanAction["kind"];ApplyEvent
type ApplyEvent =
| {
kind: "created" | "updated" | "moved" | "archived" | "uploaded";
path: string;
url: string;
}
| {
kind: "unchanged";
path: string;
url: string;
};AssetEntries
type AssetEntries = Record<string, AssetEntry>;Uploaded assets for one container, keyed by edition-relative asset path.
Change
type Change = "content" | "title" | "parent" | "order";Container
type Container =
| {
id: string;
type: "team";
}
| {
id: string;
type: "project";
};Where documents live in the target. Linear accepts both teams and projects.
LayoutMode
type LayoutMode = "nested" | "flat";How pages are arranged in the target.
ManifestEntries
type ManifestEntries = Record<string, ManifestEntry>;Entries for one container, keyed by page path.
MarkdownTransform
type MarkdownTransform = (markdown) => string;A pure Markdown → Markdown step applied to every page before hashing and push. Which ones run is the target's choice: Linear needs anchors and in-page links removed (linearTransforms in @linopress/linear), while a Markdown docs site keeps both.
Parameters
| Parameter | Type |
|---|---|
markdown | string |
Returns
string
PlanAction
type PlanAction =
| ActionBase & object
| ActionBase & object
| ActionBase & object
| ActionBase & object;ReadAsset
type ReadAsset = (path) => Promise<Uint8Array | undefined>;Reads an edition-relative file; resolves undefined when it doesn't exist.
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
Promise<Uint8Array | undefined>
Variables
defaultTransforms
const defaultTransforms: readonly MarkdownTransform[];The clean-up plan, apply and renderDoc use when given no transforms: the Linear one, since those sync to a DocumentTarget. Pass [] for none.
Deprecated
Import linearTransforms from @linopress/linear (linopress-cli/linear).
PLACEHOLDER_CONTENT
const PLACEHOLDER_CONTENT: "_Generating…_" = "_Generating…_";Body written in pass 1, replaced in pass 2 once every doc has a URL.
stripHtmlAnchors
const stripHtmlAnchors: MarkdownTransform;Removes empty HTML anchors (<a id="property-apikey"></a>) and the space after them. TypeDoc puts them in table cells; Linear shows them as literal text.
unlinkInPageLinks
const unlinkInPageLinks: MarkdownTransform;Turns in-page links [text](#fragment) into their plain text (inline code in the text is kept). Linear heading ids are UUIDs, so #slug targets don't exist and the links would be dead.
Functions
apply()
function apply(options): Promise<ApplyResult>;Syncs nodes into target.
- Upload images whose bytes weren't uploaded before, so a failed upload changes no doc.
- Ensure: create every missing doc (parents first) with a placeholder body, so every page has a URL.
- Write: render every doc with links rewritten to those URLs; update the ones whose hash, title or position changed.
- Archive docs that are no longer produced (children first). Never hard-deletes.
Parameters
| Parameter | Type |
|---|---|
options | ApplyOptions |
Returns
Promise<ApplyResult>
applyTransforms()
function applyTransforms(markdown, transforms): string;Runs transforms left to right.
Parameters
| Parameter | Type |
|---|---|
markdown | string |
transforms | readonly MarkdownTransform[] |
Returns
string
assetHash()
function assetHash(data): string;Short, stable hash of an asset's bytes.
Parameters
| Parameter | Type |
|---|---|
data | Uint8Array |
Returns
string
collectAssets()
function collectAssets(pages, read): Promise<CollectedAssets>;Finds the images pages (or doc nodes) embed and reads them through read.
Parameters
| Parameter | Type |
|---|---|
pages | readonly object[] |
read | ReadAsset |
Returns
Promise<CollectedAssets>
containerKey()
function containerKey(container): string;Stable string key for a container, used to scope the manifest.
Parameters
| Parameter | Type |
|---|---|
container | Container |
Returns
string
contentHash()
function contentHash(body): string;Short, stable hash of a document body. Title and position are tracked separately in the manifest, so a rename shows up as a title change, not a content change.
Parameters
| Parameter | Type |
|---|---|
body | string |
Returns
string
contentTypeFor()
function contentTypeFor(path): string;MIME type from the file extension; application/octet-stream when unknown.
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
string
emptyManifest()
function emptyManifest(): Manifest;Returns
findImages()
function findImages(markdown, fromPath): string[];Edition-relative paths of the local files markdown embeds or links to (, <img src="_media/flow.png">, [spec](_media/spec.pdf)), in order of first use. Code, absolute URLs, paths outside the edition and links to pages are ignored.
Parameters
| Parameter | Type |
|---|---|
markdown | string |
fromPath | string |
Returns
string[]
formatPlan()
function formatPlan(p, options?): string;Human-readable plan, one line per action, terraform-style.
Parameters
| Parameter | Type |
|---|---|
p | Plan |
options? | FormatPlanOptions |
Returns
string
isEmptyPlan()
function isEmptyPlan(p): boolean;True when applying the plan would change nothing.
Parameters
| Parameter | Type |
|---|---|
p | Plan |
Returns
boolean
layoutPages()
function layoutPages(pages, options): DocNode[];Places pages in the target's tree.
- nested (default): the index doc is the root; every other page is its child.
- flat: every doc is top-level; titles get a
rootTitle ·prefix so they group together.
Order is deterministic: the index first, then pages by path.
Parameters
| Parameter | Type |
|---|---|
pages | readonly Page[] |
options | LayoutOptions |
Returns
DocNode[]
mapProse()
function mapProse(markdown, fn): string;Applies fn to the prose of a Markdown document, line by line. Fenced code blocks are skipped, and inline code spans are masked with opaque tokens. That way a transform can still match across them (e.g. a link whose text is `Money`) but can't change what's inside.
Parameters
| Parameter | Type |
|---|---|
markdown | string |
fn | (line) => string |
Returns
string
normalizeMarkdown()
function normalizeMarkdown(markdown): string;Normalizes Markdown so that cosmetic differences (CRLF checkouts, trailing blank lines) don't count as content changes. Leading indentation and trailing spaces inside the document are kept: they can be meaningful (indented code, two-space hard line breaks).
Parameters
| Parameter | Type |
|---|---|
markdown | string |
Returns
string
parseContainerKey()
function parseContainerKey(key): Container;Parses team:<id> / project:<id>.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
parseManifest()
function parseManifest(json): Manifest;Parses a manifest file. Also accepts the spike's unversioned format ({ "team:<id>": { "<path>": { id, url, hash } } }).
Parameters
| Parameter | Type |
|---|---|
json | string |
Returns
pendingAssetUrl()
function pendingAssetUrl(asset): string;URL used in dry runs for an asset that isn't uploaded yet (differs per content).
Parameters
| Parameter | Type |
|---|---|
asset | Pick<Asset, "path" | "hash"> |
Returns
string
pendingUploads()
function pendingUploads(assets): string[];Assets with no uploaded copy, one per distinct content hash.
Parameters
| Parameter | Type |
|---|---|
assets | SyncAssets | undefined |
Returns
string[]
pendingUrl()
function pendingUrl(path): string;URL used in dry runs for docs that don't exist yet.
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
string
plan()
function plan(
nodes,
entries,
options?
): Plan;Diffs the desired docs against the manifest. Pure: no I/O, safe for dry runs.
- not in the manifest → create
- content or title hash differs → update (may also move)
- only parent / sort order differs → move
- in the manifest but no longer produced → archive
Parameters
| Parameter | Type |
|---|---|
nodes | readonly DocNode[] |
entries | ManifestEntries |
options? | PlanOptions |
Returns
renderDoc()
function renderDoc(node, options): RenderedDoc;Produces the final body for a doc: transforms applied, links and images rewritten, footer appended.
The hash is computed here, over exactly the body we send. Never hash or diff the content a target returns: Linear's document.content is a lossy re-serialization (it unescapes \| in table cells and shortens | ------ | separators), so it would never match. Image URLs are part of the body, and a changed image gets a new URL, so it counts as a content change.
Parameters
| Parameter | Type |
|---|---|
node | DocNode |
options | RenderOptions |
Returns
resolveLinkPath()
function resolveLinkPath(fromPath, target): string | null;Resolves a relative link target written in fromPath to an edition-relative path. Returns null for absolute URLs, root-relative paths and paths escaping the edition.
Parameters
| Parameter | Type |
|---|---|
fromPath | string |
target | string |
Returns
string | null
rewriteImages()
function rewriteImages(
markdown,
fromPath,
urlFor
): ImageRewriteResult;Points local images (and file links) at their uploaded URLs. Code is left untouched, as are files urlFor can't resolve (reported in missing).
Parameters
| Parameter | Type |
|---|---|
markdown | string |
fromPath | string |
urlFor | (path) => string | undefined |
Returns
rewriteLinks()
function rewriteLinks(
markdown,
fromPath,
urlFor,
options?
): RewriteResult;Rewrites relative .md links ([x](./money.md#anchor)) to target URLs, dropping the fragment unless keepFragments is set. Links in code are left untouched, as are links that urlFor can't resolve (they are reported in unresolved).
Parameters
| Parameter | Type |
|---|---|
markdown | string |
fromPath | string |
urlFor | (path) => string | undefined |
options? | RewriteOptions |
Returns
serializeManifest()
function serializeManifest(manifest): string;Parameters
| Parameter | Type |
|---|---|
manifest | Manifest |
Returns
string
uploadedUrl()
function uploadedUrl(entries, asset): string | undefined;URL of an already-uploaded copy of asset: its own entry when the bytes are unchanged, otherwise any entry with the same bytes (a moved or duplicated image).
Parameters
| Parameter | Type |
|---|---|
entries | AssetEntries |
asset | Asset |
Returns
string | undefined