@shopify/cli
Version:
A CLI tool to build for the Shopify platform
33 lines (25 loc) • 5.75 kB
JavaScript
import{a as A}from"../../../chunk-Y7JGYGV7.js";import{a as h}from"../../../chunk-GVQIPEZT.js";import{a as E,b as N}from"../../../chunk-DN2IE3VY.js";import"../../../chunk-JAO53IH2.js";import{k as c,m as q,q as v}from"../../../chunk-XITQULK4.js";import{a as O}from"../../../chunk-QFWIDATO.js";import{r as F}from"../../../chunk-CBXSPL4W.js";import"../../../chunk-UJVH7FZS.js";import"../../../chunk-EKXY5COY.js";import"../../../chunk-4DCQNGUV.js";import{O as b}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 D,c as S}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{A as I,S as T,v as w,x as m}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"../../../chunk-M56NDIMD.js";import"../../../chunk-PD5ZHJWI.js";import{r as j}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{Mb as n}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 P,g as d}from"../../../chunk-VPRTJUIN.js";d();d();async function C(t,o,e){let{name:r,verbose:u,noColor:l,json:a,force:J}=e,g=T()||J;if(A({verbose:u,noColor:l}),g&&!o){let s="A theme ID is required to duplicate a theme, specify one with the --theme flag";a?n(JSON.stringify({message:s,errors:[]})):m({body:[s]});return}let i=o?await N(t,o):await E(t,{header:"Select a theme to duplicate",filter:{theme:o}});if(!i){let s=`No theme with ID ${o} could be found. Use shopify theme list to find a theme ID.`;a?n(JSON.stringify({message:s,errors:[]})):m({body:[s]});return}if(i?.role==="development"){let s="Development themes can't be duplicated. Use shopify theme push to upload it to the store first.";a?n(JSON.stringify({message:s,errors:[]})):m({body:[s]});return}if(!g&&!await I({message:`Do you want to duplicate '${i.name}' on ${t.storeFqdn}?`,confirmationMessage:`Yes, duplicate '${i.name}'`,cancellationMessage:"No, cancel duplicate"}))return;let y=await F(i.id,r,t);a?M(i,t,y):x(i,t,y)}function x(t,o,e){if(e.userErrors&&e.userErrors.length>0){let r=e.userErrors.map(u=>u.message).join(", ");m({body:["The theme",...h(t),"could not be duplicated due to errors: ",{subdued:r},{char:"."},...e.requestId?[`
Request ID: `,{subdued:e.requestId}]:[]]})}else e.theme?w({body:["The theme",...h(t),"has been duplicated",{char:"."}],nextSteps:[[{link:{label:"View the duplicated theme",url:O(e.theme,o)}}]]}):m({body:["The theme",...h(t),"unexpectedly could not be duplicated",{char:"."},...e.requestId?[`
Request ID: `,{subdued:e.requestId}]:[]]})}function M(t,o,e){if(e.userErrors&&e.userErrors.length>0)n(JSON.stringify({message:`The theme '${t.name}' could not be duplicated due to errors`,errors:e.userErrors.map(r=>r.message),requestId:e.requestId}));else if(e.theme){let{id:r,name:u,role:l}=e.theme,a={theme:{id:r,name:u,role:l,shop:o.storeFqdn}};n(JSON.stringify(a))}else n(JSON.stringify({message:`The theme '${t.name}' unexpectedly could not be duplicated `,errors:[],requestId:e.requestId}))}var p=P(j(),1);var f=class t extends v{static{this.summary="Duplicates a theme from your theme library."}static{this.usage=["theme duplicate","theme duplicate --theme 10 --name 'New Theme'"]}static{this.descriptionWithMarkdown=`If you want to duplicate your local theme, you need to run \`shopify theme push\` first.
If no theme ID is specified, you're prompted to select the theme that you want to duplicate from the list of themes in your store. You're asked to confirm that you want to duplicate the specified theme.
Prompts and confirmations are not shown when duplicate is run in a CI environment or the \`--force\` flag is used, therefore you must specify a theme ID using the \`--theme\` flag.
You can optionally name the duplicated theme using the \`--name\` flag.
If you use the \`--json\` flag, then theme information is returned in JSON format, which can be used as a machine-readable input for scripts or continuous integration.
Sample JSON output:
\`\`\`json
{
"theme": {
"id": 108267175958,
"name": "A Duplicated Theme",
"role": "unpublished",
"shop": "mystore.myshopify.com"
}
}
\`\`\`
\`\`\`json
{
"message": "The theme 'Summer Edition' could not be duplicated due to errors",
"errors": ["Maximum number of themes reached"],
"requestId": "12345-abcde-67890"
}
\`\`\``}static{this.description=this.descriptionWithoutMarkdown()}static{this.flags={...D,...S,password:c.password,theme:p.Flags.string({char:"t",description:"Theme ID or name of the remote theme.",env:"SHOPIFY_FLAG_THEME_ID"}),name:p.Flags.string({char:"n",description:"Name of the newly duplicated theme.",env:"SHOPIFY_FLAG_NAME"}),store:c.store,environment:c.environment,force:p.Flags.boolean({char:"f",description:"Force the duplicate operation to run without prompts or confirmations.",env:"SHOPIFY_FLAG_FORCE"})}}async run(){let{flags:o}=await this.parse(t),e=q(o),r=await b(e,o.password);await C(r,o.theme,o)}};export{f as default};