UNPKG

@shopify/cli

Version:

A CLI tool to build for the Shopify platform

4 lines (2 loc) • 8.83 kB
import{a as K}from"./chunk-UJVH7FZS.js";import{O as H,va as W,xa as _,ya as Y,z as b}from"./chunk-XONFGLJQ.js";import{b as L}from"./chunk-MHWV5RQV.js";import{a as X,b as Z}from"./chunk-XOTA6JTZ.js";import{a as j}from"./chunk-JUVAGMIH.js";import{A as B,a as k,t as U,w as C,x as T}from"./chunk-6G6TMKXF.js";import{d as z,e as J}from"./chunk-WSDN25F5.js";import{d as E,g as Q}from"./chunk-M56NDIMD.js";import{r as pe}from"./chunk-LDGAHMS7.js";import{Fa as M,Gb as $,Ib as l,Qb as g,Ua as F}from"./chunk-N5PQPIBF.js";import{d as G,f as x,i as V,q as A}from"./chunk-IU2ZQ6TE.js";import{e as ce,g as d}from"./chunk-VPRTJUIN.js";d();var y=ce(pe(),1);var R={path:y.Flags.string({description:"The path where you want to run the command. Defaults to the current working directory.",env:"SHOPIFY_FLAG_PATH",parse:async t=>{let e=x(t);return F(e)?M(e)?e:(T({headline:"The path must be a directory, not a file.",body:[`The provided path is not a directory: ${e}`,`Did you mean: ${V(e)}`]}),process.exit(1)):(T({headline:"A path was explicitly provided but doesn't exist.",body:[`Please check the path and try again: ${e}`]}),process.exit(1))},default:async()=>A(),noCacheDefault:!0}),password:y.Flags.string({description:"Password generated from the Theme Access app or an Admin API token.",env:"SHOPIFY_CLI_THEME_TOKEN"}),store:y.Flags.string({char:"s",description:"Store URL. It can be the store prefix (example) or the full myshopify.com URL (example.myshopify.com, https://example.myshopify.com).",env:"SHOPIFY_FLAG_STORE",parse:async t=>b(t)}),environment:y.Flags.string({char:"e",description:"The environment to apply to the current command.",env:"SHOPIFY_FLAG_ENVIRONMENT",multiple:!0})},ee="Wrap the value in double quotes if you're using wildcards.",Se=t=>({only:y.Flags.string({char:"o",multiple:!0,description:`${t.charAt(0).toUpperCase()+t.slice(1)} only the specified files (Multiple flags allowed). ${ee}`,env:"SHOPIFY_FLAG_ONLY"}),ignore:y.Flags.string({char:"x",multiple:!0,description:`Skip ${t}ing the specified files (Multiple flags allowed). ${ee}`,env:"SHOPIFY_FLAG_IGNORE"})});d();d();import{AsyncLocalStorage as he}from"node:async_hooks";var se=new he,te,oe,re,ne;function c(){return te??=new L({projectName:"shopify-cli-theme-conf"}),te}function O(){return oe??=new L({projectName:"shopify-cli-development-theme-config"}),oe}function N(){return re??=new L({projectName:"shopify-cli-repl-theme-config"}),re}function I(){return ne??=new L({projectName:"shopify-cli-theme-store-password"}),ne}function D(t=c()){return se.getStore()?.store??t.get("themeStore")}function ae(t,e=c()){e.set("themeStore",t)}function Ee(t=c()){return g(l`Getting development theme...`),O().get(u(t))}function xe(t,e=c()){g(l`Setting development theme...`),O().set(u(e),t)}function Ae(t=c()){g(l`Removing development theme...`),O().delete(u(t))}function be(t=c()){return g(l`Getting REPL theme...`),N().get(u(t))}function Pe(t,e=c()){g(l`Setting REPL theme to ${t}...`),N().set(u(e),t)}function _e(t=c()){g(l`Removing REPL theme...`),N().delete(u(t))}function Ce(t=c()){let e=u(t);return g(l`Getting storefront password for shop ${e}...`),I().get(e)}function $e(t,e=c()){let o=u(e);g(l`Setting storefront password for shop ${o}...`),I().set(o,t)}function Re(t=c()){let e=u(t);g(l`Removing storefront password for ${e}...`),I().delete(e)}function u(t=c()){let e=D(t);if(!e)throw new Q("Theme store is not set. This indicates an unexpected issue with the CLI. Please report this to the Shopify CLI team.",["It may be possible to recover by running",{command:"shopify theme list --store <store>"},"(setting the store flag to the store you wish to use) and then running the command again."]);return e}async function ie(t,e){return se.run({store:t},e)}function me(t){let e=t.store??D();if(!e)throw W(new E("A store is required",`Specify the store passing ${l`${$.genericShellCommand(`--${R.store.name}=example.myshopify.com`)}`.value} or set the ${l`${$.genericShellCommand(R.store.env)}`.value} environment variable.`));return ae(e),e}d();d();var le="shopify.theme.toml",je=new Intl.DateTimeFormat(void 0,{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"}),He=["**/.git","**/.vscode","**/.hg","**/.bzr","**/.svn","**/_darcs","**/CVS","**/*.sublime-(project|workspace)","**/.DS_Store","**/.sass-cache","**/Thumbs.db","**/desktop.ini","**/config.yml","**/node_modules/",".prettierrc.json"],We=50;var q=class extends Z{environmentsFilename(){return le}async command(e,o,s=!1,i,r){}async run(e){let o=this.constructor,s=o.multiEnvironmentsFlags,{args:i,flags:r}=await this.parse(o),n="password"in o.flags,h=(Array.isArray(r.environment)?r.environment:[r.environment]).filter(Boolean),p=s!==null&&s.some(a=>Array.isArray(a)?a.includes("store"):a==="store");if(h.length<=1){if(h[0]&&!r.store&&p)throw new E("Please provide a valid environment.");let a=n?await this.createSession(r):void 0,w=this.constructor.name.toLowerCase();if(_(`theme-command:${w}:single-env:authenticated`),r.path&&!F(r.path))throw new E(`Path does not exist: ${r.path}`);try{await this.command(r,a,!1,i)}finally{await this.logAnalyticsData(a)}return}if(s===null){C({body:"This command does not support multiple environments."});return}let{flags:m}=await this.parse(X(o),this.argv);if("path"in m){this.errorOnGlobalPath();return}let S=await this.loadEnvironments(h,r,m),f=await this.validateEnvironments(S,s,n);"force"in o.flags&&!r.force&&!await this.showConfirmation(this.constructor.name,s,f)||await this.runConcurrent(f.valid)}async loadEnvironments(e,o,s){let i=new Map;for(let r of e){let n=await K(r,"shopify.theme.toml",{from:o.path,silent:!0});n?.store&&typeof n.store=="string"&&(n.store=b(n.store)),n?.path&&typeof n.path=="string"&&(n.path=x(n.path)),i.set(r,{flags:{...o,...n,...s,environment:[r]},validationFlags:{...n,...s}})}return i}async validateEnvironments(e,o,s){let i=[],r=[];for(let[n,{flags:h,validationFlags:p}]of e){let m=this.validConfig(p,o,n);if(m!==!0){let S=m.join(", ");r.push({environment:n,reason:`Missing flags: ${S}`});continue}i.push({environment:n,flags:h,requiresAuth:s})}return{valid:i,invalid:r}}async showConfirmation(e,o,s){let n={message:[`Run ${e.toLowerCase()} in the following environments?`],confirmationMessage:"Yes, proceed",cancellationMessage:"Cancel"},h=[...s.valid.map(({environment:p,flags:m})=>{let S=o.map(f=>{let v=Array.isArray(f)?f.find(a=>m[a]):f;if(v==="password")return"password";if(v==="path"&&typeof m.path=="string"){let a=m.path.split(/[/\\]/);if(a.length===1)return`path: ${m.path}`;let w=a[0]===""?`/${a[1]}`:a[0],P=a.at(-1);return`path: ${w}/.../${P}`}return v&&`${v}: ${m[v]}`}).join(", ");return[p,{subdued:S||"No flags required"}]}),...s.invalid.map(({environment:p,reason:m})=>[p,{error:`Skipping | ${m}`}])];return n.infoTable={Environment:h},s.invalid.length>0&&(n.confirmationMessage="Proceed anyway (will skip invalid environments)"),B(n)}async runConcurrent(e){let o=new k,s=e.map(n=>n.flags.store),i=new Set(s),r=s.length===i.size?[e]:this.createSequentialGroups(e);for(let n of r)await U({processes:n.map(({environment:h,flags:p,requiresAuth:m})=>({prefix:h,action:async(S,f,v)=>{try{let a=p.store;await ie(a,async()=>{let w=m?await this.createSession(p):void 0,P=this.constructor.name.toLowerCase();_(`theme-command:${P}:multi-env:authenticated`);try{await this.command(p,w,!0,{},{stdout:S,stderr:f})}finally{await this.logAnalyticsData(w)}})}catch(a){a instanceof Error&&(a.message=`Environment ${h} failed: ${a.message}`,T({body:[a.message]}))}}})),abortSignal:o.signal,showTimestamps:!0,renderOptions:{stdout:process.stderr}})}createSequentialGroups(e){let o=[];return e.forEach(s=>{let i=o.find(r=>!r.some(n=>n.flags.store===s.flags.store));i?i.push(s):o.push([s])}),o}async createSession(e){let o=e.store,s=e.password;return await H(me({store:o}),s)}validConfig(e,o,s){let i=o.filter(r=>Array.isArray(r)?!r.some(n=>e[n]):!e[r]).map(r=>Array.isArray(r)?r.join(" or "):r);return i.length>0?(C({body:[`Missing required flags in environment configuration${s?` for ${s}`:""}:`,{list:{items:i}}]}),i):!0}errorOnGlobalPath(){let e=G(A(),"shopify.theme.toml"),o=F(e);T({body:["Can't use `--path` flag with multiple environments.",...o?["Configure each environment's theme path in your shopify.theme.toml file instead."]:["Run this command from the directory containing shopify.theme.toml.","No shopify.theme.toml found in current directory."]]})}async logAnalyticsData(e){if(!e)return;let o=Y();await z(()=>({store_fqdn_hash:j(e.storeFqdn),cmd_theme_timings:JSON.stringify(o.timings),cmd_theme_errors:JSON.stringify(o.errors),cmd_theme_retries:JSON.stringify(o.retries),cmd_theme_events:JSON.stringify(o.events)})),await J(()=>({store_fqdn:e.storeFqdn}))}};export{D as a,Ee as b,xe as c,Ae as d,be as e,Pe as f,_e as g,Ce as h,$e as i,Re as j,R as k,Se as l,me as m,je as n,He as o,We as p,q};