@shopify/cli
Version:
A CLI tool to build for the Shopify platform
2 lines (1 loc) • 5.58 kB
JavaScript
import{b as _}from"../../../chunk-HRUGYZZ4.js";import"../../../chunk-NF2ABOOU.js";import"../../../chunk-JQJBBXMX.js";import"../../../chunk-OY3PNHPZ.js";import"../../../chunk-MWGBTOO3.js";import{j as f,l as h,n as I}from"../../../chunk-K6CTUBFC.js";import"../../../chunk-GVQIPEZT.js";import{a as F}from"../../../chunk-DN2IE3VY.js";import"../../../chunk-JAO53IH2.js";import{k as S,q as T}from"../../../chunk-XITQULK4.js";import"../../../chunk-6SF3ZETE.js";import"../../../chunk-3VZEETAV.js";import"../../../chunk-IX5ICOBV.js";import"../../../chunk-QFWIDATO.js";import"../../../chunk-CBXSPL4W.js";import"../../../chunk-UJVH7FZS.js";import"../../../chunk-UXVZ2P63.js";import"../../../chunk-QSTEVZFQ.js";import"../../../chunk-5Y7GIF2W.js";import"../../../chunk-EKXY5COY.js";import"../../../chunk-4DCQNGUV.js";import{o as w,ua as v}from"../../../chunk-XONFGLJQ.js";import"../../../chunk-4LNCYIS3.js";import"../../../chunk-L2MGAEV3.js";import"../../../chunk-PRKBO42R.js";import"../../../chunk-ZSBA6VIC.js";import"../../../chunk-F2QU6WWX.js";import"../../../chunk-XULPJ6UG.js";import{b as P}from"../../../chunk-XR6GMMEU.js";import"../../../chunk-3TNEIDOD.js";import"../../../chunk-MHWV5RQV.js";import"../../../chunk-XOTA6JTZ.js";import"../../../chunk-MOA33ZFO.js";import"../../../chunk-JUVAGMIH.js";import{v as g}from"../../../chunk-6G6TMKXF.js";import"../../../chunk-P6XE4MH5.js";import"../../../chunk-KLMDWDT2.js";import"../../../chunk-5CH3B62S.js";import"../../../chunk-QUTQDXSL.js";import"../../../chunk-WSDN25F5.js";import{d as o}from"../../../chunk-M56NDIMD.js";import"../../../chunk-PD5ZHJWI.js";import{r as x}from"../../../chunk-LDGAHMS7.js";import"../../../chunk-ZR76GGZ6.js";import"../../../chunk-EENHXSWU.js";import"../../../chunk-FUOIGXI4.js";import"../../../chunk-6M3ZYNGO.js";import"../../../chunk-QYR5VPQA.js";import"../../../chunk-OBEWZXOQ.js";import{Nb as O,Ua as u,ma as c}from"../../../chunk-N5PQPIBF.js";import"../../../chunk-CERXUPGC.js";import"../../../chunk-T4M5CWAO.js";import"../../../chunk-PRVQAHWI.js";import"../../../chunk-YTNDFQJT.js";import"../../../chunk-ULQG3XQS.js";import"../../../chunk-IU2ZQ6TE.js";import"../../../chunk-PIBY5DDZ.js";import{e as $,g as d}from"../../../chunk-VPRTJUIN.js";d();d();d();async function y({session:e,overridesContent:r,themeId:t}){v("theme-preview:create");let m=`${h(e)}/theme_preview.json?preview_theme_id=${t}`,n=await f(e,{headers:{"Content-Type":"application/json"}}),i=await w(m,{method:"POST",body:r,headers:n});if(!i.ok)throw new o(`Theme preview request failed with status ${i.status}: ${i.statusText}`);let s=await R(i);return v("theme-preview:create"),s}async function b({session:e,overridesContent:r,themeId:t,previewIdentifier:a}){v("theme-preview:update");let n=`${h(e)}/theme_preview.json?preview_theme_id=${t}&preview_identifier=${encodeURIComponent(a)}`,i=await f(e,{headers:{"Content-Type":"application/json"}}),s=await w(n,{method:"POST",body:r,headers:i});if(!s.ok)throw new o(`Theme preview request failed with status ${s.status}: ${s.statusText}`);let J=await R(s);return v("theme-preview:update"),J}async function R(e){let r=await e.json();if(r.error)throw new o(`Theme preview failed: ${r.error}`);if(!r.url||!r.preview_identifier)throw new o("Theme preview returned an unexpected response");return{url:r.url,preview_identifier:r.preview_identifier}}async function A(e){if(!u(e.overrideJson))throw new o(`Override file not found: ${e.overrideJson}`);let r=await c(e.overrideJson),t;try{t=JSON.parse(r)}catch(i){let s=i instanceof Error?i.message:String(i);throw new o(`Failed to parse override file: ${e.overrideJson}`,s)}let a=await I(e.themeId,e.adminSession,e.password),m=JSON.stringify(t),n=e.previewIdentifier?await b({session:a,overridesContent:m,themeId:e.themeId,previewIdentifier:e.previewIdentifier}):await y({session:a,overridesContent:m,themeId:e.themeId});e.json?O(JSON.stringify({url:n.url,preview_identifier:n.preview_identifier})):g({body:[{list:{title:e.previewIdentifier?"Preview updated":"Preview is ready",items:[{link:{url:n.url}},`Preview ID: ${n.preview_identifier}`]}}]}),e.open&&_(n.url,"theme preview")}var p=$(x(),1);var l=class extends T{static{this.summary="Applies JSON overrides to a theme and returns a preview URL."}static{this.descriptionWithMarkdown="Applies a JSON overrides file to a theme and creates or updates a preview. This lets you quickly preview changes.\n\n The command returns a preview URL and a preview identifier. You can reuse the preview identifier with `--preview-id` to update an existing preview instead of creating a new one."}static{this.description=this.descriptionWithoutMarkdown()}static{this.flags={...P,...S,theme:p.Flags.string({char:"t",description:"Theme ID or name of the remote theme.",env:"SHOPIFY_FLAG_THEME_ID",required:!0}),overrides:p.Flags.string({description:"Path to a JSON overrides file.",env:"SHOPIFY_FLAG_OVERRIDES",required:!0}),"preview-id":p.Flags.string({description:"An existing preview identifier to update instead of creating a new preview.",env:"SHOPIFY_FLAG_PREVIEW_ID"}),open:p.Flags.boolean({description:"Automatically launch the theme preview in your default web browser.",env:"SHOPIFY_FLAG_OPEN",default:!1}),json:p.Flags.boolean({description:"Output the preview URL and identifier as JSON.",env:"SHOPIFY_FLAG_JSON",default:!1})}}static{this.multiEnvironmentsFlags=null}async command(r,t){let a=await F(t,{filter:{theme:r.theme}});await A({adminSession:t,overrideJson:r.overrides,themeId:a.id.toString(),previewIdentifier:r["preview-id"],open:r.open,password:r.password,json:r.json})}};export{l as default};