2024-02-02 19:53:33 +00:00
## Setting up the environment
2024-12-20 11:54:17 +00:00
This repository uses [`yarn@v1` ](https://classic.yarnpkg.com/lang/en/docs/install ).
2024-02-02 19:53:33 +00:00
Other package managers may work but are not officially supported for development.
2024-02-29 17:39:28 +01:00
To set up the repository, run:
2024-02-02 19:53:33 +00:00
2024-10-01 19:35:05 +00:00
``` sh
$ yarn
$ yarn build
2024-02-02 19:53:33 +00:00
```
This will install all the required dependencies and build output files to `dist/` .
## Modifying/Adding code
2024-09-13 15:29:42 +00:00
Most of the SDK is generated code. Modifications to code will be persisted between generations, but may
result in merge conflicts between manual patches and changes from the generator. The generator will never
modify the contents of the `src/lib/` and `examples/` directories.
2024-02-02 19:53:33 +00:00
## Adding and running examples
2024-09-13 15:29:42 +00:00
All files in the `examples/` directory are not modified by the generator and can be freely edited or added to.
2024-02-02 19:53:33 +00:00
2024-10-01 19:35:05 +00:00
``` ts
2024-02-02 19:53:33 +00:00
// add an example to examples/<your-example>.ts
# ! / u s r / b i n / e n v - S n p m r u n t s n - T
…
```
2024-12-20 11:54:17 +00:00
``` sh
$ chmod +x examples/<your-example>.ts
2024-02-02 19:53:33 +00:00
# run the example against your api
2024-12-20 11:54:17 +00:00
$ yarn tsn -T examples/<your-example>.ts
2024-02-02 19:53:33 +00:00
```
## Using the repository from source
If you’ d like to use the repository from source, you can either install from git or link to a cloned repository:
To install via git:
2024-10-01 19:35:05 +00:00
``` sh
$ npm install git+ssh://git@github.com:openai/openai-node.git
2024-02-02 19:53:33 +00:00
```
Alternatively, to link a local copy of the repo:
2024-10-01 19:35:05 +00:00
``` sh
2024-02-02 19:53:33 +00:00
# Clone
2024-10-01 19:35:05 +00:00
$ git clone https://www.github.com/openai/openai-node
$ cd openai-node
2024-02-02 19:53:33 +00:00
# With yarn
2024-10-01 19:35:05 +00:00
$ yarn link
$ cd ../my-package
$ yarn link openai
2024-02-02 19:53:33 +00:00
# With pnpm
2024-10-01 19:35:05 +00:00
$ pnpm link --global
$ cd ../my-package
$ pnpm link -—global openai
2024-02-02 19:53:33 +00:00
```
## Running tests
2024-02-29 17:39:28 +01:00
Most tests require you to [set up a mock server ](https://github.com/stoplightio/prism ) against the OpenAPI spec to run the tests.
2024-02-02 19:53:33 +00:00
2024-10-01 19:35:05 +00:00
``` sh
$ npx prism mock path/to/your/openapi.yml
2024-02-02 19:53:33 +00:00
```
2024-10-01 19:35:05 +00:00
``` sh
$ yarn run test
2024-02-02 19:53:33 +00:00
```
## Linting and formatting
This repository uses [prettier ](https://www.npmjs.com/package/prettier ) and
[eslint ](https://www.npmjs.com/package/eslint ) to format the code in the repository.
To lint:
2024-10-01 19:35:05 +00:00
``` sh
$ yarn lint
2024-02-02 19:53:33 +00:00
```
To format and fix all lint issues automatically:
2024-10-01 19:35:05 +00:00
``` sh
$ yarn fix
2024-02-02 19:53:33 +00:00
```
## Publishing and releases
Changes made to this repository via the automated release PR pipeline should publish to npm automatically. If
the changes aren't made through the automated pipeline, you may want to make releases manually.
### Publish with a GitHub workflow
2024-02-29 17:39:28 +01:00
You can release to package managers by using [the `Publish NPM` GitHub action ](https://www.github.com/openai/openai-node/actions/workflows/publish-npm.yml ). This requires a setup organization or repository secret to be set up.
2024-02-02 19:53:33 +00:00
### Publish manually
If you need to manually release a package, you can run the `bin/publish-npm` script with an `NPM_TOKEN` set on
the environment.