← back to Marketing Command Center

scripts/build-clients-manifest.js

26 lines

#!/usr/bin/env node
/*
 * build-clients-manifest.js — scan public/data for staged client/prospect
 * datasets and (re)write public/data/clients-manifest.json, which the Clients
 * panel reads. Run after fetch-clients.js or any crawl-csv-emails.py run.
 */
const fs = require('fs');
const path = require('path');
const DIR = path.join(__dirname, '..', 'public', 'data');
const pretty = s => s.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase());

const datasets = [];
const counts = d => ({ with_email: d.with_email || 0, with_instagram: d.with_instagram || 0, with_linkedin: d.with_linkedin || 0 });
if (fs.existsSync(path.join(DIR, 'clients-fm.json'))) {
  const d = JSON.parse(fs.readFileSync(path.join(DIR, 'clients-fm.json'), 'utf8'));
  datasets.push({ id: 'fm-clients', label: 'FileMaker Clients', file: 'clients-fm.json', kind: 'clients', count: d.total || (d.clients || []).length, ...counts(d) });
}
for (const f of fs.readdirSync(DIR).filter(f => /^prospects-.*\.json$/.test(f)).sort()) {
  const slug = f.replace(/^prospects-|\.json$/g, '');
  const d = JSON.parse(fs.readFileSync(path.join(DIR, f), 'utf8'));
  datasets.push({ id: slug, label: pretty(slug), file: f, kind: 'prospects', count: d.total || (d.businesses || []).length, ...counts(d) });
}
fs.writeFileSync(path.join(DIR, 'clients-manifest.json'), JSON.stringify({ updated: new Date().toISOString().slice(0, 10), datasets }, null, 2));
console.log(`clients-manifest.json — ${datasets.length} groups:`);
datasets.forEach(d => console.log(`   ${d.id} · ${d.label} · ${d.count}`));