Publishing

Beta
View as Markdown
Early access

The CLI generator is in early access. Reach out to get started.

Publish your generated CLI to npm. After following the steps on this page, each tagged release builds cross-platform binaries and publishes them automatically. Homebrew and GitHub Releases distribution are coming soon. To keep generation on your own infrastructure, you can self-host the generator instead of using Fern’s cloud.

This page assumes that you have:

  • An initialized fern folder with generators.yml configured for the CLI generator. See Quickstart.
  • An existing GitHub repository for the generated CLI source, with the Fern GitHub App installed on it.

Configure output location

1

Set the output location to npm

In the group for your CLI, set the output location to npm:

generators.yml
1groups:
2 cli:
3 generators:
4 - name: fern-cli-generator
5 version: 0.23.4
6 output:
7 location: npm
8 config:
9 binaryName: my-cli
2

Add a unique package name

The package name must be unique in the npm registry.

generators.yml
1groups:
2 cli:
3 generators:
4 - name: fern-cli-generator
5 version: 0.23.4
6 output:
7 location: npm
8 package-name: "@myorg/my-cli"
9 config:
10 binaryName: my-cli

Configure GitHub publishing

Fern publishes your CLI via GitHub Actions. Configure your GitHub repository and publishing mode:

generators.yml
1groups:
2 cli:
3 generators:
4 - name: fern-cli-generator
5 version: 0.23.4
6 output:
7 location: npm
8 package-name: "@myorg/my-cli"
9 config:
10 binaryName: my-cli
11 github:
12 repository: my-org/my-cli
13 mode: release

The repository owner is independent of your Fern organization (the --organization value passed to fern init). Point it at the GitHub user or organization that owns the target repository.

ModeBehavior
releaseCommits to the default branch and tags a release. The CI workflow builds binaries and publishes automatically.
pull-requestOpens a PR with generated source for review. Merge the PR and create a GitHub release to trigger publishing.

Configure authentication

Choose how to authenticate with npm when publishing.

1

Generate an npm token

  1. Log into npmjs.com
  2. Click your profile picture and select Access Tokens
  3. Click Generate New Token and create a granular access token
  4. Give it Read and Write access to All packages
  5. Save your token securely
2

Add token to generators.yml

Set token: ${NPM_TOKEN} in the output section:

generators.yml
1groups:
2 cli:
3 generators:
4 - name: fern-cli-generator
5 version: 0.23.4
6 output:
7 location: npm
8 package-name: "@myorg/my-cli"
9 token: ${NPM_TOKEN}
10 config:
11 binaryName: my-cli
12 github:
13 repository: my-org/my-cli
14 mode: release
3

Add NPM_TOKEN as a GitHub Actions secret

  1. Open your CLI repository on GitHub and go to Settings
  2. Navigate to Secrets and variables > Actions
  3. Click New repository secret
  4. Name it NPM_TOKEN and paste your npm token
  5. Click Add secret

Publish your CLI

How you trigger a publish depends on your mode:

  • In release mode, fern generate --group cli commits the updated source and tags a release. The tag triggers the CI workflow (no manual release step).
  • In pull-request mode, fern generate --group cli opens a PR. Merge it, then create a GitHub release with a version tag (e.g. v1.0.0) to trigger publishing.

The CI workflow then builds binaries for all platforms and publishes to npm.

Build targets

The CI workflow produces statically linked binaries for:

TargetOSArchitecture
x86_64-unknown-linux-gnuLinuxx86_64
aarch64-unknown-linux-gnuLinuxARM64
x86_64-apple-darwinmacOSIntel
aarch64-apple-darwinmacOSApple Silicon
x86_64-pc-windows-msvcWindowsx86_64

The npm package wraps the native binary with a Node.js launcher. Platform-specific optional dependencies ensure only the correct binary downloads at install time.

Install instructions for users

After publishing, direct users to install with npm:

$npm install -g @myorg/my-cli