#!/usr/bin/env bash
# Copy manifold-3d (Apache-2.0) as published on npm: the ES module glue and the WebAssembly file, plus its license.
# Pages that load it need 'wasm-unsafe-eval' in their CSP. The glue is renamed .mjs so Node reads it as a module too.
set -euo pipefail
VERSION="${1:-3.5.4}"
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
cd "$WORK"
npm init -y > /dev/null
npm install --no-audit --no-fund "manifold-3d@$VERSION" > /dev/null
OUT="$ROOT/js/vendor/manifold-3d-$VERSION"
mkdir -p "$OUT"
cp node_modules/manifold-3d/manifold.js "$OUT/manifold.mjs"
cp node_modules/manifold-3d/manifold.wasm "$OUT/manifold.wasm"
cp node_modules/manifold-3d/LICENSE "$OUT/LICENSE.txt"
ls -l "$OUT"
