Skip to content

Commit 862667f

Browse files
committed
clarify npm publishing workflow
1 parent 57ab37c commit 862667f

File tree

2 files changed

+104
-83
lines changed

2 files changed

+104
-83
lines changed

fern/products/sdks/overview/typescript/publishing-to-npm.mdx

Lines changed: 97 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ you'll have a versioned package published on npm.
2222

2323
</Info>
2424

25-
## Configure `generators.yml`
25+
## Configure SDK package settings
2626

27-
<Note>Your `generators.yml` [should live in your source repository](/sdks/overview/project-structure) (or on your local machine), not the repository that contains your TypeScript SDK code.</Note>
27+
You'll need to update your `generators.yml` file to configure the package name, output location, and client naming for npm publishing. Your `generators.yml` [should live in your source repository](/sdks/overview/project-structure) (or on your local machine), not the repository that contains your TypeScript SDK code.
2828

2929
<Steps>
3030
<Step title="Configure `output` location">
@@ -79,26 +79,6 @@ you'll have a versioned package published on npm.
7979

8080
</Step>
8181

82-
<Step title="Add repository location">
83-
84-
Add the path to the GitHub repository containing your TypeScript SDK:
85-
86-
```yaml {11-12} title="generators.yml"
87-
groups:
88-
ts-sdk:
89-
generators:
90-
- name: fernapi/fern-typescript-sdk
91-
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
92-
output:
93-
location: npm
94-
package-name: your-package-name
95-
config:
96-
namespaceExport: YourClientName
97-
github:
98-
repository: your-org/company-typescript
99-
```
100-
101-
</Step>
10282
</Steps>
10383

10484
## Generate an npm token
@@ -163,10 +143,83 @@ you'll have a versioned package published on npm.
163143

164144
## Configure npm publication
165145

