← Files Flows by plugin.spaceARCHIVED FILE
scripts/library.mjs
2.11 KB · Nov 30, 2026 · 00:17 UTC
#!/usr/bin/env node
import { resolve } from 'node:path';
import { createLibrary, inferApplication } from '../lib/library.mjs';
import { isEntrypoint } from '../lib/entrypoint.mjs';
import { launcherCommand } from '../lib/node-runtime.mjs';
export async function main(args = process.argv.slice(2)) {
if (args.includes('--help')) {
console.log(`${launcherCommand('library')} --action status|reserve|check|register|archive|activate [--file /path/flow.flows.json] [--library /path/library] [--project /path/app]\nReserve a slot before creating a new document. Reservations expire after 30 minutes. Check access before editing; register after saving. Archive preserves the local files. Restore the flow when a slot is free before opening or exporting it in Flows.`); return;
}
const options = {};
for (let index = 0; index < args.length; index += 2) {
if (!['--action', '--file', '--library', '--project'].includes(args[index]) || !args[index + 1]) throw new Error('Invalid option. Use --help.');
options[args[index]] = args[index + 1];
}
const library = createLibrary(options['--library']);
const action = options['--action'] || 'status';
if (action === 'status') { console.log(JSON.stringify({ access: await library.status(), flows: await library.list() })); return; }
if (!['reserve', 'check', 'register', 'archive', 'activate'].includes(action) || !options['--file']) throw new Error('Choose an action and provide --file.');
const file = resolve(options['--file']), application = await inferApplication(file, options['--project']);
if (action === 'reserve') { console.log(JSON.stringify(await library.reserve(file, application))); return; }
const id = await library.register(file, application);
if (action === 'archive' || action === 'activate') await library.setActive(id, action === 'activate');
if (action === 'check' || action === 'register') await library.withWritable(id, () => {});
console.log(JSON.stringify({ id, access: await library.status(), readOnly: (await library.resolve(id)).readOnly }));
}
if (isEntrypoint(import.meta.url)) main().catch(error => { console.error(error.message); process.exitCode = 1; });
SHA-256: fe19c1fe20cc4255d6da80a8e0babb9aff6614403ac38d406d7a0beb35167ac8