Files
maestro/scripts/copy-mermaid-vendor.mjs
oss-sync 57702b4f34
CI / build-and-test (push) Canceled after 0s
sync: update from private repo (2336949a)
2026-09-17 11:29:31 +00:00

37 lines
1.7 KiB
JavaScript

#!/usr/bin/env node
/**
* Copy the Mermaid browser bundle into vendor/ so the server can render
* diagrams (#1025).
*
* The copy comes from the UI's own dependency — deliberately the SAME install
* the app renders Markdown with. Adding `mermaid` to the server's package.json
* instead would create two versions that drift apart, which is precisely the
* failure this tool exists to remove.
*
* vendor/ is gitignored and is already what the Docker image ships (noVNC lives
* there too), so the runtime stage picks this up with the COPY it already has.
* Runs at the end of `npm run build:ui`, when ui/node_modules is guaranteed.
*/
import { copyFileSync, mkdirSync, readFileSync, writeFileSync, existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
const src = join(root, 'ui', 'node_modules', 'mermaid', 'dist', 'mermaid.min.js');
const pkg = join(root, 'ui', 'node_modules', 'mermaid', 'package.json');
const destDir = join(root, 'vendor', 'mermaid');
const dest = join(destDir, 'mermaid.min.js');
if (!existsSync(src)) {
console.error(`[copy-mermaid-vendor] ${src} not found — run npm --prefix ui ci first.`);
process.exit(1);
}
mkdirSync(destDir, { recursive: true });
copyFileSync(src, dest);
const version = existsSync(pkg) ? JSON.parse(readFileSync(pkg, 'utf8')).version : 'unknown';
// The UMD bundle does not expose its own version, and package.json is not
// copied — leave a sidecar so the tool can report what it validated with.
writeFileSync(join(destDir, 'version.txt'), `${version}\n`);
console.log(`[copy-mermaid-vendor] mermaid ${version} -> vendor/mermaid/mermaid.min.js`);