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
<Info>You can also additionally configure the `github` section to whether Fern
49
+
should commit and release, create a pull request, or push code to a branch when
50
+
you make changes to your SDK code. See [GitHub
51
+
Configuration](/sdks/reference/generators-yml#github-configuration) for more
52
+
details. </Info>
53
+
54
+
## Structuring SDK-specific repositories
55
+
56
+
1. Create a new GitHub repository called `company-<language>` (or something
57
+
similar) for each of your SDKs, if you haven't done so already.
58
+
1. Install the [Fern GitHub App](https://github.com/apps/fern-api) on the
59
+
top-level repository and all SDK repositories. Select **Configure**, then
60
+
scroll down to **Repository Access**. Select **Only select repositories** and
61
+
in the dropdown select the repository for your SDK. Click **Save**.
62
+
63
+
64
+
The repository structure for a specific SDK should look similar to this:
65
+
66
+
```{6-11}
67
+
├─ company-repo # Top-level repo for all SDKs
68
+
├─ fern/
69
+
├─ apis/
70
+
├─ sdks/
71
+
└── generators.yml # Contains settings for all SDKs
72
+
├─ typescript-sdk-repo # Repository for a TypeScript SDK
73
+
├─ .github/workflows/ # Contains GitHub Actions for publishing to package repositories, etc.
74
+
├─ scripts/
75
+
├─ src/
76
+
├─ tests/
77
+
└── .fernignore # Lists files that Fern shouldn't modify
78
+
├─ python-sdk-repo
79
+
└── go-sdk-repo
80
+
```
81
+
82
+
Fern generates most of the SDK files listed in this example repository (`scripts/`, `src/`, `tests`,
83
+
`.fernignore`, etc.), including any custom code you added. You have to manually set up `.github/workflows` to execute actions, like publishing SDK versions to a package repository.
84
+
85
+
For additional examples, see Cohere's [Python SDK repository](https://github.com/cohere-ai/cohere-python) and [Vapi's TypeScript SDK repository](https://github.com/VapiAI/server-sdk-typescript).
86
+
87
+
## Generate an SDK in your desired language
88
+
89
+
Once you've set up your GitHub repository structure, you can proceed with generating SDKs in your desired languages.
* An initialized `fern` folder on your local machine. See [Set up the `fern`
18
+
folder](/sdks/overview/quickstart).
19
+
* A GitHub repository for your TypeScript SDK. See [Set up your GitHub structure](/sdks/overview/github).
20
+
* A TypeScript generator group in `generators.yml`. See [TypeScript
21
+
Quickstart](quickstart#add-the-sdk-generator).
17
22
18
-
1. Create a new GitHub repository called `company-typescript` (or something similar) for your SDK, if you haven't done so already.
19
-
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**.
20
-
23
+
</Info>
21
24
22
25
## Configure `generators.yml`
23
26
24
27
<Steps>
25
28
26
-
<Steptitle="Run `fern add <generator>`">
27
-
28
-
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.
29
-
30
-
Add a new generator to `generators.yml`:
31
-
32
-
33
-
```bash
34
-
fern add fern-typescript-sdk --group ts-sdk
35
-
```
36
-
37
-
Once the command completes, you'll see a new group created in your `generators.yml`:
Next, change the output location in`generators.yml` from `local-file-system` (the default) to `npm` to indicate that Fern should publish your package directly to the npm registry:
31
+
In the `group` for your TypeScript SDK, change the output location in from `local-file-system` (the default) to `npm` to indicate that Fern should publish your package directly to the npm registry:
Add the path to your GitHub repository to `generators.yml`:
85
+
Add the path to your GitHub repository to `generators.yml`, if you haven't already:
110
86
111
87
```yaml {11-12}
112
88
groups:
@@ -118,15 +94,15 @@ groups:
118
94
location: npm
119
95
package-name: your-package-name
120
96
config:
121
-
namespaceExport: your-client-name
97
+
namespaceExport: YourClientName
122
98
github:
123
99
repository: your-org/company-typescript
124
100
```
125
101
126
102
</Step>
127
103
</Steps>
128
104
129
-
## Set up npm publishing authentication
105
+
## Generate an npm token
130
106
131
107
<Steps>
132
108
@@ -184,6 +160,79 @@ groups:
184
160
185
161
</Step>
186
162
163
+
</Steps>
164
+
165
+
## Configure npm authentication
166
+
167
+
<AccordionGroup>
168
+
<Accordion title="Option 1: Configure authentication via GitHub Actions">
169
+
170
+
Use [GitHub Actions](https://docs.github.com/en/actions/get-started/quickstart) to automatically publish new SDK versions to npm when you push code changes.
171
+
172
+
<Steps>
173
+
174
+
<Step title="Navigate to Actions in Settings">
175
+
176
+
Open your Fern repository in GitHub. Click on the **Settings** tab in your repository. Then, under the **Security** section, open **Secrets and variables** > **Actions**.
Change your workflow permissions to allow GitHub to run workflows:
202
+
203
+
1. Click on the **Settings** tab in your repository.
204
+
1. Under the **Code and automation** section, navigate to **Actions** > **General**.
205
+
1. Under **Actions permissions**, select **Allow all actions and reusable workflows**.
206
+
1. **Save** your settings. Now GitHub can run the actions you configure.
207
+
208
+
</Step>
209
+
<Step title="Add token to `generators.yml`">
210
+
211
+
Add `token: ${NPM_TOKEN}` to `generators.yml` to tell Fern to use the `NPM_TOKEN` environment variable (which you just configured in your GitHub repo) for authentication when publishing to the npm registry.
When you regenerate your release, Fern will automatically create a workflow in your repository called `.github/workflows/ci.yml` that will automatically publish your release to npm. For an example, see Vapi's [npm publishing GitHub Action](https://github.com/VapiAI/server-sdk-typescript/blob/main/.github/workflows/ci.yml)
230
+
</Step>
231
+
</Steps>
232
+
233
+
</Accordion>
234
+
<Accordion title="Option 2: Configure via environment variables">
235
+
<Steps>
187
236
<Step title="Configure npm authentication token">
188
237
189
238
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.
@@ -199,20 +248,11 @@ groups:
199
248
package-name: name-of-your-package
200
249
token: ${NPM_TOKEN}
201
250
config:
202
-
namespaceExport: your-client-name
251
+
namespaceExport: YourClientName
203
252
github:
204
253
repository: your-org/your-repository
205
254
```
206
255
</Step>
207
-
208
-
</Steps>
209
-
210
-
## Release your SDK to NPM
211
-
212
-
At this point, you're ready to generate a release for your SDK.
213
-
214
-
<Steps>
215
-
216
256
<Step title="Set npm environment variable">
217
257
218
258
Set the `NPM_TOKEN` environment variable on your local machine:
@@ -222,8 +262,13 @@ groups:
222
262
```
223
263
224
264
</Step>
265
+
</Steps>
266
+
</Accordion>
267
+
</AccordionGroup>
268
+
269
+
225
270
226
-
<Step title="Generate your release">
271
+
## Release your SDK to npm
227
272
228
273
Regenerate your SDK and publish it on npm:
229
274
@@ -232,8 +277,4 @@ groups:
232
277
```
233
278
Local machine output will verify that the release is pushed to your
234
279
repository and tagged with the version you specified. Log back into npm and
0 commit comments