// Vendor the pulseq +mr MATLAB package into src/engine/pulseq/+mr so the app // can stage it into the numbl VFS at runtime. Run against a local pulseq // checkout: node scripts/vendor-pulseq.mjs [path-to-pulseq] (default ../../pulseq). // Copies only .m files, plus pulseq's LICENSE, and records the source commit. import fs from 'node:fs' import path from 'node:path' import { execSync } from 'node:child_process' import { fileURLToPath } from 'node:url' const here = path.dirname(fileURLToPath(import.meta.url)) const repoRoot = path.join(here, '..') const pulseqRoot = path.resolve(repoRoot, process.argv[2] ?? '../../pulseq') const srcMr = path.join(pulseqRoot, 'matlab', '+mr') const destRoot = path.join(repoRoot, 'src', 'engine', 'pulseq') const destMr = path.join(destRoot, '+mr') if (!fs.existsSync(srcMr)) { console.error(`pulseq +mr tree not found at ${srcMr}`) process.exit(1) } fs.rmSync(destMr, { recursive: true, force: true }) let count = 0 for (const entry of fs.readdirSync(srcMr, { recursive: true })) { const rel = String(entry) const from = path.join(srcMr, rel) if (!fs.statSync(from).isFile() || !rel.endsWith('.m')) continue const to = path.join(destMr, rel) fs.mkdirSync(path.dirname(to), { recursive: true }) fs.copyFileSync(from, to) count++ } fs.copyFileSync(path.join(pulseqRoot, 'LICENSE'), path.join(destRoot, 'LICENSE')) let commit = 'unknown' try { commit = execSync('git describe --tags --always', { cwd: pulseqRoot }).toString().trim() } catch { /* not a git checkout */ } fs.writeFileSync( path.join(destRoot, 'VENDORED.md'), `# Vendored pulseq +mr package Copied from https://github.com/pulseq/pulseq (\`matlab/+mr\`, .m files only) at version \`${commit}\` by \`scripts/vendor-pulseq.mjs\`. Do not edit these files here — update the pulseq checkout and re-run \`npm run vendor-pulseq\`. pulseq is MIT-licensed; see LICENSE in this directory. Note: at runtime the engine replaces \`+mr/+aux/md5.m\` (which needs Java on MATLAB) with a wrapper over numbl's \`hash\` builtin — see src/engine/mrFiles.ts. `, ) console.log(`vendored ${count} .m files from ${srcMr} (${commit})`)