Skip to content

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 ​
ts
new DocNotFoundError(docId, message?): DocNotFoundError;
Parameters ​
ParameterType
docIdstring
message?string
Returns ​

DocNotFoundError

Overrides ​

Error.constructor

Properties ​

PropertyType
docIdstring

Interfaces ​

ApplyOptions ​

Properties ​

PropertyTypeDescription
assets?SyncAssetsImages 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.
entriesManifestEntriesCurrent entries for the target's container; not mutated.
footer?(node) => string-
nodesreadonly 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-
targetDocumentTarget-
transforms?readonly MarkdownTransform[]Markdown clean-up before link rewriting. Defaults to Linear's (defaultTransforms).

ApplyResult ​

Properties ​

PropertyTypeDescription
assetsAssetEntriesAsset entries for exactly the images the docs embed (empty when assets was omitted).
entriesManifestEntries-
eventsreadonly ApplyEvent[]-

Asset ​

A local file a page embeds (an image), read and hashed so it can be uploaded once.

Properties ​

PropertyTypeDescription
contentTypestring-
dataUint8Array-
hashstringHash of the file's bytes. Unchanged bytes are never uploaded again.
pathstringEdition-relative POSIX path, e.g. _media/diagram.png.

AssetEntry ​

What Linopress knows about an uploaded asset: the bytes it uploaded (hash) and where they live.

Properties ​

PropertyType
hashstring
urlstring

CollectedAssets ​

Properties ​

PropertyTypeDescription
assetsReadonlyMap<string, Asset>Every image that exists, keyed by edition-relative path.
missingreadonly 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 ​

PropertyType
contentstring
parentIdstring | null
sortOrdernumber
titlestring

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 ​

PropertyTypeDescription
contentstring-
parentPathstring | null-
pathstring-
sortOrdernumber-
sources?readonly string[]The page's source files, if the source knows them. Used by footers, never hashed.
titlestring-

DocPosition ​

Where a doc sits: under parentId (or top-level when null), at sortOrder.

Extended by ​

Properties ​

PropertyType
parentIdstring | null
sortOrdernumber

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() ​
ts
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 ​
ParameterType
idstring
Returns ​

Promise<void>

create() ​
ts
create(input): Promise<RemoteDoc>;
Parameters ​
ParameterType
inputCreateDocInput
Returns ​

Promise<RemoteDoc>

update() ​
ts
update(id, input): Promise<void>;

Throws DocNotFoundError when the doc is deleted or archived.

Parameters ​
ParameterType
idstring
inputUpdateDocInput
Returns ​

Promise<void>

uploadAsset()? ​
ts
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 ​
ParameterType
assetAsset
Returns ​

Promise<string>


FormatPlanOptions ​

Properties ​

PropertyTypeDescription
verbose?booleanInclude unchanged docs. Defaults to false.

ImageRewriteResult ​

Properties ​

PropertyTypeDescription
contentstring-
missingreadonly string[]Edition-relative file paths that urlFor couldn't resolve (left as written).

LayoutOptions ​

Properties ​

