You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: fern/products/sdks/overview/typescript/publishing-to-npm.mdx
+48-86Lines changed: 48 additions & 86 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ description: How to publish the Fern Typescript SDK to npm.
5
5
6
6
Publish your public-facing Fern Typescript SDK to the [npm registry](https://www.npmjs.com/). Once you've followed the steps on this page to connect your npm account to your SDK, Fern will automatically publish the latest version of your SDK.
7
7
8
-
<Info>This guide assumes that you've already generated a TypeScript SDK by following the instructions in [TypeScript Quickstart](quickstart.mdx).</Info>
8
+
<Info>This guide assumes that you already have an initialized `fern` folder on your local machine. If you don’t, run `fern init`. See [TypeScript Quickstart](quickstart.mdx) for more details.</Info>
9
9
10
-
## Configure your GitHub integration
10
+
## Set up your GitHub integration
11
11
12
12
1. Create a new GitHub repository for your SDK, if you haven't done so already.
13
-
1. Install the [Fern GitHub App](https://github.com/apps/fern-api). Select **Configure**, then scroll down to **Repository Access**. Select **Only select repositories** and in the dropdown select the repository for your SDK. Click **Save**.
14
-
1. Add your TypeScript SDK files (`fern` and `sdks` folders) to your repository.
13
+
1. Install the [Fern GitHub App](https://github.com/apps/fern-api): Select **Configure**, then scroll down to **Repository Access**. Select **Only select repositories** and in the dropdown select the repository for your SDK. Click **Save**.
14
+
1. Add your SDK files to your repository.
15
15
16
16
17
17
## Configure `generators.yml`
@@ -20,7 +20,7 @@ Publish your public-facing Fern Typescript SDK to the [npm registry](https://www
20
20
21
21
<Steptitle="Run `fern add <generator>`">
22
22
23
-
Navigate to your `generators.yml`. Your `generators.yml` lives inside of your `fern` folder and contains all the configuration for your Fern generators.
23
+
Navigate to your `generators.yml` on your local machine. Your `generators.yml` lives inside of your `fern` folder and contains all the configuration for your Fern generators.
24
24
25
25
In order to generate the SDK, add the generator to your `generators.yml` using the `fern <add>` command:
26
26
@@ -49,7 +49,7 @@ Publish your public-facing Fern Typescript SDK to the [npm registry](https://www
49
49
50
50
<Steptitle="Configure `output` location">
51
51
52
-
Next, change the output location in `generators.yml` to `npm`:
52
+
Next, change the output location in `generators.yml`from `local-file-system` (the default) to `npm`:
53
53
54
54
```yaml title="TypeScript" {6-7}
55
55
groups:
@@ -114,7 +114,7 @@ ts-sdk:
114
114
115
115
<Step title="Navigate to Access Tokens">
116
116
117
-
Click on your profile pictureand select **Access Tokens**.
117
+
Click on your profile picture, select **Edit Profile**, and then select **Access Tokens**.
<Warning>When you click **Generate Token**, you’ll be returned to the **Access Token** dashboard. A box on the top of the dashboard will confirm that your token creation was a success and prompt you to copy your token id. Make sure you save this id, as you'll need to add it to your GitHub repository in the later on.</Warning>
132
+
<Warning>When you click **Generate Token**, you’ll be returned to the **Access Tokens** dashboard. A box on the top of the dashboard will confirm that you successfully created a new token and prompt you to copy your token id. Make sure you save this id, as you'll need to add it to your GitHub repository in the later on.</Warning>
133
133
134
134
</Step>
135
+
136
+
<Step title="Configure npm authentication token">
137
+
138
+
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.
139
+
140
+
```yaml title="TypeScript" {9}
141
+
groups:
142
+
ts-sdk:
143
+
generators:
144
+
- name: fernapi/fern-typescript-node-sdk
145
+
version: 0.9.5
146
+
output:
147
+
location: npm
148
+
package-name: name-of-your-package
149
+
token: ${NPM_TOKEN}
150
+
github:
151
+
repository: your-org/your-repository
152
+
```
153
+
</Step>
154
+
135
155
</Steps>
136
156
137
-
## Add NPM and Fern Tokens to your GitHub Tepository
157
+
## Add npm Token to your GitHub Repository
138
158
139
159
<Info>
140
160
Using GitLab? Follow [these steps](/learn/docs/developer-tools/gitlab#add-a-token-to-gitlab).
@@ -144,11 +164,11 @@ Using GitLab? Follow [these steps](/learn/docs/developer-tools/gitlab#add-a-toke
144
164
145
165
<Step title="Open Repository">
146
166
147
-
Open your Fern repository in GitHub.
167
+
Open your repository in GitHub.
148
168
149
169
</Step>
150
170
151
-
<Step title="Navigate to Actions in Settings">
171
+
<Step title="Add a Secret for your npm Token">
152
172
153
173
Click on the **Settings** tab in your repository. Then, under the **Security** section, open **Secrets and variables** > **Actions**.
154
174
@@ -158,9 +178,6 @@ Using GitLab? Follow [these steps](/learn/docs/developer-tools/gitlab#add-a-toke
158
178
159
179
You can also use the url `https://github.com/<your-repo>/settings/secrets/actions`.
160
180
161
-
</Step>
162
-
163
-
<Step title="Add secret for your NPM Token">
164
181
165
182
1. Select **New repository secret**.
166
183
1. Name your secret `NPM_TOKEN`.
@@ -169,88 +186,33 @@ Using GitLab? Follow [these steps](/learn/docs/developer-tools/gitlab#add-a-toke
169
186
170
187
</Step>
171
188
172
-
<Step title="Generate and Add Secret for your Fern Token">
173
-
174
-
1. Generate a Fern token by running `fern token` and saving the token id.
175
-
1. Select **New repository secret**.
176
-
1. Name your secret `FERN_TOKEN`.
177
-
1. Add the corresponding token you generated above.
178
-
1. Click **Add secret**.
179
-
180
-
</Step>
181
-
182
189
</Steps>
183
190
184
-
## Configure GitHub Actions
191
+
## Release your SDK to NPM
192
+
193
+
At this point, you're ready to generate a release for your SDK.
185
194
186
195
<Steps>
187
-
<Step title="Update Workflow Action Settings">
196
+
197
+
<Step title="Set npm environment variable">
188
198
189
-
Change your workflow permissions to allow GitHub to run workflows:
199
+
Set the NPM_TOKEN environment variable on your local machine:
190
200
191
-
1. Click on the **Settings** tab in your repository.
192
-
1. Navigate to **Actions**. Under **Actions permissions**, select **Allow all actions and reusable workflows**.
193
-
1. **Save** your settings. Now GitHub can run the action you just configured.
201
+
```bash
202
+
export NPM_TOKEN=your-actual-npm-token
203
+
```
194
204
195
205
</Step>
196
-
<Step title="Set up a GitHub Action">
197
-
198
-
Add a GitHub Action to trigger releases for your SDK. Add a new file called `publish-typescript-sdk.yml` (or something similar) to a new `.github/workflows` directory. Your file should look like this:
199
-
200
-
201
-
```yaml title="TypeScript" maxLines=0
202
-
name: Publish TypeScript SDK
203
-
204
-
on:
205
-
workflow_dispatch:
206
-
inputs:
207
-
version:
208
-
description: "The version of the TypeScript SDK that you would like to release"
The group name in the `run` command (`ts-sdk`) must match the name of your group in `generators.yml`:
231
-
232
-
```yaml {2}
233
-
groups:
234
-
ts-sdk:
235
-
generators:
236
-
- name: fernapi/fern-typescript-node-sdk
237
-
version: 1.10.3
238
-
output:
239
-
location: npm
240
-
package-name: name-of-your-package
241
-
token: ${NPM_TOKEN}
242
-
github:
243
-
repository: your-org/your-repository
244
-
```
245
-
</Step>
246
-
</Steps>
207
+
<Step title="Generate your release">
247
208
248
-
## Release your SDK to NPM
209
+
Run the following command to regenerate your SDK and publish it on npm:
249
210
250
-
At this point, you're ready to generate a release for your SDK. You can do this by either:
251
-
* Running `fern generate --version <version>` to regenerate your SDK.
252
-
* Manually triggering your SDK generation workflow from your GitHub repository by navigating to **Actions** and selecting your workflow. Once you initiate the workflow, you'll be prompted to enter the version number of your release.
211
+
```bash
212
+
fern generate --version <version>
213
+
```
214
+
Local machine output will verify that the release is pushed to your repository and tagged with the version you specified. You'll receive an email from npm notifying you that a new version of your package has been successfully published!
0 commit comments