← back to Hollywood Import

momentum-feed/build-acoustic-manifest.mjs

46 lines

#!/usr/bin/env node
// Build the Acoustic go-live manifest (drip schema) from momentum_colorways ⋈ momentum_golive_prep.
// Feeds hollywood-create.mjs --manifest=... (the EXISTING capped drip engine). $0, reversible (a JSON file).
import { createRequire } from 'module';
import fs from 'fs';
const require = createRequire(import.meta.url);
const { Pool } = require('pg');
const pool = new Pool({ connectionString: 'postgresql://dw_admin:DW2024!@127.0.0.1:5432/dw_unified' });
const OUT = new URL('acoustic-golive.json', import.meta.url).pathname;

async function main() {
  const { rows } = await pool.query(`
    SELECT c.id, c.dw_sku, c.momentum_sku, p.hw_title, COALESCE(c.ai_color_name, c.color_name) AS color,
           c.hw_price, c.uom, c.width, c.image_url, p.panel_spec, c.pl_city_name, c.content, c.finish,
           c.has_flame_cert, c.fire_rating, c.weight, c.description, c.repeat_info, c.cleaning
    FROM momentum_colorways c JOIN momentum_golive_prep p ON p.colorway_id = c.id
    WHERE c.category='Acoustic' AND c.hw_price IS NOT NULL AND c.dw_sku IS NOT NULL
      AND c.image_url IS NOT NULL AND c.image_url <> ''
    ORDER BY p.hw_title, c.dw_sku`);

  const items = rows.map(r => {
    const tags = ['Hollywood Wallcoverings', 'Acoustic Panel', r.color, r.pl_city_name, 'Commercial', 'Contract',
      r.hw_title, r.momentum_sku, r.fire_rating, r.has_flame_cert ? 'Flame Certified' : null]
      .filter(Boolean).join(', ');
    return {
      id: r.id, dw_sku: r.dw_sku, mfr_sku: r.momentum_sku,
      pattern: r.hw_title, color: r.color,
      hw: Number(r.hw_price).toFixed(2), uom: r.uom || 'BOX', width: r.width || '',
      image: r.image_url, tags,
      content: r.content || '', finish: r.finish || '',
      product_type: 'Acoustic Panel',
      spec: r.panel_spec || '',
      weight: r.weight || '', description: r.description || '',
      repeat: r.repeat_info || '', cleaning: r.cleaning || '',
      fire_rating: r.fire_rating || (r.has_flame_cert ? 'Flame Certified' : ''),
    };
  });
  fs.writeFileSync(OUT, JSON.stringify(items, null, 1));
  console.log(`acoustic-golive.json: ${items.length} items.`);
  console.log('  sample:', JSON.stringify(items[0]).slice(0, 260));
  const uoms = items.reduce((a, x) => (a[x.uom] = (a[x.uom] || 0) + 1, a), {});
  console.log('  UOM dist:', JSON.stringify(uoms));
  await pool.end();
}
main().catch(e => { console.error(e); process.exit(1); });