1// Vendor the pulseq +mr MATLAB package into src/engine/pulseq/+mr so the app
2// can stage it into the numbl VFS at runtime. Run against a local pulseq
3// checkout: node scripts/vendor-pulseq.mjs [path-to-pulseq] (default ../../pulseq).
4// Copies only .m files, plus pulseq's LICENSE, and records the source commit.
5import fs from 'node:fs'
6import path from 'node:path'
7import { execSync } from 'node:child_process'
8import { fileURLToPath } from 'node:url'
10const here = path.dirname(fileURLToPath(import.meta.url))
11const repoRoot = path.join(here, '..')
12const pulseqRoot = path.resolve(repoRoot, process.argv[2] ?? '../../pulseq')
13const srcMr = path.join(pulseqRoot, 'matlab', '+mr')
14const destRoot = path.join(repoRoot, 'src', 'engine', 'pulseq')
15const destMr = path.join(destRoot, '+mr')
17if (!fs.existsSync(srcMr)) {
18 console.error(`pulseq +mr tree not found at ${srcMr}`)
19 process.exit(1)
20}
22fs.rmSync(destMr, { recursive: true, force: true })
23let count = 0
24for (const entry of fs.readdirSync(srcMr, { recursive: true })) {
25 const rel = String(entry)
26 const from = path.join(srcMr, rel)
27 if (!fs.statSync(from).isFile() || !rel.endsWith('.m')) continue
28 const to = path.join(destMr, rel)
29 fs.mkdirSync(path.dirname(to), { recursive: true })
30 fs.copyFileSync(from, to)
31 count++
32}
34fs.copyFileSync(path.join(pulseqRoot, 'LICENSE'), path.join(destRoot, 'LICENSE'))
36let commit = 'unknown'
37try {
38 commit = execSync('git describe --tags --always', { cwd: pulseqRoot }).toString().trim()
39} catch {
40 /* not a git checkout */
41}
42fs.writeFileSync(
43 path.join(destRoot, 'VENDORED.md'),
44 `# Vendored pulseq +mr package
46Copied from https://github.com/pulseq/pulseq (\`matlab/+mr\`, .m files only)
47at version \`${commit}\` by \`scripts/vendor-pulseq.mjs\`. Do not edit these
48files here — update the pulseq checkout and re-run \`npm run vendor-pulseq\`.
50pulseq is MIT-licensed; see LICENSE in this directory.
52Note: at runtime the engine replaces \`+mr/+aux/md5.m\` (which needs Java on
53MATLAB) with a wrapper over numbl's \`hash\` builtin — see src/engine/mrFiles.ts.
54`,
55)
56console.log(`vendored ${count} .m files from ${srcMr} (${commit})`)