@shopify/cli
Version:
A CLI tool to build for the Shopify platform
6 lines (4 loc) • 12 kB
JavaScript
import{a as ee,b as te}from"../../../../chunk-C2IK2HY3.js";import{a as Z}from"../../../../chunk-JCL2RRU6.js";import{a as W}from"../../../../chunk-AGNMOFJS.js";import{Ba as Q,D as B,F as K,c as J,d as X,l as w}from"../../../../chunk-54CAKCYR.js";import{b as z,d as H}from"../../../../chunk-7ESSIN27.js";import{b as v}from"../../../../chunk-6WL4GA2M.js";import{c as q}from"../../../../chunk-TYZXGSHO.js";import{j as Y}from"../../../../chunk-GZS44BUW.js";import"../../../../chunk-K2WUCOQJ.js";import"../../../../chunk-7QIOUDCX.js";import"../../../../chunk-7MUKLZOL.js";import"../../../../chunk-VBUZWRUL.js";import"../../../../chunk-DCPBRWVC.js";import"../../../../chunk-KR6QDE7D.js";import"../../../../chunk-UXVZ2P63.js";import"../../../../chunk-QSTEVZFQ.js";import"../../../../chunk-5Y7GIF2W.js";import"../../../../chunk-EKXY5COY.js";import"../../../../chunk-4DCQNGUV.js";import"../../../../chunk-QBSKKQBN.js";import"../../../../chunk-FQWB2F75.js";import"../../../../chunk-XONFGLJQ.js";import"../../../../chunk-4LNCYIS3.js";import{C as L,p as T,x as j,y as P}from"../../../../chunk-L2MGAEV3.js";import"../../../../chunk-PRKBO42R.js";import"../../../../chunk-ZSBA6VIC.js";import"../../../../chunk-F2QU6WWX.js";import"../../../../chunk-XULPJ6UG.js";import{b as $}from"../../../../chunk-XR6GMMEU.js";import"../../../../chunk-3TNEIDOD.js";import"../../../../chunk-MHWV5RQV.js";import"../../../../chunk-XOTA6JTZ.js";import"../../../../chunk-MOA33ZFO.js";import{d as h}from"../../../../chunk-JUVAGMIH.js";import{B as D,D as F,F as V,v as M,z as R}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 f}from"../../../../chunk-M56NDIMD.js";import"../../../../chunk-PD5ZHJWI.js";import{r as ue}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{Hb as U,Oa as C,Ta as S,Ua as b,Wa as _,Y as u,ka as g,wa as G,ya as E}from"../../../../chunk-N5PQPIBF.js";import"../../../../chunk-CERXUPGC.js";import"../../../../chunk-T4M5CWAO.js";import"../../../../chunk-PRVQAHWI.js";import{e as N}from"../../../../chunk-YTNDFQJT.js";import"../../../../chunk-ULQG3XQS.js";import{d,n as I}from"../../../../chunk-IU2ZQ6TE.js";import"../../../../chunk-PIBY5DDZ.js";import{e as de,g as c}from"../../../../chunk-VPRTJUIN.js";c();c();c();async function ne(e,t,r){let{templates:i,groupOrder:n}=await e.templateSpecifications(t);return{templates:i.filter(a=>r.includes(a.identifier)||r.includes(a.type)),groupOrder:n}}c();function O(e){switch(e){case"vanilla-js":case"preact":case"react":case"typescript":case"typescript-react":return"javascript";case"rust":case"wasm":return e;case void 0:case"liquid":case"config-only":return}}async function ie(e){let t=e.extensionChoices.name,r=e.extensionChoices.flavor,i=e.extensionTemplate.supportedFlavors.find(s=>s.value===r),n=await te({app:e.app,name:t}),o=e.cloneUrl??e.extensionTemplate.url,a={directory:n,url:o,app:e.app,project:e.project,type:e.extensionTemplate.type,name:t,extensionFlavor:i,onGetTemplateRepository:e.onGetTemplateRepository??(async(s,p)=>{await q({repoUrl:s,destination:p,shallow:!0})})};return await fe(a),{directory:I(n),extensionTemplate:e.extensionTemplate}}async function fe(e){try{switch(e.type){case"theme":await xe(e);break;case"function":await ye(e);break;default:await ge(e);break}let t=d(e.directory,z.lockFile);await E(t)}catch(t){throw await E(e.directory),t}}async function xe({directory:e,url:t,type:r,name:i,extensionFlavor:n,onGetTemplateRepository:o}){return g(async a=>{let s=await A(t,n,a,o);await v(s,e,{name:i,type:r,uid:h(u(i))})})}async function ye({directory:e,url:t,app:r,project:i,name:n,extensionFlavor:o,onGetTemplateRepository:a}){let s=O(o?.value),p=[];p.push({title:"Generating function extension",task:async()=>{if(await g(async l=>{let m=await A(t,o,l,a);await v(m,e,{name:n,handle:u(n),flavor:o?.value,uid:h(u(n))})}),s==="javascript"){let l=re(o?.value??"rust");await oe(e,l,"!(*.graphql)")}}}),s==="javascript"&&p.push({title:"Installing additional dependencies",task:async()=>{i.usesWorkspaces&&await T({packageManager:i.packageManager,directory:i.directory});let l=Ee(s);await P(l,{packageManager:i.packageManager,type:"prod",directory:i.usesWorkspaces?e:i.directory})}}),s==="javascript"&&p.push({title:"Building GraphQL types",task:async()=>{await X({directory:e,isJavaScript:!0},{stdout:process.stdout,stderr:process.stderr,app:r})}}),await F(p)}async function ge({directory:e,url:t,app:r,project:i,name:n,extensionFlavor:o,onGetTemplateRepository:a}){let s=O(o?.value),p=[{title:"Generating extension",task:async()=>{let l=re(o?.value??"vanilla-js");await g(async m=>{let x=await A(t,o,m,a);await v(x,e,{srcFileExtension:l,name:n,handle:u(n),flavor:o?.value??"",uid:h(u(n))})}),s==="javascript"&&await oe(e,l)}},{title:"Installing dependencies",task:async()=>{let l=i.packageManager;if(i.usesWorkspaces)O(o?.value)==="javascript"&&await T({packageManager:l,directory:i.directory});else{await he(i.directory,o?.value);let m=d(e,"package.json"),x=await ve(m);await P(x,{packageManager:l,type:"prod",directory:i.directory}),await E(m)}}}];p.push({title:"Update shared type definition",task:async()=>{await K(r)}}),await F(p)}function re(e){return{"vanilla-js":"js",preact:"jsx",react:"jsx",typescript:"ts","typescript-react":"tsx",rust:"rs",wasm:"wasm",liquid:"liquid","config-only":""}[e]??"js"}function Ee(e){let t=[];return e==="javascript"&&t.push({name:"@shopify/shopify_function",version:`~${J}.0.0`}),t}async function oe(e,t,r="*"){let i=await _(d(e,"src",r)),n=[];for(let o of i)n.push(C(o,`${o}.${t}`));await Promise.all(n)}async function he(e,t){t==="typescript-react"&&await L(e,{"@types/react":H.reactTypes})}async function ve(e){if(!await S(e))return[];let t=await j(e);return Object.entries(t?.dependencies??{}).map(([r,i])=>({name:r,version:i}))}async function A(e,t,r,i){let n=d(r,"download");return await G(n),await i(e,n),ee(t,n)}c();function we(e,t=[]){let r=[...e.map(n=>({label:n.name,value:n.identifier,group:n.group||"Other",sortPriority:n.sortPriority??Number.MAX_SAFE_INTEGER})),...t.map(n=>({label:`${n.name} (limit reached)`,value:n.identifier,group:n.group||"Other",disabled:!0,sortPriority:n.sortPriority??Number.MAX_SAFE_INTEGER}))],i=(n,o)=>n.sortPriority===o.sortPriority?n.label.localeCompare(o.label):n.sortPriority-o.sortPriority;return r.sort(i)}var Te=async e=>{let t=e.extensionTemplates,r=e.templateType,i=e.extensionFlavor;if(!r){if(i&&(t=t.filter(p=>p.supportedFlavors.map(l=>l.value).includes(i))),t.length===0)throw new f("You have reached the limit for the number of extensions you can create.");r=await D({message:"Type of extension?",choices:we(t,e.unavailableExtensions),groupOrder:e.groupOrder})}let n=t.find(p=>p.identifier===r),o=e.name||await ae(e.directory,n.defaultName),a=e.extensionFlavor??await Pe(n);return{extensionTemplate:n,extensionContent:{name:o,flavor:a}}};async function ae(e,t,r=1){let i=t.includes(" ")?" ":"-",n=r<=1?t:`${t}${i}${r}`,o=d(e,u(n));return b(o)?ae(e,t,r+1):V({message:"Name your extension:",defaultValue:n})}async function Pe(e){if(e.supportedFlavors.length!==0)return e.supportedFlavors.length===1&&e.supportedFlavors[0]?e.supportedFlavors[0].value:R({message:"What would you like to work in?",choices:e.supportedFlavors.map(t=>({label:t.name,value:t.value})),defaultValue:"react"})}var se=Te;async function Fe(e){let{app:t,developerPlatformClient:r,remoteApp:i,specifications:n,template:o}=e,a=n.map(me=>me.identifier),{templates:s,groupOrder:p}=await ne(r,i,a),l=await Oe(s,p,n,t,e),m=await se(l);await ke(m,o);let x=Ie(m,t,e,r),ce=await ie(x);Ge(ce,e.project.packageManager)}async function Oe(e,t,r,i,n){let o=await be(n.template,i,e,r);Ce(o,n.flavor);let{validTemplates:a,templatesOverlimit:s}=Ae(e,r,i);return{templateType:o?.identifier,name:n.name,extensionFlavor:n.flavor,directory:d(n.directory,"extensions"),app:i,extensionTemplates:a??[],unavailableExtensions:s??[],reset:n.reset,groupOrder:t}}function Ae(e,t,r){return Y(e,n=>!pe(r,t,n)?"validTemplates":"templatesOverlimit")}function pe(e,t,r){let i=r.type,n=t.find(a=>a.identifier===i||a.externalIdentifier===i);return e.extensionsForType({identifier:i,externalIdentifier:i}).length>=(n?.registrationLimit??1)}async function ke(e,t){let{extensionContent:r}=e;return w.addPublicMetadata(()=>({cmd_scaffold_template_flavor:r.flavor,cmd_scaffold_type:e.extensionTemplate.identifier,cmd_scaffold_used_prompts_for_type:!t}))}function Ie(e,t,r,i){return{app:t,project:r.project,cloneUrl:r.cloneUrl,extensionChoices:e.extensionContent,extensionTemplate:e.extensionTemplate,developerPlatformClient:i}}function Ge(e,t){let r=Se(e.extensionTemplate,e.directory,t);M(r)}function Ce(e,t){if(!t||!e)return;let r=e.supportedFlavors.map(i=>i.value);if(!r.includes(t))throw new f("Invalid template for extension type",`Expected template to be one of the following: ${r.join(", ")}.`)}function Se(e,t,r){let i={headline:["Your extension was created in",{filePath:t},{char:"."}],nextSteps:[],reference:[]};return e.type!=="function"&&i.nextSteps.push(["To preview this extension along with the rest of the project, run",{command:U(r,"shopify app dev")}]),e.supportLinks[0]&&i.reference.push(["For more details, see the",{link:{label:"docs",url:e.supportLinks[0]}}]),i}async function be(e,t,r,i){if(!e)return;let n=r.find(o=>o.identifier===e);if(!n){let o=await N(),a=r.map(p=>p.identifier),s=o?"You might need to enable some flags on your Organization or App":void 0;throw new f(`Unknown extension type: ${e}.
The following extension types are supported: ${a.join(", ")}`,s)}if(pe(t,i,n))throw new f(`Invalid extension type: ${e}`,`You have reached the limit of extension(s) of type ${n.type} per app`);return n}var le=Fe;var y=de(ue(),1);var k=class e extends Z{static{this.summary="Generate a new app Extension."}static{this.descriptionWithMarkdown=`Generates a new [app extension](https://shopify.dev/docs/apps/build/app-extensions). For a list of app extensions that you can generate using this command, refer to [Supported extensions](https://shopify.dev/docs/apps/build/app-extensions/list-of-app-extensions).
Each new app extension is created in a folder under \`extensions/\`. To learn more about the extensions file structure, refer to [App structure](https://shopify.dev/docs/apps/build/cli-for-apps/app-structure) and the documentation for your extension.
`}static{this.description=this.descriptionWithoutMarkdown()}static{this.flags={...$,...W,template:y.Flags.string({char:"t",hidden:!1,description:"Extension template",env:"SHOPIFY_FLAG_EXTENSION_TEMPLATE"}),name:y.Flags.string({char:"n",hidden:!1,description:"name of your Extension",env:"SHOPIFY_FLAG_NAME"}),"clone-url":y.Flags.string({hidden:!0,char:"u",description:"The Git URL to clone the function extensions templates from. Defaults to: https://github.com/Shopify/function-examples",env:"SHOPIFY_FLAG_CLONE_URL"}),flavor:y.Flags.string({hidden:!1,description:"Choose a starting template for your extension, where applicable",options:["vanilla-js","react","typescript","typescript-react","wasm","rust"],env:"SHOPIFY_FLAG_FLAVOR"})}}async run(){let{flags:t}=await this.parse(e);await w.addPublicMetadata(()=>({cmd_scaffold_required_auth:!0,cmd_scaffold_template_custom:t["clone-url"]!==void 0,cmd_scaffold_type_owner:"@shopify/app"})),await B(t.path);let{app:r,project:i,specifications:n,remoteApp:o,developerPlatformClient:a}=await Q({directory:t.path,clientId:t["client-id"],forceRelink:t.reset,userProvidedConfigName:t.config});return await le({directory:t.path,reset:t.reset,name:t.name,cloneUrl:t["clone-url"],template:t.template,flavor:t.flavor,app:r,project:i,specifications:n,remoteApp:o,developerPlatformClient:a}),{app:r}}};export{k as default};