#!/bin/sh
# Compile the TypeScript sources and bundle them into the two module layouts
# that package.json declares, plus the type declarations:
#
#   dist/sentencex.js   ES modules  (the "import" entry point)
#   dist/sentencex.cjs  CommonJS    (the "require" entry point)
#   dist/*.d.ts         type declarations
#
# Upstream builds this with Vite, which is not packaged in Debian.  Vite's
# library mode is a thin wrapper around Rollup, which is available, so the
# equivalent Rollup invocation is used instead (see rollup.config.mjs).
set -e

# The JavaScript goes to the scratch directory that Rollup bundles from; the
# type declarations land in dist/ because package.json points "types" there.
tsc --project tsconfig.build.json --outDir build-js
rollup --config debian/nodejs/rollup.config.mjs

rm -rf build-js
