← back to Fix Live Board
scaffold.mjs
42 lines
#!/usr/bin/env node
// Scaffold a new fix-live-board job: node scaffold.mjs <slug> "<Display Name>"
// Writes jobs/<slug>.json (template) + probes/<slug>.mjs (stub) if absent, then prints next steps.
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const ROOT = path.dirname(fileURLToPath(import.meta.url));
const slug = (process.argv[2] || '').trim().toLowerCase().replace(/[^a-z0-9\-]+/g, '-').replace(/^-+|-+$/g, '');
const name = (process.argv[3] || slug).trim();
if (!slug) { console.error('Usage: node scaffold.mjs <slug> "<Display Name>"'); process.exit(1); }
const jobPath = path.join(ROOT, 'jobs', slug + '.json');
const probePath = path.join(ROOT, 'probes', slug + '.mjs');
if (fs.existsSync(jobPath)) { console.error('Job already exists: ' + jobPath); process.exit(1); }
const job = {
id: slug, name, blurb: 'TODO: one-line description of the fix set.', watch: true,
probe: 'node probes/' + slug + '.mjs', probeTimeoutMs: 30000,
fields: [
{ key: 'field_a', ok: 'a ok', bad: 'a missing' },
{ key: 'field_b', ok: 'b ok', bad: 'b missing', warn: true }
],
fixers: []
};
const probeStub = `#!/usr/bin/env node
// Probe for "${name}" — print a JSON array of rows to stdout. READ-ONLY.
// Row: {id,title,sku,price,img,created,status,fields:{field_a:bool,field_b:bool},fixed?:bool}
// 'fixed' is optional; if omitted a row is fixed when every non-warn field is true.
const rows = [
// TODO: query your real source (Shopify / Postgres / API / file) and map each item to a row.
{ id: 'TODO-1', title: 'example', sku: 'TODO-1', price: 0, created: new Date().toISOString(), status: '', fields: { field_a: false, field_b: false } }
];
process.stdout.write(JSON.stringify(rows));
`;
fs.writeFileSync(jobPath, JSON.stringify(job, null, 2) + '\n');
if (!fs.existsSync(probePath)) fs.writeFileSync(probePath, probeStub);
console.log('✓ Scaffolded job [' + slug + ']');
console.log(' jobs/' + slug + '.json — edit fields[] + fixers[]');
console.log(' probes/' + slug + '.mjs — make it query your real source');
console.log('\nThen: node run.mjs ' + slug + ' (the watcher will also auto-spin it while it has items to follow)');