#!/usr/bin/env node // Developer mode: set up loop device, stream fa2json output through jq, // tear down on exit. Optionally launch a terminal at the mount point. // // Usage: // sudo node test/dev.mjs // sudo node test/dev.mjs --terminal konsole // sudo node test/dev.mjs --terminal "konsole -e bash" import { spawn } from 'node:child_process'; import { createInterface } from 'node:readline'; import { setup, spawnFa2json } from './lib/setup.mjs'; const terminalArg = (() => { const i = process.argv.indexOf('--terminal'); return i !== -1 ? process.argv.slice(i + 1).join(' ') : null; })(); const { mnt, teardown } = await setup(); console.error(`Mount point: ${mnt}`); // Pipe fa2json stdout through jq for pretty coloured output const fa2json = spawnFa2json(mnt); const jq = spawn('jq', ['-C', '--unbuffered', '.'], { stdio: ['pipe', 'inherit', 'inherit'] }); fa2json.stdout.pipe(jq.stdin); fa2json.on('exit', async () => { jq.stdin.end(); await teardown(); process.exit(0); }); // Launch optional terminal at mount point if (terminalArg) { const [cmd, ...args] = terminalArg.split(' '); spawn(cmd, [...args, '--workdir', mnt], { detached: true, stdio: 'ignore' }).unref(); console.error(`Launched: ${terminalArg} --workdir ${mnt}`); } // Clean teardown on Ctrl+C process.on('SIGINT', async () => { fa2json.kill('SIGTERM'); });