← back to Dw Fleet Registry
propagate-component.mjs
26 lines
import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path';
import { execSync } from 'node:child_process';
const PROJECTS = path.join(os.homedir(),'Projects');
const SELF = '/Users/macstudio3/Projects/dw-fleet-registry';
const comp = fs.readFileSync(path.join(SELF,'component','dw-header.js'),'utf8');
const targets = fs.readFileSync('/tmp/fleet-targets.txt','utf8').split('\n').filter(Boolean);
const sh=(c,d)=>{try{return execSync(c,{cwd:d,stdio:['ignore','pipe','pipe']}).toString().trim()}catch{return null}};
const titleCase=s=>s.replace(/(wallcoverings?|wallpapers?|walls?|fabric|covering)/gi,' $1').replace(/\s+/g,' ').trim().replace(/\b\w/g,c=>c.toUpperCase());
const nameFix={linenwallpaper:'Linen Wallpaper',silkwallpaper:'Silk Wallpaper'};
let n=0;
for(const slug of targets){
const dir=path.join(PROJECTS,slug); const pub=path.join(dir,'public','dw-header.js'); const idx=path.join(dir,'public','index.html');
if(!fs.existsSync(idx)) continue;
let changed=false;
// 1. propagate component
if(!fs.existsSync(pub) || fs.readFileSync(pub,'utf8')!==comp){ fs.writeFileSync(pub,comp); changed=true; }
// 2. fix lowercase name
if(nameFix[slug]){ let h=fs.readFileSync(idx,'utf8'); const nh=h.replace(/(window\.DwHeaderConfig=\{siteName:)("[^"]*"|'[^']*')/, `$1${JSON.stringify(nameFix[slug])}`); if(nh!==h){fs.writeFileSync(idx,nh);changed=true;} }
if(changed){
sh('git checkout -B style-rebuild-pilot',dir); sh('git add public/dw-header.js public/index.html',dir);
const c=sh(`git -c user.email="steve@designerwallcoverings.com" -c user.name="Steve Abrams" commit -q -m "dw-header: hide ANY pre-existing <header> (not just ns-header); title-case bare-slug names" && git rev-parse --short HEAD`,dir);
n++; if(nameFix[slug]||n<=3) console.log(' '+slug.padEnd(22)+(c||''));
}
}
console.log(`\n${n} sites updated (component + name fixes)`);