← back to Dw Sarah Rowland Searchfix

read-coll-and-designers.mjs

17 lines

import { gql } from './lib.mjs'; import fs from 'node:fs';
// 1) current Sarah Rowland collection body (backup)
const c=(await gql(`{ collection(id:"gid://shopify/Collection/291337273395"){ id title handle templateSuffix descriptionHtml } }`)).collection;
fs.mkdirSync(new URL('./coll-backups/',import.meta.url),{recursive:true});
fs.writeFileSync(new URL('./coll-backups/sarah-rowland.body.BEFORE.html',import.meta.url), c.descriptionHtml||'');
console.log(`Collection: ${c.title} templateSuffix=${c.templateSuffix||'(default)'} bodyLen=${(c.descriptionHtml||'').length}`);
console.log('body preview:', (c.descriptionHtml||'(empty)').replace(/\s+/g,' ').slice(0,200));
// 2) which of the 13 Koroseal designers have Koroseal-vendor products in the DW store?
const names=['Sarah Rowland','Clodagh','Roger Thomas','Chris Collacott','Kurt Johnson','Mandy Budan','Patty Madden','Sondra Alexander','Stacy Garcia','Republic of II BY IV','Evans and Brown','Arte','Alpha Workshops'];
console.log('\nKoroseal designers present in DW store (vendor=Koroseal + name in title):');
for(const n of names){
  const q=`vendor:Koroseal AND title:*${n.split(' ')[0]}*`;
  const d=await gql(`query($q:String!){ products(first:5, query:$q){ nodes{ title } } }`,{q});
  const hits=d.products.nodes.filter(p=>new RegExp(n.split(' ')[0],'i').test(p.title));
  console.log(`  ${hits.length? '✓ '+hits.length : '·  0'}  ${n}`);
}