import{p as S,v as E}from"./chunk-PTIJDS6I.js";import{$ as re,aa as G}from"./chunk-QPJQ67GU.js";import{r as C}from"./chunk-VRRDIXFQ.js";import{b as $}from"./chunk-Q6LCSRIW.js";import{u as w,v as N}from"./chunk-E24W34C4.js";import{$a as A,Lb as l,Mb as P,N as x,Nb as T,Pb as L,Ta as b,na as R,ua as _}from"./chunk-EYDNSYYE.js";import{d as F,p as I}from"./chunk-773TIA5M.js";import{r as oe}from"./chunk-T6CC5WUU.js";import{e as O,g as k}from"./chunk-VKWPEFWQ.js";k();k();var i=O(G(),1),y=O(re(),1);function ie(t){switch(t){case"error":return i.Severity.ERROR;case"suggestion":case"warning":return i.Severity.WARNING;case"style":case"info":return i.Severity.INFO;case"crash":return}}function j(t){switch(t){case i.Severity.ERROR:return"error";case i.Severity.WARNING:return"warning";case i.Severity.INFO:return"info"}}function se(t,e,n){let o=i.path.fsPath(t),c=R(o).toString().split(`
`).slice(e,n+1),a=c.length===1;return c.map((u,h)=>{let f=e+h+1,d=a?u.trim():u;return`${f}  ${d}`}).join(`
`)}function ce(t){switch(t){case i.Severity.ERROR:return{error:`
[error]:`};case i.Severity.WARNING:return{warn:`
[warning]:`};case i.Severity.INFO:return{info:`
[info]:`}}}function ae(t){return t.map((n,o)=>{let{message:r,uri:s,start:c,end:a,check:u,severity:h}=n,f=se(s,c.line,a.line),d=o===t.length-1?"":`

`;return[ce(h),{bold:u},{subdued:`
${r}`},`

${f}`,d]}).flat()}var ue=(t,e)=>t.severity-e.severity;function Y(t){let e=t.reduce((n,o)=>{let{uri:r}=o,s=i.path.fsPath(r);return n[s]??(n[s]=[]),n[s].push(o),n},{});return Object.keys(e).reduce((n,o)=>(n[o]=e[o].sort(ue),n),{})}function U(t){return t.reduce((e,n)=>(!Object.prototype.hasOwnProperty.call(e,n.severity)&&(e[n.severity]=0),e[n.severity]++,e),{})}function W(t,e,n){let o=[`${n.length} files inspected`];if(t.length===0)o.push("with no offenses found.");else{o.push(`with ${t.length} total offenses found across ${Object.keys(e).length} files.`);let r=U(t);r[i.Severity.ERROR]&&o.push(`
${r[i.Severity.ERROR]} errors.`),r[i.Severity.WARNING]&&o.push(`
${r[i.Severity.WARNING]} warnings.`),r[i.Severity.INFO]&&o.push(`
${r[i.Severity.INFO]} info issues.`)}return o}function q(t,e,n){Object.keys(t).sort().forEach(r=>{let s=r.replace(e,"").slice(1);w({headline:n?`[${n}] ${s}`:s,body:ae(t[r])})})}function H(t,e){return Object.entries(t).map(([n,o])=>{let r=o.map(c=>({check:c.check,severity:j(c.severity),start_row:c.start.line,start_column:c.start.character,end_row:c.end.line,end_column:c.end.character,message:c.message})),s=U(o);return{environment:e,path:n,offenses:r,errorCount:s[i.Severity.ERROR]??0,warningCount:s[i.Severity.WARNING]??0,infoCount:s[i.Severity.INFO]??0}})}function B(t,e){e||process.exit(0);let n=ie(e),o=n!==void 0&&t.some(r=>r.severity<=n);process.exit(o?1:0)}function fe(t){return t.split(`
`).map(e=>`# ${e}`).join(`
`)}async function D(t){let e=".theme-check.yml",n=F(t,e);if(await b(n)){P(`${e} already exists at ${t}`);return}let{settings:o}=await(0,i.loadConfig)(void 0,t),r=fe(y.default.stringify(o)),s=y.default.stringify({extends:"theme-check:recommended",ignore:["node_modules/**"]});await _(n,`${s}${r}`),T(`Created ${e} at ${t}`)}var de=async(t,e)=>{let n=(0,i.applyFixToString)(t.source,e),o=i.path.fsPath(t.uri);await _(o,n)};async function M(t,e){await(0,i.autofix)(t,e,de)}async function J(t,e,n){let{ignore:o,settings:r,rootUri:s}=await(0,i.loadConfig)(e,t),c={extends:[],ignore:x(o??[]),rootUri:s,...r},a=n?{[n]:c}:c;l(y.default.stringify(a))}async function V(t,e,n){let{settings:o,ignore:r,checks:s}=await(0,i.loadConfig)(e,t),c=x(r??[]),u=Object.keys(o).reduce((f,d)=>{let{severity:Q,enabled:X,...Z}=o[d];if(!X)return f;let ee=j(Q??i.Severity.INFO),v=s.find(ne=>ne.meta.code===d),te=v&&v.meta?{description:v.meta.docs.description,doc:v.meta.docs.url}:{};return f[d]={severity:ee,...te,ignored_patterns:`[${c.join(", ")}]`,...Z},f},{}),h=n?{[n]:u}:u;l(y.default.stringify(h))}function z(t){return"_handle"in t&&typeof t._handle=="object"&&t._handle!==null&&typeof t._handle.setBlocking=="function"}var m=O(oe(),1);var g=O(G(),1);var K,p=class extends E{async command(e,n,o){let r=e.path,s=e.environment?.[0],a=e.config?.startsWith(":")&&g.LegacyIdentifiers.has(e.config.slice(1))?g.LegacyIdentifiers.get(e.config.slice(1)):e.config;if(e.init){await D(r);return}if(e.version){let f=await A(F("node_modules","@shopify","theme-check-node","package.json"),{type:"file",cwd:I(import.meta.url)}),d="unknown";f&&(d=await C(f)??"unknown"),l(d);return}if(e.print){await J(r,a,s);return}if(e.list){await V(r,a,s);return}let{offenses:u,theme:h}=await me(r,e.output,a,s);if(e["auto-correct"]&&await M(h,u),!o)return B(u,e["fail-level"])}};K=p;p.summary="Validate the theme.";p.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)";p.description=K.descriptionWithoutMarkdown();p.flags={...$,path:S.path,"auto-correct":m.Flags.boolean({char:"a",required:!1,description:"Automatically fix offenses",env:"SHOPIFY_FLAG_AUTO_CORRECT"}),config:m.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":m.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:m.Flags.boolean({required:!1,description:"Generate a .theme-check.yml file",env:"SHOPIFY_FLAG_INIT"}),list:m.Flags.boolean({required:!1,description:"List enabled checks",env:"SHOPIFY_FLAG_LIST"}),output:m.Flags.string({char:"o",required:!1,description:"The output format to use",env:"SHOPIFY_FLAG_OUTPUT",options:["text","json"],default:"text"}),print:m.Flags.boolean({required:!1,description:"Output active config to STDOUT",env:"SHOPIFY_FLAG_PRINT"}),version:m.Flags.boolean({char:"v",required:!1,description:"Print Theme Check version",env:"SHOPIFY_FLAG_VERSION"}),environment:S.environment};p.multiEnvironmentsFlags=["path"];var Ae=p;async function me(t,e,n,o){let{offenses:r,theme:s}=await(0,g.themeCheckRun)(t,n,a=>{process.env.SHOPIFY_TMP_FLAG_DEBUG&&L(a)}),c=Y(r);if(e==="text"&&(q(c,t,o),(r.length?w:N)({headline:o?`[${o}] Theme Check Summary.`:"Theme Check Summary.",body:W(r,c,s)})),e==="json"){let a=process.stdout;z(a)&&a._handle.setBlocking(!0),l(JSON.stringify(H(c,o)))}return{offenses:r,theme:s}}export{Ae as a,me as b};
