cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
scripts/build
57lines · modecode
| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -exuo pipefail |
| 4 | |
| 5 | cd "$(dirname "$0")/.." |
| 6 | |
| 7 | node scripts/utils/check-version.cjs |
| 8 | |
| 9 | # Build into dist and will publish the package from there, |
| 10 | # so that src/resources/foo.ts becomes <package root>/resources/foo.js |
| 11 | # This way importing from `"cloudflare/resources/foo"` works |
| 12 | # even with `"moduleResolution": "node"` |
| 13 | |
| 14 | rm -rf dist; mkdir dist |
| 15 | # Copy src to dist/src and build from dist/src into dist, so that |
| 16 | # the source map for index.js.map will refer to ./src/index.ts etc |
| 17 | cp -rp src README.md dist |
| 18 | for file in LICENSE CHANGELOG.md; do |
| 19 | if [ -e "${file}" ]; then cp "${file}" dist; fi |
| 20 | done |
| 21 | if [ -e "bin/cli" ]; then |
| 22 | mkdir -p dist/bin |
| 23 | cp -p "bin/cli" dist/bin/; |
| 24 | fi |
| 25 | if [ -e "bin/migration-config.json" ]; then |
| 26 | mkdir -p dist/bin |
| 27 | cp -p "bin/migration-config.json" dist/bin/; |
| 28 | fi |
| 29 | # this converts the export map paths for the dist directory |
| 30 | # and does a few other minor things |
| 31 | node scripts/utils/make-dist-package-json.cjs > dist/package.json |
| 32 | |
| 33 | # build to .js/.mjs/.d.ts files |
| 34 | ./node_modules/.bin/tsc-multi |
| 35 | # we need to patch index.js so that `new module.exports()` works for cjs backwards |
| 36 | # compat. No way to get that from index.ts because it would cause compile errors |
| 37 | # when building .mjs |
| 38 | node scripts/utils/fix-index-exports.cjs |
| 39 | cp tsconfig.dist-src.json dist/src/tsconfig.json |
| 40 | |
| 41 | node scripts/utils/postprocess-files.cjs |
| 42 | |
| 43 | # make sure that nothing crashes when we require the output CJS or |
| 44 | # import the output ESM |
| 45 | (cd dist && node -e 'require("cloudflare")') |
| 46 | (cd dist && node -e 'import("cloudflare")' --input-type=module) |
| 47 | |
| 48 | if [ -e ./scripts/build-deno ] |
| 49 | then |
| 50 | ./scripts/build-deno |
| 51 | fi |
| 52 | # build all sub-packages |
| 53 | for dir in packages/*; do |
| 54 | if [ -d "$dir" ]; then |
| 55 | (cd "$dir" && yarn install --pure-lockfile && yarn build) |
| 56 | fi |
| 57 | done |
| 58 | |