@shopify/cli
Version:
A CLI tool to build for the Shopify platform
20 lines (17 loc) • 6.83 kB
JavaScript
import{k as w,q as $}from"./chunk-XITQULK4.js";import{$ as ne,aa as E}from"./chunk-UXVZ2P63.js";import{r as C}from"./chunk-L2MGAEV3.js";import{b as P}from"./chunk-XR6GMMEU.js";import{u as S,v as T}from"./chunk-6G6TMKXF.js";import{r as te}from"./chunk-LDGAHMS7.js";import{$a as I,Mb as p,Nb as A,Ob as N,Qb as L,Ta as R,na as _,ua as F}from"./chunk-N5PQPIBF.js";import{d as k,p as x}from"./chunk-IU2ZQ6TE.js";import{e as O,g as v}from"./chunk-VPRTJUIN.js";v();v();var s=O(E(),1),h=O(ne(),1);function re(t){switch(t){case"error":return s.Severity.ERROR;case"suggestion":case"warning":return s.Severity.WARNING;case"style":case"info":return s.Severity.INFO;case"crash":return}}function G(t){switch(t){case s.Severity.ERROR:return"error";case s.Severity.WARNING:return"warning";case s.Severity.INFO:return"info"}}function ie(t,e,r){let n=s.path.fsPath(t),a=_(n).toString().split(`
`).slice(e,r+1),c=a.length===1;return a.map((f,m)=>{let u=e+m+1,d=c?f.trim():f;return`${u} ${d}`}).join(`
`)}function se(t){switch(t){case s.Severity.ERROR:return{error:`
[error]:`};case s.Severity.WARNING:return{warn:`
[warning]:`};case s.Severity.INFO:return{info:`
[info]:`}}}function oe(t){return t.map((r,n)=>{let{message:i,uri:o,start:a,end:c,check:f,severity:m}=r,u=ie(o,a.line,c.line),d=n===t.length-1?"":`
`;return[se(m),{bold:f},{subdued:`
${i}`},`
${u}`,d]}).flat()}var ae=(t,e)=>t.severity-e.severity;function j(t){let e=t.reduce((r,n)=>{let{uri:i}=n,o=s.path.fsPath(i);return r[o]??=[],r[o].push(n),r},{});return Object.keys(e).reduce((r,n)=>(r[n]=e[n].sort(ae),r),{})}function W(t){return t.reduce((e,r)=>(!Object.prototype.hasOwnProperty.call(e,r.severity)&&(e[r.severity]=0),e[r.severity]++,e),{})}function H(t,e,r){let n=[`${r.length} files inspected`];if(t.length===0)n.push("with no offenses found.");else{n.push(`with ${t.length} total offenses found across ${Object.keys(e).length} files.`);let i=W(t);i[s.Severity.ERROR]&&n.push(`
${i[s.Severity.ERROR]} errors.`),i[s.Severity.WARNING]&&n.push(`
${i[s.Severity.WARNING]} warnings.`),i[s.Severity.INFO]&&n.push(`
${i[s.Severity.INFO]} info issues.`)}return n}function M(t,e,r){Object.keys(t).sort().forEach(i=>{let o=i.replace(e,"").slice(1);S({headline:r?`[${r}] ${o}`:o,body:oe(t[i])})})}function Y(t,e){return Object.entries(t).map(([r,n])=>{let i=n.map(a=>({check:a.check,severity:G(a.severity),start_row:a.start.line,start_column:a.start.character,end_row:a.end.line,end_column:a.end.character,message:a.message})),o=W(n);return{environment:e,path:r,offenses:i,errorCount:o[s.Severity.ERROR]??0,warningCount:o[s.Severity.WARNING]??0,infoCount:o[s.Severity.INFO]??0}})}function q(t,e){e||process.exit(0);let r=re(e),n=r!==void 0&&t.some(i=>i.severity<=r);process.exit(n?1:0)}function ce(t){return t.split(`
`).map(e=>`# ${e}`).join(`
`)}async function U(t){let e=".theme-check.yml",r=k(t,e);if(await R(r)){A(`${e} already exists at ${t}`);return}let{settings:n}=await(0,s.loadConfig)(void 0,t),i=ce(h.default.stringify(n)),o=h.default.stringify({extends:"theme-check:recommended",ignore:["node_modules/**"]});await F(r,`${o}${i}`),N(`Created ${e} at ${t}`)}var fe=async(t,e)=>{let r=(0,s.applyFixToString)(t.source,e),n=s.path.fsPath(t.uri);await F(n,r)};async function B(t,e){await(0,s.autofix)(t,e,fe)}async function J(t,e,r){let{ignore:n,settings:i,rootUri:o}=await(0,s.loadConfig)(e,t),a={extends:[],ignore:[...new Set(n)],rootUri:o,...i},c=r?{[r]:a}:a;p(h.default.stringify(c))}async function D(t,e,r){let{settings:n,ignore:i,checks:o}=await(0,s.loadConfig)(e,t),a=[...new Set(i)],f=Object.keys(n).reduce((u,d)=>{let{severity:z,enabled:K,...Q}=n[d];if(!K)return u;let X=G(z??s.Severity.INFO),y=o.find(ee=>ee.meta.code===d),Z=y&&y.meta?{description:y.meta.docs.description,doc:y.meta.docs.url}:{};return u[d]={severity:X,...Z,ignored_patterns:`[${a.join(", ")}]`,...Q},u},{}),m=r?{[r]:f}:f;p(h.default.stringify(m))}function V(t){return"_handle"in t&&typeof t._handle=="object"&&t._handle!==null&&typeof t._handle.setBlocking=="function"}var l=O(te(),1);var g=O(E(),1);var b=class extends ${static{this.summary="Validate the theme."}static{this.descriptionWithMarkdown="Calls and runs [Theme Check](https://shopify.dev/docs/themes/tools/theme-check) to analyze your theme code for errors and to ensure that it follows theme and Liquid best practices. [Learn more about the checks that Theme Check runs.](https://shopify.dev/docs/themes/tools/theme-check/checks)"}static{this.description=this.descriptionWithoutMarkdown()}static{this.flags={...P,path:w.path,"auto-correct":l.Flags.boolean({char:"a",required:!1,description:"Automatically fix offenses",env:"SHOPIFY_FLAG_AUTO_CORRECT"}),config:l.Flags.string({char:"C",required:!1,description:`Use the config provided, overriding .theme-check.yml if present
Supports all theme-check: config values, e.g., theme-check:theme-app-extension,
theme-check:recommended, theme-check:all
For backwards compatibility, :theme_app_extension is also supported `,env:"SHOPIFY_FLAG_CONFIG"}),"fail-level":l.Flags.string({required:!1,description:"Minimum severity for exit with error code",env:"SHOPIFY_FLAG_FAIL_LEVEL",options:["crash","error","suggestion","style","warning","info"],default:"error"}),init:l.Flags.boolean({required:!1,description:"Generate a .theme-check.yml file",env:"SHOPIFY_FLAG_INIT"}),list:l.Flags.boolean({required:!1,description:"List enabled checks",env:"SHOPIFY_FLAG_LIST"}),output:l.Flags.string({char:"o",required:!1,description:"The output format to use",env:"SHOPIFY_FLAG_OUTPUT",options:["text","json"],default:"text"}),print:l.Flags.boolean({required:!1,description:"Output active config to STDOUT",env:"SHOPIFY_FLAG_PRINT"}),version:l.Flags.boolean({char:"v",required:!1,description:"Print Theme Check version",env:"SHOPIFY_FLAG_VERSION"}),environment:w.environment}}static{this.multiEnvironmentsFlags=["path"]}async command(e,r,n){let i=e.path,o=e.environment?.[0],c=e.config?.startsWith(":")&&g.LegacyIdentifiers.has(e.config.slice(1))?g.LegacyIdentifiers.get(e.config.slice(1)):e.config;if(e.init){await U(i);return}if(e.version){let u=await I(k("node_modules","@shopify","theme-check-node","package.json"),{type:"file",cwd:x(import.meta.url)}),d="unknown";u&&(d=await C(u)??"unknown"),p(d);return}if(e.print){await J(i,c,o);return}if(e.list){await D(i,c,o);return}let{offenses:f,theme:m}=await ue(i,e.output,c,o);if(e["auto-correct"]&&await B(m,f),!n)return q(f,e["fail-level"])}};async function ue(t,e,r,n){let{offenses:i,theme:o}=await(0,g.themeCheckRun)(t,r,c=>{process.env.SHOPIFY_TMP_FLAG_DEBUG&&L(c)}),a=j(i);if(e==="text"&&(M(a,t,n),(i.length?S:T)({headline:n?`[${n}] Theme Check Summary.`:"Theme Check Summary.",body:H(i,a,o)})),e==="json"){let c=process.stdout;V(c)&&c._handle.setBlocking(!0),p(JSON.stringify(Y(a,n)))}return{offenses:i,theme:o}}export{b as a,ue as b};