#!/usr/bin/env node // Headless desktop: boots all components under the Node host and prints the // composed desktop as text, optionally after a scripted interaction. // node host/src/cli.mjs [--config file] [--time ISO] [--click-launcher] [--scene out.json] import { writeFile } from 'node:fs/promises'; import { bootDesktop } from './headless.mjs'; import { renderAscii } from './ascii.mjs'; const args = process.argv.slice(2); const opt = (n) => { const i = args.indexOf(`--${n}`); return i < 0 ? undefined : args[i + 1]; }; const flag = (n) => args.includes(`--${n}`); const fixed = opt('time') ? new Date(opt('time')) : undefined; const { desktop, platform } = await bootDesktop({ configPath: opt('config'), now: fixed ? () => fixed : undefined }); let f = desktop.frame(); if (flag('click-launcher')) { const e = desktop.hit.widgets.find((w) => w.widget.id === 'launcher'); desktop.pointer('down', e.rect.x + 10, e.rect.y + 10); f = desktop.frame(); if (flag('type')) { for (const ch of opt('type')) desktop.key(ch); f = desktop.frame(); } } console.log(renderAscii(f.ops, f.screen)); console.log(`\n-- ${f.ops.length} draw-ops; widgets: ${desktop.widgets.map((w) => `${w.id}=${w.componentName}`).join(', ')}; theme=${platform.tokens.name}`); if (opt('scene')) await writeFile(opt('scene'), JSON.stringify(f, null, 1)); if (desktop.faults.length) { console.error(`${desktop.faults.length} component fault(s)`); process.exit(1); }