← back to Shopify Sample Shipping
publish-rollback.mjs
16 lines
#!/usr/bin/env node
// TK-11333 — ROLLBACK: re-publish the theme that was live before ~/publish. Steve runs (--apply).
import fs from 'node:fs';
import { query } from './query.mjs';
const APPLY = process.argv.includes('--apply');
const REC = new URL('./verification/theme-publish.json', import.meta.url);
if (!fs.existsSync(REC)) { console.error('no theme-publish.json — nothing to roll back'); process.exit(1); }
const rec = JSON.parse(fs.readFileSync(REC, 'utf8'));
console.log('will re-publish previous LIVE:', rec.previousMainName, rec.previousMainId);
if (!rec.previousMainId) { console.error('no previousMainId recorded'); process.exit(1); }
if (!APPLY) { console.log('\nDRY-RUN. --apply re-publishes it LIVE.'); process.exit(0); }
const r = (await query(`mutation($id:ID!){themePublish(id:$id){userErrors{field message}}}`, { id: rec.previousMainId })).themePublish;
if (r.userErrors?.length) { console.error('rollback errors:', JSON.stringify(r.userErrors)); process.exit(1); }
const after = (await query(`{themes(first:30){nodes{id name role}}}`)).themes.nodes.find(t => t.role === 'MAIN');
console.log('\n✅ ROLLED BACK. LIVE theme is now:', after ? `${after.name} ${after.id}` : '(?)');