166-
Choose how you want to authenticate and publish your SDK to npm. You can use GitHub workflows for automated releases or publish directly via the CLI.
146+
<Steps>
147+
<Step title="Add repository location">
148+
149+
Add the path to the GitHub repository containing your TypeScript SDK:
150+
151+
```yaml {11-12} title="generators.yml"
152+
groups:
153+
ts-sdk:
154+
generators:
155+
- name: fernapi/fern-typescript-sdk
156+
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
157+
output:
158+
location: npm
159+
package-name: your-package-name
160+
config:
161+
namespaceExport: YourClientName
162+
github:
163+
repository: your-org/company-typescript
164+
```
165+
166+
</Step>
167+
<Step title="Configure npm authentication token">
168+
169+
Add `token: ${NPM_TOKEN}` to `generators.yml` to tell Fern to use the `NPM_TOKEN` environment variable for authentication when publishing to the npm registry.
170+
171+
```yaml title="generators.yml" {9}
172+
groups:
173+
ts-sdk:
174+
generators:
175+
- name: fernapi/fern-typescript-sdk
176+
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
177+
output:
178+
location: npm
179+
package-name: name-of-your-package
180+
token: ${NPM_TOKEN}
181+
config:
182+
namespaceExport: YourClientName
183+
github:
184+
repository: your-org/your-repository
185+
```
186+
</Step>
187+
<Step title="Choose your publishing mode">
188+
189+
Optionally set the mode to control how Fern handles SDK publishing:
190+
191+
- `mode: release` (default): Fern generates code, commits to main, and tags a release automatically
192+
- `mode: pull-request`: Fern generates code and creates a PR for you to review before release
193+
- `mode: push`: Fern generates code and pushes to a branch for you to review before release
194+
195+
```yaml title="generators.yml" {14}
196+
groups:
197+
ts-sdk:
198+
generators:
199+
- name: fernapi/fern-typescript-sdk
200+
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
201+
output:
202+
location: npm
203+
package-name: name-of-your-package
204+
token: ${NPM_TOKEN}
205+
config:
206+
namespaceExport: YourClientName
207+
github:
208+
repository: your-org/your-repository
209+
mode: pull-request
210+
```
211+
You can also configure other settings, like the reviwers or license. Refer to the [full `github` reference](/sdks/reference/generators-yml#github) for more information.
212+
213+
</Step>
214+
</Steps>
215+
216+
## Publish your SDK
217+
218+
Decide how you want to publish your SDK to npm. You can use GitHub workflows for automated releases or publish directly via the CLI.
167219

168220
<AccordionGroup>
169-
<Accordion title="Release via a GitHub workflow (recommended)">
221+
222+
<Accordion title="Release via a GitHub workflow">
170223

171224
Set up a release workflow via [GitHub Actions](https://docs.github.com/en/actions/get-started/quickstart) so you can trigger new SDK releases directly from your source repository.
172225

@@ -203,26 +256,6 @@ Set up a release workflow via [GitHub Actions](https://docs.github.com/en/action
203256
organization listed in `fern.config.json`.
204257
1. Click **Add secret**.
205258

206-
</Step>
207-
<Step title="Configure npm authentication token">
208-
209-
Add `token: ${NPM_TOKEN}` to `generators.yml`.
210-
211-
```yaml {9} title="generators.yml"
212-
groups:
213-
ts-sdk:
214-
generators:
215-
- name: fernapi/fern-typescript-sdk
216-
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
217-
output:
218-
location: npm
219-
package-name: name-of-your-package
220-
token: ${NPM_TOKEN}
221-
config:
222-
namespaceExport: YourClientName
223-
github:
224-
repository: your-org/your-repository
225-
```
226259
</Step>
227260
<Step title="Set up a new workflow">
228261

@@ -261,64 +294,45 @@ Set up a release workflow via [GitHub Actions](https://docs.github.com/en/action
261294
</Note>
262295
</Step>
263296

264-
<Step title="Run your workflow">
297+
<Step title="Regenerate and release your SDK">
265298

266-
Navigate to the **Actions** tab, select the workflow you just created, specify a version number, and click **Run workflow**.
267-
268-
This regenerates your SDK, tags the new release with the version number you specified, and initiates a Fern-generated publishing workflow in your TypeScript SDK repository that publishes your release to npm.
299+
Navigate to the **Actions** tab, select the workflow you just created, specify a version number, and click **Run workflow**. This regenerates your SDK.
269300

270301
<Frame>
271302
<img src="assets/ts-sdk-release-action.png" alt="Running TS publish workflow" />
272303
</Frame>
273-
274-
Once your workflow completes, log back into npm and navigate to **Packages** to see your new release.
304+
305+
<Markdown src="/products/sdks/snippets/release-sdk.mdx"/>
275306

276307
</Step>
308+
277309
</Steps>
278310

279311
</Accordion>
312+
280313
<Accordion title="Release via CLI and environment variables">
281314
<Steps>
282-
<Step title="Configure npm authentication token">
283315

284-
Add `token: ${NPM_TOKEN}` to `generators.yml` to tell Fern to use the `NPM_TOKEN` environment variable for authentication when publishing to the npm registry.
316+
<Step title="Set npm environment variable">
285317

286-
```yaml {9}
287-
groups:
288-
ts-sdk:
289-
generators:
290-
- name: fernapi/fern-typescript-sdk
291-
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
292-
output:
293-
location: npm
294-
package-name: name-of-your-package
295-
token: ${NPM_TOKEN}
296-
config:
297-
namespaceExport: YourClientName
298-
github:
299-
repository: your-org/your-repository
300-
```
301-
</Step>
302-
<Step title="Set npm environment variable">
318+
Set the `NPM_TOKEN` environment variable on your local machine:
303319

304-
Set the `NPM_TOKEN` environment variable on your local machine:
320+
```bash
321+
export NPM_TOKEN=your-actual-npm-token
322+
```
305323

306-
```bash
307-
export NPM_TOKEN=your-actual-npm-token
308-
```
324+
</Step>
325+
<Step title="Regenerate and release your SDK">
309326

310-
</Step>
311-
<Step title="Regenerate your SDK">
312-
Regenerating your SDK tags the new release with the version number you specified and initiates a Fern-generated publishing workflow in your TypeScript SDK repository that publishes your release to npm.
327+
Regenerate your SDK, specifying the version:
313328

314-
```bash
315-
fern generate --group ts-sdk --version <version>
316-
```
317-
Local machine output will verify that the release is pushed to your
318-
repository and tagged with the version you specified. Log back into npm and
319-
navigate to **Packages** to see your new release.
329+
```bash
330+
fern generate --group ts-sdk --version <version>
331+
```
332+
333+
<Markdown src="/products/sdks/snippets/release-sdk.mdx"/>
334+
</Step>
320335

321-
</Step>
322336
</Steps>
323337
</Accordion>
324338
</AccordionGroup>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The rest of the release process depends on your chosen mode:
2+
3+
- **Release mode (default):** If you didn't specify a `mode` or set `mode: release`, no further action is required. Fern automatically tags the new release with your specified version number and initiates the npm publishing workflow in your SDK repository.
4+
5+
- **Pull request or push mode:** If you set `mode: pull-request` or `mode: push`, Fern creates a pull request. Merge this PR and tag a new release to initiate the npm publishing workflow in your SDK repository.
6+
7+
Once the workflow completes, you can view your new release by logging into npm and navigating to **Packages**.

0 commit comments

Comments
 (0)