cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
edf48d11e4fca60f8412a135113649ae9421c6ab

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/build

57lines · modecode

1#!/usr/bin/env bash
2
3set -exuo pipefail
4
5cd "$(dirname "$0")/.."
6
7node 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
14rm -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
17cp -rp src README.md dist
18for file in LICENSE CHANGELOG.md; do
19 if [ -e "${file}" ]; then cp "${file}" dist; fi
20done
21if [ -e "bin/cli" ]; then
22 mkdir -p dist/bin
23 cp -p "bin/cli" dist/bin/;
24fi
25if [ -e "bin/migration-config.json" ]; then
26 mkdir -p dist/bin
27 cp -p "bin/migration-config.json" dist/bin/;
28fi
29# this converts the export map paths for the dist directory
30# and does a few other minor things
31node 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
38node scripts/utils/fix-index-exports.cjs
39cp tsconfig.dist-src.json dist/src/tsconfig.json
40
41node 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
48if [ -e ./scripts/build-deno ]
49then
50 ./scripts/build-deno
51fi
52# build all sub-packages
53for dir in packages/*; do
54 if [ -d "$dir" ]; then
55 (cd "$dir" && yarn install --pure-lockfile && yarn build)
56 fi
57done
58