#!/bin/bash
set -e
cd "$(dirname "$0")/.."

pnpm run build

# Assemble the release bundle under target/, the way the other modules do.
# esbuild leaves the runtime dependencies external (sharp, pino, pino-pretty,
# pino-loki), so the image has to install them on build: ship the manifests
# next to dist/ plus a setup script for Dockerfile.media-processor to run.
rm -rf target
mkdir -p target
rsync -avr --delete dist/ target/dist/
cp package.json pnpm-lock.yaml pnpm-workspace.yaml target/

cat <<SETUP | tee target/setup > /dev/null
#!/usr/bin/env bash
set -e;
command -v pnpm >/dev/null || { echo "error: pnpm not found in PATH" >&2; exit 1; };
pnpm install -P;
SETUP

chmod +x target/setup
