← back to Flock Fix Viewer

apply-theme-sqft2.mjs

24 lines

// Adds "Sq Ft S/R" + "Sq Ft D/R" rows to the PRINTABLE spec-sheet block (snippets/spec-sheet-button.liquid),
// so sqft shows in BOTH spec areas. Run: node apply-theme-sqft2.mjs  (idempotent, backs up first)
import fs from 'fs';
const SHOP='designer-laboratory-sandbox.myshopify.com', MAIN='145121607731';
const KEY='snippets/spec-sheet-button.liquid';
const TOKEN=(fs.readFileSync('/Users/macstudio3/Projects/secrets-manager/.env','utf8')
  .split('\n').find(l=>l.startsWith('SHOPIFY_THEME_TOKEN='))||'').split('=').slice(1).join('=').replace(/["']/g,'').trim();
const API=`https://${SHOP}/admin/api/2024-10`, H={'X-Shopify-Access-Token':TOKEN,'Content-Type':'application/json'};

const anchor="{%- if rep != blank -%}<div class=\"dw-spec-item\"><strong>Repeat:</strong><span>{{ rep | escape }}</span></div>{%- endif -%}";
const add="\n        {%- assign sqftsr = mf.global.sqft_single_roll | default: mf.custom.sqft_single_roll -%}"+
          "\n        {%- if sqftsr != blank -%}<div class=\"dw-spec-item\"><strong>Sq Ft S/R:</strong><span>{{ sqftsr | escape }}</span></div>{%- endif -%}"+
          "\n        {%- assign sqftdr = mf.global.sqft_double_roll | default: mf.custom.sqft_double_roll -%}"+
          "\n        {%- if sqftdr != blank -%}<div class=\"dw-spec-item\"><strong>Sq Ft D/R:</strong><span>{{ sqftdr | escape }}</span></div>{%- endif -%}";

const r=await (await fetch(`${API}/themes/${MAIN}/assets.json?asset%5Bkey%5D=${encodeURIComponent(KEY)}`,{headers:H})).json();
let body=r.asset.value;
fs.writeFileSync('/Users/macstudio3/Projects/flock-fix-viewer/theme-backup/spec-sheet-button.PRE-SQFT.liquid', body);
if(body.includes('Sq Ft S/R')){console.log('Already applied — nothing to do.');process.exit(0);}
if(body.split(anchor).length!==2){console.error('anchor not found uniquely — aborting');process.exit(1);}
body=body.replace(anchor,anchor+add);
const put=await (await fetch(`${API}/themes/${MAIN}/assets.json`,{method:'PUT',headers:H,body:JSON.stringify({asset:{key:KEY,value:body}})})).json();
console.log(put.asset?('OK — updated '+put.asset.key+'. Sq Ft now shows on the printable spec sheet too.'):('ERROR '+JSON.stringify(put)));