SIGN IN SIGN UP
openai / openai-node UNCLAIMED

Official JavaScript / TypeScript library for the OpenAI API

0 0 1 TypeScript
2023-06-15 22:36:11 -07:00
#!/usr/bin/env bash
2023-06-30 18:45:59 -07:00
set -exuo pipefail
2023-06-15 22:36:11 -07:00
cd "$(dirname "$0")/.."
node scripts/utils/check-version.cjs
2023-06-15 22:36:11 -07:00
2023-06-30 18:45:59 -07:00
# Build into dist and will publish the package from there,
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
# This way importing from `"openai/resources/foo"` works
# even with `"moduleResolution": "node"`
2023-06-15 22:36:11 -07:00
2023-08-05 08:27:09 -07:00
rm -rf dist; mkdir dist
2023-06-30 18:45:59 -07:00
# Copy src to dist/src and build from dist/src into dist, so that
# the source map for index.js.map will refer to ./src/index.ts etc
2023-07-08 11:14:58 -07:00
cp -rp src README.md dist
for file in LICENSE CHANGELOG.md; do
if [ -e "${file}" ]; then cp "${file}" dist; fi
done
2023-08-11 09:24:50 -07:00
if [ -e "bin/cli" ]; then
2025-05-02 14:36:51 +00:00
mkdir -p dist/bin
2023-08-11 09:24:50 -07:00
cp -p "bin/cli" dist/bin/;
fi
2025-05-02 14:36:51 +00:00
if [ -e "bin/migration-config.json" ]; then
mkdir -p dist/bin
cp -p "bin/migration-config.json" dist/bin/;
fi
2023-06-30 18:45:59 -07:00
# this converts the export map paths for the dist directory
# and does a few other minor things
node scripts/utils/make-dist-package-json.cjs > dist/package.json
2023-06-15 22:36:11 -07:00
2023-06-30 18:45:59 -07:00
# build to .js/.mjs/.d.ts files
./node_modules/.bin/tsc-multi
# we need to patch index.js so that `new module.exports()` works for cjs backwards
# compat. No way to get that from index.ts because it would cause compile errors
2023-06-30 18:45:59 -07:00
# when building .mjs
node scripts/utils/fix-index-exports.cjs
cp tsconfig.dist-src.json dist/src/tsconfig.json
2023-08-05 08:27:09 -07:00
node scripts/utils/postprocess-files.cjs
2023-06-27 10:20:27 -07:00
2023-06-30 18:45:59 -07:00
# make sure that nothing crashes when we require the output CJS or
# import the output ESM
2023-08-05 08:27:09 -07:00
(cd dist && node -e 'require("openai")')
(cd dist && node -e 'import("openai")' --input-type=module)
if [ "${OPENAI_DISABLE_DENO_BUILD:-0}" != "1" ] && [ -e ./scripts/build-deno ]
2023-08-05 08:27:09 -07:00
then
./scripts/build-deno
2023-08-05 08:27:09 -07:00
fi