diff --git a/fern/products/sdks/overview/typescript/publishing-to-npm.mdx b/fern/products/sdks/overview/typescript/publishing-to-npm.mdx index b93e88f37..010be1e37 100644 --- a/fern/products/sdks/overview/typescript/publishing-to-npm.mdx +++ b/fern/products/sdks/overview/typescript/publishing-to-npm.mdx @@ -22,9 +22,9 @@ you'll have a versioned package published on npm. -## Configure `generators.yml` +## Configure SDK package settings -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. +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. @@ -79,26 +79,6 @@ you'll have a versioned package published on npm. - - - Add the path to the GitHub repository containing your TypeScript SDK: - - ```yaml {11-12} title="generators.yml" - groups: - ts-sdk: - generators: - - name: fernapi/fern-typescript-sdk - version: - output: - location: npm - package-name: your-package-name - config: - namespaceExport: YourClientName - github: - repository: your-org/company-typescript - ``` - - ## Generate an npm token @@ -132,7 +112,7 @@ you'll have a versioned package published on npm. 1. Name your token and select **Automation** as the token type. 1. Click **Generate Token**. - Save your new token – it won’t be displayed after you leave the page. + Save your new token – it won't be displayed after you leave the page. Creating NPM Automation Token @@ -148,7 +128,7 @@ you'll have a versioned package published on npm. 1. Optionally fill out additional permissions according to your organization's requirements. 1. Click **Generate Token**. - Save your new token – it won’t be displayed after you leave the page. + Save your new token – it won't be displayed after you leave the page. Creating Granular Access Token @@ -163,10 +143,84 @@ you'll have a versioned package published on npm. ## Configure npm publication -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. + + + + Add the path to the GitHub repository containing your TypeScript SDK: + + ```yaml {11-12} title="generators.yml" + groups: + ts-sdk: + generators: + - name: fernapi/fern-typescript-sdk + version: + output: + location: npm + package-name: your-package-name + config: + namespaceExport: YourClientName + github: + repository: your-org/company-typescript + ``` + + + + +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. + +```yaml title="generators.yml" {9} +groups: + ts-sdk: + generators: + - name: fernapi/fern-typescript-sdk + version: + output: + location: npm + package-name: name-of-your-package + token: ${NPM_TOKEN} + config: + namespaceExport: YourClientName + github: + repository: your-org/your-repository +``` + + + +Optionally set the mode to control how Fern handles SDK publishing: + +- `mode: release` (default): Fern generates code, commits to main, and tags a release automatically +- `mode: pull-request`: Fern generates code and creates a PR for you to review before release +- `mode: push`: Fern generates code and pushes to a branch you specify for you to review before release + +```yaml title="generators.yml" {14} +groups: + ts-sdk: + generators: + - name: fernapi/fern-typescript-sdk + version: + output: + location: npm + package-name: name-of-your-package + token: ${NPM_TOKEN} + config: + namespaceExport: YourClientName + github: + repository: your-org/your-repository + mode: push + branch: your-branch-name # Required for mode: push +``` +You can also configure other settings, like the reviewers or license. Refer to the [full `github` (`generators.yml`) reference](/sdks/reference/generators-yml#github) for more information. + + + + +## Publish your SDK + +Decide how you want to publish your SDK to npm. You can use GitHub workflows for automated releases or publish directly via the CLI. - + + 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. @@ -203,26 +257,6 @@ Set up a release workflow via [GitHub Actions](https://docs.github.com/en/action organization listed in `fern.config.json`. 1. Click **Add secret**. - - - - Add `token: ${NPM_TOKEN}` to `generators.yml`. - - ```yaml {9} title="generators.yml" - groups: - ts-sdk: - generators: - - name: fernapi/fern-typescript-sdk - version: - output: - location: npm - package-name: name-of-your-package - token: ${NPM_TOKEN} - config: - namespaceExport: YourClientName - github: - repository: your-org/your-repository - ``` @@ -261,64 +295,45 @@ Set up a release workflow via [GitHub Actions](https://docs.github.com/en/action - + - Navigate to the **Actions** tab, select the workflow you just created, specify a version number, and click **Run workflow**. - - 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. + Navigate to the **Actions** tab, select the workflow you just created, specify a version number, and click **Run workflow**. This regenerates your SDK. Running TS publish workflow - - Once your workflow completes, log back into npm and navigate to **Packages** to see your new release. + + + + - - 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. + - ```yaml {9} - groups: - ts-sdk: - generators: - - name: fernapi/fern-typescript-sdk - version: - output: - location: npm - package-name: name-of-your-package - token: ${NPM_TOKEN} - config: - namespaceExport: YourClientName - github: - repository: your-org/your-repository - ``` - - +Set the `NPM_TOKEN` environment variable on your local machine: - Set the `NPM_TOKEN` environment variable on your local machine: +```bash +export NPM_TOKEN=your-actual-npm-token +``` - ```bash - export NPM_TOKEN=your-actual-npm-token - ``` + + - - - 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. +Regenerate your SDK, specifying the version: - ```bash - fern generate --group ts-sdk --version - ``` - Local machine output will verify that the release is pushed to your - repository and tagged with the version you specified. Log back into npm and - navigate to **Packages** to see your new release. +```bash +fern generate --group ts-sdk --version +``` + + + - diff --git a/fern/products/sdks/snippets/release-sdk.mdx b/fern/products/sdks/snippets/release-sdk.mdx new file mode 100644 index 000000000..3f046ad61 --- /dev/null +++ b/fern/products/sdks/snippets/release-sdk.mdx @@ -0,0 +1,7 @@ +The rest of the release process depends on your chosen mode: + +- **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. + +- **Pull request or push mode:** If you set `mode: pull-request` or `mode: push`, Fern creates a pull request or pushes to a branch respectively. Review and merge the PR (`pull-request`) or branch (`push`), then [tag a new release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) to initiate the npm publishing workflow in your SDK repository. + +Once the workflow completes, you can view your new release by logging into npm and navigating to **Packages**. \ No newline at end of file