@shopify/cli
Version:
A CLI tool to build for the Shopify platform
4 lines (2 loc) • 4.78 kB
JavaScript
import{a as R}from"../../../chunk-MWGBTOO3.js";import{c as k,i as O,n as j}from"../../../chunk-K6CTUBFC.js";import{e as x}from"../../../chunk-GVQIPEZT.js";import{a as b}from"../../../chunk-DN2IE3VY.js";import"../../../chunk-JAO53IH2.js";import{k as A,q as v}from"../../../chunk-XITQULK4.js";import"../../../chunk-IX5ICOBV.js";import"../../../chunk-QFWIDATO.js";import"../../../chunk-CBXSPL4W.js";import"../../../chunk-UJVH7FZS.js";import"../../../chunk-EKXY5COY.js";import"../../../chunk-4DCQNGUV.js";import"../../../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 y,c as L}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{J as F}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 T}from"../../../chunk-M56NDIMD.js";import"../../../chunk-PD5ZHJWI.js";import{r as I}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{$a as $,Mb as S,Qb as a,la as w,ua as g}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{d as m,i as u}from"../../../chunk-IU2ZQ6TE.js";import"../../../chunk-PIBY5DDZ.js";import{e as _,g as l}from"../../../chunk-VPRTJUIN.js";l();l();l();import{fileURLToPath as D}from"node:url";async function q(...r){let e=await $("package.json",{cwd:D(import.meta.url),type:"file"});if(!e)throw new Error("Failed to find CLI root path");return e.endsWith("/packages/theme/package.json")?m(u(e),"assets",...r):m(u(e),"dist","assets",...r)}async function E(r,e,i,t,n,p){let f=await k(r)?await R(p,r.storeFqdn):void 0;if(n)throw new T("Unable to use Admin API or Theme Access tokens with the profile command","You must authenticate manually by not passing the --password flag.");let c=await j(e,r,n,f),o=await O(c,{method:"GET",path:i,query:[],themeId:e,headers:{Accept:"application/vnd.speedscope+json"}});if(o.status!==200){let h=await o.text();throw new Error(`Bad response: ${o.status}: ${h}`)}let s=await o.text();t?S(s):await U(s)}async function U(r){let e=process.env.WSL_DISTRO_NAME,i=e?`//wsl$/${e}`:"",t=await q("speedscope","index.html");a(`[Theme Profile] Resolved URL to open: ${t}`);let n="liquid-profile",p=Buffer.from(r).toString("base64"),f=`speedscope.loadFileFromBase64(${JSON.stringify(n)}, ${JSON.stringify(p)})`,c=`speedscope-${Number(new Date)}-${process.pid}`,o=m(w(),`${c}.js`);a(`[Theme Profile] writing JS file to: ${o}`),await g(o,f),a(`[Theme Profile] JS file created successfully: ${o}`),t=`${i}${t}`,o=`${i}${o}`,t+=`#localProfilePath=${o}`;let s=m(w(),`${c}.html`);a(`[Theme Profile] writing HTML file to: ${s}`),await g(s,`<script>window.location=${JSON.stringify(t)}</script>`),a(`[Theme Profile] HTML file created successfully: ${s}`),s=`${i}${s}`,t=`file://${s}`,a(`[Theme Profile] Opening URL: ${t}`);let h=await F(t);a(`[Theme Profile] URL opened successfully: ${h}`)}var d=_(I(),1);var P=class extends v{static{this.summary="Profile the Liquid rendering of a theme page."}static{this.usage=["theme profile","theme profile --url /products/classic-leather-jacket"]}static{this.descriptionWithMarkdown=`Profile the Shopify Liquid on a given page.
This command will open a web page with the Speedscope profiler detailing the time spent executing Liquid on the given page.`}static{this.description=this.descriptionWithoutMarkdown()}static{this.flags={...y,...A,theme:d.Flags.string({char:"t",description:"Theme ID or name of the remote theme.",env:"SHOPIFY_FLAG_THEME_ID"}),url:d.Flags.string({description:"The url to be used as context",env:"SHOPIFY_FLAG_URL",default:"/"}),"store-password":d.Flags.string({description:"The password for storefronts with password protection.",env:"SHOPIFY_FLAG_STORE_PASSWORD"}),...L}}static{this.multiEnvironmentsFlags=null}async command(e,i){let{password:t}=e,n;e.theme?n={filter:{theme:e.theme}}:n={filter:{live:!0}};let p=await b(i,n),f=[{title:`Generating Liquid profile for ${i.storeFqdn} ${e.url}`,task:async()=>{await E(i,p.id.toString(),e.url,e.json,t,e["store-password"])}}];await x(f)}};export{P as default};