PropertyTypeDescription
indexPath?stringPath of the index page. Defaults to README.md (TypeDoc's entry page).
modeLayoutMode-
rootTitlestringTitle of the index doc, and the title prefix in flat mode.
separator?stringSeparator between the root title and page titles in flat mode. Defaults to ·.

Manifest ​

Properties ​

PropertyTypeDescription
assetsRecord<string, AssetEntries>Uploaded images, keyed like containers, then by edition-relative asset path.
containersRecord<string, ManifestEntries>Keyed by container key (team:<id> / project:<id>).
version1-

ManifestEntry ​

What Linopress knows about a doc it created: identity, last-synced position and content hash.

Properties ​

PropertyTypeDescription
hashstring | nullHash of the last content pushed; null right after creation (body is a placeholder).
idstring-
parentPathstring | null-
sortOrdernumber-
titlestring-
urlstring-

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 ​

PropertyTypeDescription
contentstringMarkdown body. Relative .md links are rewritten to document URLs at sync time.
pathstringPOSIX path relative to the edition root, e.g. client.md or internal/retry.md.
sources?readonly string[]Absolute paths of the source files the page documents (for TypeDoc: the module's file).
titlestringHuman title, without any edition prefix.

Plan ​

Properties ​

PropertyTypeDescription
actionsreadonly PlanAction[]In execution order: creates (parents first), updates/moves, archives (children first).
countsReadonly<Record<ActionKind, number>>-
missingImagesReadonly<Record<string, readonly string[]>>page path → local images it embeds that don't exist (left as written).
unresolvedLinksReadonly<Record<string, readonly string[]>>page path → edition-relative link targets that don't exist in this edition.
uploadsreadonly string[]Edition-relative paths of images to upload (new or changed bytes), one per distinct file.

PlanOptions ​

Properties ​

PropertyTypeDescription
assets?SyncAssetsImages 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 ​

PropertyType
idstring
urlstring

RenderedDoc ​

Properties ​

PropertyTypeDescription
contentstring-
hashstring-
missingImagesreadonly string[]Local images the page embeds that don't exist.
unresolvedLinksreadonly string[]-

RenderOptions ​

Properties ​

PropertyTypeDescription
assetUrlFor?(path) => string | undefinedURL of an uploaded image for an edition-relative path; undefined when the file is missing. When omitted, images are left as written.
footer?(node) => stringAppended 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 | undefinedURL of the doc for an edition-relative path, if one exists (or is about to).

RewriteOptions ​

Properties ​

PropertyTypeDescription
keepFragments?booleanKeep #fragments on rewritten links. Defaults to false, because Linear ignores fragments on document URLs (its heading ids are UUIDs, not TypeDoc slugs).

RewriteResult ​

Properties ​

PropertyTypeDescription
contentstring-
unresolvedreadonly 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 ​

PropertyTypeDescription
entriesAssetEntriesUploaded assets from the manifest.
filesReadonlyMap<string, Asset>Images that exist, keyed by edition-relative path (see collectAssets).

UpdateDocInput ​

Only the fields present are changed.

Properties ​

PropertyType
content?string
position?DocPosition
title?string

Type Aliases ​

ActionKind ​

ts
type ActionKind = PlanAction["kind"];

ApplyEvent ​

ts
type ApplyEvent = 
  | {
  kind: "created" | "updated" | "moved" | "archived" | "uploaded";
  path: string;
  url: string;
}
  | {
  kind: "unchanged";
  path: string;
  url: string;
};

AssetEntries ​

ts
type AssetEntries = Record<string, AssetEntry>;

Uploaded assets for one container, keyed by edition-relative asset path.


Change ​

ts
type Change = "content" | "title" | "parent" | "order";

Container ​

ts
type Container = 
  | {
  id: string;
  type: "team";
}
  | {
  id: string;
  type: "project";
};

Where documents live in the target. Linear accepts both teams and projects.


LayoutMode ​

ts
type LayoutMode = "nested" | "flat";

How pages are arranged in the target.


ManifestEntries ​

ts
type ManifestEntries = Record<string, ManifestEntry>;

Entries for one container, keyed by page path.


MarkdownTransform ​

ts
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 ​

ParameterType
markdownstring

Returns ​

string


PlanAction ​

ts
type PlanAction = 
  | ActionBase & object
  | ActionBase & object
  | ActionBase & object
  | ActionBase & object;

ReadAsset ​

ts
type ReadAsset = (path) => Promise<Uint8Array | undefined>;

Reads an edition-relative file; resolves undefined when it doesn't exist.

Parameters ​

ParameterType
pathstring

Returns ​

Promise<Uint8Array | undefined>

Variables ​

defaultTransforms ​

ts
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 ​

ts
const PLACEHOLDER_CONTENT: "_Generating…_" = "_Generating…_";

Body written in pass 1, replaced in pass 2 once every doc has a URL.


stripHtmlAnchors ​

ts
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.


ts
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() ​

ts
function apply(options): Promise<ApplyResult>;

Syncs nodes into target.

  1. Upload images whose bytes weren't uploaded before, so a failed upload changes no doc.
  2. Ensure: create every missing doc (parents first) with a placeholder body, so every page has a URL.
  3. Write: render every doc with links rewritten to those URLs; update the ones whose hash, title or position changed.
  4. Archive docs that are no longer produced (children first). Never hard-deletes.

Parameters ​

ParameterType
optionsApplyOptions

Returns ​

Promise<ApplyResult>


applyTransforms() ​

ts
function applyTransforms(markdown, transforms): string;

Runs transforms left to right.

Parameters ​

ParameterType
markdownstring
transformsreadonly MarkdownTransform[]

Returns ​

string


assetHash() ​

ts
function assetHash(data): string;

Short, stable hash of an asset's bytes.

Parameters ​

ParameterType
dataUint8Array

Returns ​

string


collectAssets() ​

ts
function collectAssets(pages, read): Promise<CollectedAssets>;

Finds the images pages (or doc nodes) embed and reads them through read.

Parameters ​

ParameterType
pagesreadonly object[]
readReadAsset

Returns ​

Promise<CollectedAssets>


containerKey() ​

ts
function containerKey(container): string;

Stable string key for a container, used to scope the manifest.

Parameters ​

ParameterType
containerContainer

Returns ​

string


contentHash() ​

ts
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 ​

ParameterType
bodystring

Returns ​

string


contentTypeFor() ​

ts
function contentTypeFor(path): string;

MIME type from the file extension; application/octet-stream when unknown.

Parameters ​

ParameterType
pathstring

Returns ​

string


emptyManifest() ​

ts
function emptyManifest(): Manifest;

Returns ​

Manifest


findImages() ​

ts
function findImages(markdown, fromPath): string[];

Edition-relative paths of the local files markdown embeds or links to (![alt](./diagram.png), <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 ​

ParameterType
markdownstring
fromPathstring

Returns ​

string[]


formatPlan() ​

ts
function formatPlan(p, options?): string;

Human-readable plan, one line per action, terraform-style.

Parameters ​

ParameterType
pPlan
options?FormatPlanOptions

Returns ​

string


isEmptyPlan() ​

ts
function isEmptyPlan(p): boolean;

True when applying the plan would change nothing.

Parameters ​

ParameterType
pPlan

Returns ​

boolean


layoutPages() ​

ts
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 ​

ParameterType
pagesreadonly Page[]
optionsLayoutOptions

Returns ​

DocNode[]


mapProse() ​

ts
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 ​

ParameterType
markdownstring
fn(line) => string

Returns ​

string


normalizeMarkdown() ​

ts
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 ​

ParameterType
markdownstring

Returns ​

string


parseContainerKey() ​

ts
function parseContainerKey(key): Container;

Parses team:<id> / project:<id>.

Parameters ​

ParameterType
keystring

Returns ​

Container


parseManifest() ​

ts
function parseManifest(json): Manifest;

Parses a manifest file. Also accepts the spike's unversioned format ({ "team:<id>": { "<path>": { id, url, hash } } }).

Parameters ​

ParameterType
jsonstring

Returns ​

Manifest


pendingAssetUrl() ​

ts
function pendingAssetUrl(asset): string;

URL used in dry runs for an asset that isn't uploaded yet (differs per content).

Parameters ​

ParameterType
assetPick<Asset, "path" | "hash">

Returns ​

string


pendingUploads() ​

ts
function pendingUploads(assets): string[];

Assets with no uploaded copy, one per distinct content hash.

Parameters ​

ParameterType
assetsSyncAssets | undefined

Returns ​

string[]


pendingUrl() ​

ts
function pendingUrl(path): string;

URL used in dry runs for docs that don't exist yet.

Parameters ​

ParameterType
pathstring

Returns ​

string


plan() ​

ts
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 ​

ParameterType
nodesreadonly DocNode[]
entriesManifestEntries
options?PlanOptions

Returns ​

Plan


renderDoc() ​

ts
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 ​

ParameterType
nodeDocNode
optionsRenderOptions

Returns ​

RenderedDoc


resolveLinkPath() ​

ts
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 ​

ParameterType
fromPathstring
targetstring

Returns ​

string | null


rewriteImages() ​

ts
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 ​

ParameterType
markdownstring
fromPathstring
urlFor(path) => string | undefined

Returns ​

ImageRewriteResult


ts
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 ​

ParameterType
markdownstring
fromPathstring
urlFor(path) => string | undefined
options?RewriteOptions

Returns ​

RewriteResult


serializeManifest() ​

ts
function serializeManifest(manifest): string;

Parameters ​

ParameterType
manifestManifest

Returns ​

string


uploadedUrl() ​

ts
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 ​

ParameterType
entriesAssetEntries
assetAsset

Returns ​

string | undefined

MIT licensed. Not made by or affiliated with Linear.