#!/usr/bin/env node
// Copy @bobfrankston/rmf-tiny's adapter.js into client/lib/ so the compose
// page can dynamic-import it at runtime. msger's custom protocol serves
// files only from contentDir (client/), and `node_modules/` lives at
// app/node_modules — outside that root. A build-time copy keeps the public
// adapter entry reachable without changing msger's served root or messing
// with junctions that npm install would clobber.
import fs from "node:fs";
import path from "node:path";

const root = path.resolve(import.meta.dirname, "..");
const src = path.join(root, "node_modules", "@bobfrankston", "rmf-tiny", "src", "adapter.js");
const dst = path.join(root, "client", "lib", "rmf-tiny.js");

if (!fs.existsSync(src)) {
    console.error(`build-rmf-tiny: source not found at ${src} — run npm install first`);
    process.exit(1);
}
fs.copyFileSync(src, dst);
console.log(`build-rmf-tiny: copied ${path.relative(root, src)} → ${path.relative(root, dst)}`);
