← Files Flows by plugin.spaceARCHIVED FILE
scripts/capture-status.mjs
2.28 KB · Nov 30, 2026 · 00:17 UTC
#!/usr/bin/env node
import { launcherCommand } from '../lib/node-runtime.mjs';
import { realpath, stat } from 'node:fs/promises';
import { dirname, isAbsolute, relative, resolve } from 'node:path';
import { isEntrypoint } from '../lib/entrypoint.mjs';
import { readDocument } from '../lib/document.mjs';
import { createLibrary } from '../lib/library.mjs';
export async function captureStatus(file, library = createLibrary()) {
const { document } = await readDocument(file);
const root = await realpath(dirname(file));
const profiles = (await library.capturePreferences.effective(document.captureSettings)).profiles.filter(profile => profile.enabled);
const missing = [], stale = [], captured = [];
for (const node of document.nodes.filter(node => node.type === 'screen')) for (const profile of profiles) {
const shot = node.screenshots?.[profile.id];
if (!shot) { missing.push({ node: node.id, profile: profile.id, reason: 'not captured' }); continue; }
try {
const path = await realpath(resolve(root, shot.path));
const part = relative(root, path);
const info = await stat(path);
if (!part || part.startsWith('..') || isAbsolute(part) || !info.isFile() || !info.size || info.size > 8 * 1024 * 1024) throw new Error('invalid image');
if (shot.viewport.width !== profile.width || shot.viewport.height !== profile.height) stale.push({ node: node.id, profile: profile.id, reason: 'viewport settings changed' });
else captured.push({ node: node.id, profile: profile.id });
} catch { missing.push({ node: node.id, profile: profile.id, reason: 'image file missing or outside scope' }); }
}
return { complete: missing.length === 0 && stale.length === 0, captured: captured.length, expected: captured.length + missing.length + stale.length, missing, stale };
}
export async function main(args = process.argv.slice(2)) {
if (!args[0] || args.includes('--help')) { console.log(`${launcherCommand('capture-status')} /path/flow.flows.json [--require-complete]`); return; }
const result = await captureStatus(resolve(args[0]));
console.log(JSON.stringify(result, null, 2));
if (args.includes('--require-complete') && !result.complete) process.exitCode = 2;
}
if (isEntrypoint(import.meta.url)) main().catch(error => { console.error(error.message); process.exitCode = 1; });
SHA-256: 95d4a1980b067da47f730bbe09bb63e9835332c54482193891ffe56fafe5be24