Docs commands

Learn about the Fern CLI docs commands.

以 Markdown 格式查看

These commands build, preview, and publish a Fern documentation site, and validate the MDX pages and links behind it. Creating a docs project with fern init --docs and validating docs.yml with fern check are general commands, and SDK commands generate client libraries from the same API definition your docs render. Each docs command accepts the global options.

CommandDescription
fern docs devRun local documentation preview server
fern docs diff BetaGenerate visual diffs between preview and production docs
fern generate --docsBuild & publish documentation updates
fern docs preview listList all preview deployments
fern docs preview deleteDelete a preview deployment
fern docs md checkValidate MDX syntax in documentation files
fern docs md generateGenerate MDX pages from library source code
fern docs theme exportExport theme-eligible fields from docs.yml into a standalone directory
fern docs theme uploadUpload a theme to Fern’s registry
fern docs link checkCheck for broken links on a live documentation site
fern docs theme listList all themes for your organization

Detailed command documentation

Use fern generate --docs to create a documentation site for your API.

terminal
$fern generate --docs [--instance <instance-url>] [--preview] [--id <name>] [--force]

instance

Use --instance to specify which instance URL in your docs.yml to generate documentation for.

$fern generate --docs --instance your-organization.docs.buildwithfern.com

preview

Use --preview to preview updates to your documentation before publishing changes to your production site.

$fern generate --docs --preview

id

Use --id with --preview to create a stable, named preview link. The preview URL follows the format {org}-preview-{id}.docs.buildwithfern.com, so rerunning with the same --id updates the existing preview in place rather than creating a new one.

$fern generate --docs --preview --id my-feature
$# -> https://your-org-preview-my-feature.docs.buildwithfern.com

This is useful in CI workflows where you want one preview URL per pull request. See Preview changes for details.

force

When reusing an --id that already exists, Fern prompts you to confirm the overwrite. Use --force to skip the confirmation. This is detected automatically in GitHub Actions, but is needed for other CI environments like Azure Pipelines.

$fern generate --docs --preview --id my-feature --force

Use fern docs dev to run a local development server to preview your docs.

terminal
$fern docs dev [--port <port-number>]
Windows: enable long path support

On Windows, fern docs dev requires long path support to be enabled.

To enable long path support, run the following command in an elevated PowerShell prompt, then restart your terminal:

1New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 -PropertyType DWORD -Force

If you can’t enable long path support, use Windows Subsystem for Linux (WSL) to run fern docs dev in a Linux environment instead.

port

Use --port <port-number> to specify the port the docs preview will be run on.

$fern docs dev --port 57908
Beta

Use fern docs diff to generate visual diffs between your preview deployment and production docs. This command is intended for use in GitHub Actions. It captures screenshots of both versions and creates side-by-side comparison images.

terminal
$fern docs diff <preview-url> <files..> [--output <output-dir>]

Pass the preview URL from fern generate --docs --preview and one or more MDX file paths. Diff images are saved to .fern/diff by default.

$fern docs diff acme-preview-abc123.docs.buildwithfern.com fern/pages/intro.mdx fern/pages/quickstart.mdx

output

Use --output to specify a custom directory for diff images.

$fern docs diff acme-preview-abc123.docs.buildwithfern.com fern/pages/intro.mdx --output ./my-diffs

Use fern docs preview list to list all preview deployments for your organization.

terminal
$fern docs preview list [--limit <number>] [--page <number>]

limit

Use --limit to specify the number of preview deployments to display per page.

$fern docs preview list --limit 20

page

Use --page to specify which page of results to display.

$fern docs preview list --page 2

Use fern docs preview delete to delete a preview deployment generated with fern generate --docs --preview. Pass the full preview URL, or use --id to delete by the identifier used during generation.

terminal
$fern docs preview delete <url>
$
$# Or delete by preview ID
$fern docs preview delete --id <preview-id>

id

Use --id to delete a preview deployment by the identifier used during generation instead of the full preview URL.

$fern docs preview delete --id <preview-id>

Use fern docs md check to validate MDX syntax across all documentation pages referenced in your navigation configuration, including docs.yml, versioned configuration files, and product-specific YAML files.

terminal
$fern docs md check

The command parses each MDX file and reports syntax errors with file paths and line:column numbers. The command accounts for frontmatter offsets, so reported line numbers correspond to the actual lines in your file.

fern/pages/quickstart.mdx:12:5
Unexpected closing tag, expected corresponding closing tag for `<CodeBlock>`
fern/pages/guide.mdx:45:1
Expected a closing tag for `<Note>` before the end of `paragraph`

When all files are valid, you’ll see a success message:

✓ All 42 MDX files are valid

Use fern docs md generate to generate MDX documentation pages from your library source code. The command reads libraries entries in docs.yml and produces pages for modules, classes, functions, and types.

terminal
$fern docs md generate [--local] [--library <name>]

For git inputs, the command sends the repository URL to Fern’s servers for parsing. For path inputs, pass --local to parse the source on your machine instead.

local

Use --local to parse library source locally rather than on Fern’s servers. Required when the library uses a path input. Local generation does not require authentication.

$fern docs md generate --local

library

Use --library to generate docs for a single library when multiple libraries are configured.

$fern docs md generate --library plant-sdk

When --library is omitted, all configured libraries are processed in parallel.

Use fern docs theme export to extract the theme-eligible fields from your docs.yml into a standalone directory. The exported theme.yml and its assets can then be uploaded with fern docs theme upload.

terminal
$fern docs theme export [--output <directory>]

By default, files are written to ./fern/theme/.

output

Use --output to specify a custom directory for the exported theme.

$fern docs theme export --output ./my-theme

Use fern docs theme upload to upload a theme to Fern’s registry. The command reads theme.yml from ./fern/theme/ and uploads it along with any referenced file assets.

terminal
$fern docs theme upload [--name <name>] [--org <org>]

name

Use --name to set the theme name. Defaults to default.

$fern docs theme upload --name my-theme

org

Use --org to override the organization ID from fern.config.json.

$fern docs theme upload --org my-org

Use fern docs theme list to list all themes uploaded for your organization.

terminal
$fern docs theme list [--json] [--org <org>]

By default, outputs one theme name per line.

json

Use --json to output the full list as a JSON array, including updatedAt timestamps.

$fern docs theme list --json

org

Use --org to override the organization ID from fern.config.json.

$fern docs theme list --org my-org