← back to Dw Marketing Reels

storefront/graduate-interactive/PUSH-graduate-interactive.sh

25 lines

#!/usr/bin/env bash
# GATED — customer-facing LIVE Shopify theme write. Do NOT run without Steve's go.
# Swaps the graduate collection hero's plain <video> for the interactive auto-play
# flip book. Rollback-first: snapshots the current live section before PUT.
set -euo pipefail
DOMAIN="designer-laboratory-sandbox.myshopify.com"; VER="2024-10"; THEME="145121607731"
KEY="sections/dw-collection-hero.liquid"
NEW="$HOME/Projects/dw-marketing-reels/storefront/graduate-interactive/dw-collection-hero.NEW.liquid"
BAK="$HOME/Projects/dw-marketing-reels/storefront/graduate-interactive/ROLLBACK-dw-collection-hero-$(date +%Y%m%d-%H%M%S).json"
TOK="$(grep -E '^SHOPIFY_THEME_TOKEN=' "$HOME/Projects/secrets-manager/.env" | head -1 | cut -d= -f2-)"
echo "== 1. ROLLBACK SNAPSHOT of current live section → $BAK"
curl -s "https://$DOMAIN/admin/api/$VER/themes/$THEME/assets.json?asset%5Bkey%5D=$KEY" -H "X-Shopify-Access-Token: $TOK" > "$BAK"
grep -q '"value"' "$BAK" && echo "   saved (rollback = re-PUT this .json's value)" || { echo "   ✗ no current value fetched — ABORT"; exit 1; }
echo "== 2. PUT new section (interactive flip book)"
NEW="$NEW" KEY="$KEY" DOMAIN="$DOMAIN" VER="$VER" THEME="$THEME" TOK="$TOK" node -e '
const fs=require("fs"),https=require("https");
const val=fs.readFileSync(process.env.NEW,"utf8");
const body=JSON.stringify({asset:{key:process.env.KEY,value:val}});
const req=https.request({method:"PUT",host:process.env.DOMAIN,path:`/admin/api/${process.env.VER}/themes/${process.env.THEME}/assets.json`,headers:{"X-Shopify-Access-Token":process.env.TOK,"Content-Type":"application/json","Content-Length":Buffer.byteLength(body)}},r=>{let s="";r.on("data",d=>s+=d);r.on("end",()=>{console.log("   HTTP",r.statusCode);console.log("   ",s.slice(0,300));process.exit(r.statusCode<300?0:1);});});
req.on("error",e=>{console.error(e);process.exit(1)});req.write(body);req.end();
'
echo "== 3. VERIFY live page"
sleep 3
curl -s "https://www.designerwallcoverings.com/collections/the-graduate-collection" | grep -c "dw-gbook" | xargs echo "   dw-gbook on live page:"