hghcn 3.6.21 → 3.6.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {b,a as a$1}from'./chunk-2NUTTJQY.js';import {a,J,v,M,S,C,p,Q as Q$1,K,q,r,I,x,c as c$1,V,D as D$1,F as F$1,ca,H,da,$,Z,aa,E,G,L,ea,b as b$1,ba,s,X,w,o as o$1,O as O$1,i,P,y,u,N,t,z as z$2,B,A}from'./chunk-XYXOKYQL.js';export{$ as fetchTree,aa as getItemTargetPath,da as getPreset,ca as getPresets,U as getRegistriesConfig,ba as getRegistriesIndex,R as getRegistry,Z as getRegistryBaseColor,Y as getRegistryBaseColors,X as getRegistryIcons,S as getRegistryItems,W as getRegistryStyles,V as getShadcnRegistryIndex,T as resolveRegistryItems,_ as resolveTree}from'./chunk-XYXOKYQL.js';import {c,o,n}from'./chunk-WKG3W635.js';import'./chunk-PMFK2ZSQ.js';import'./chunk-BFNVF2P5.js';import*as D from'path';import D__default,{join}from'path';import {execa}from'execa';import Q from'fs-extra';import Ce from'prompts';import We,{z as z$1}from'zod';import {existsSync,promises}from'fs';import {Command}from'commander';import Rr from'deepmerge';import x$1 from'postcss';import jr from'postcss/lib/at-rule';import {Project,ScriptKind,SyntaxKind,VariableDeclarationKind}from'ts-morph';import*as _ from'fs/promises';import _e from'dedent';import zt from'open';import {diffLines}from'diff';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import {randomBytes}from'crypto';import {tmpdir}from'os';import Ji from'fast-glob';var yt={next:"next","next-monorepo":"next-monorepo",vite:"vite",start:"start"};async function T(t=process.cwd()){try{let{config:e}=await import('@dotenvx/dotenvx'),r=[".env.local",".env.development.local",".env.development",".env"];for(let i of r){let n=join(t,i);existsSync(n)&&e({path:n,overload:!1,quiet:!0});}}catch(e){C.warn("Failed to load env files:",e);}}var Fe=".bak";function wt(t){if(!Q.existsSync(t))return null;let e=`${t}${Fe}`;try{return Q.renameSync(t,e),e}catch(r){return console.error(`Failed to create backup of ${t}: ${r}`),null}}function bt(t){let e=`${t}${Fe}`;if(!Q.existsSync(e))return false;try{return Q.renameSync(e,t),!0}catch(r){return console.error(`Warning: Could not restore backup file ${e}: ${r}`),false}}function Oe(t){let e=`${t}${Fe}`;if(!Q.existsSync(e))return false;try{return Q.unlinkSync(e),!0}catch{return false}}async function xt(t,e){let r=new Set,i$1=new Set,n=[...t];for(;n.length>0;){let o=n.shift();if(i$1.has(o))continue;i$1.add(o);let{registry:a}=o$1(o);a&&!b$1[a]&&r.add(a);try{let[s]=await O$1([o],e,{useCache:!0});if(s?.registryDependencies)for(let c of s.registryDependencies){let{registry:m}=o$1(c);m&&!b$1[m]&&r.add(m),i$1.has(c)||n.push(c);}}catch(s){if(s instanceof i){let{registry:c}=o$1(o);c&&!b$1[c]&&r.add(c);continue}continue}}return Array.from(r)}async function F(t,e,r={}){r={silent:false,writeFile:true,...r};let n=(await xt(t,e)).filter(m=>!e.registries?.[m]&&!Object.keys(b$1).includes(m));if(n.length===0)return {config:e,newRegistries:[]};let o=await ba({useCache:process.env.NODE_ENV!=="development"});if(!o)return {config:e,newRegistries:[]};let a={};for(let m of n)o[m]&&(a[m]=o[m]);if(Object.keys(a).length===0)return {config:e,newRegistries:[]};let s=Object.fromEntries(Object.entries(e.registries||{}).filter(([m])=>!Object.keys(b$1).includes(m))),c$1={...e,registries:{...s,...a}};if(r.writeFile){let{resolvedPaths:m,...l}=c$1,f=D$1("Updating components.json.",{silent:r.silent}).start(),d=c.parse(l);await Q.writeFile(D__default.resolve(e.resolvedPaths.cwd,"components.json"),JSON.stringify(d,null,2)+`
3
3
  `,"utf-8"),f.succeed();}return {config:c$1,newRegistries:Object.keys(a)}}process.on("exit",t=>{let e=D__default.resolve(process.cwd(),"components.json");return t===0?Oe(e):bt(e)});var Ae=z$1.object({cwd:z$1.string(),name:z$1.string().optional(),components:z$1.array(z$1.string()).optional(),yes:z$1.boolean(),defaults:z$1.boolean(),force:z$1.boolean(),silent:z$1.boolean(),isNewProject:z$1.boolean(),srcDir:z$1.boolean().optional(),cssVariables:z$1.boolean(),template:z$1.string().optional().refine(t=>t?yt[t]:true,{message:"Invalid template. Please use 'next', 'vite', 'start' or 'next-monorepo'."}),baseColor:z$1.string().optional().refine(t=>t?a.find(e=>e.name===t):true,{message:`Invalid base color. Please use '${a.map(t=>t.name).join("', '")}'`}),baseStyle:z$1.boolean(),registryBaseConfig:c.deepPartial().optional()}),St=new Command().name("init").description("initialize your project and install dependencies").argument("[components...]","names, url or local path to component").option("-t, --template <template>","the template to use. (next, start, vite, next-monorepo)").option("-b, --base-color <base-color>","the base color to use. (neutral, gray, zinc, stone, slate)",void 0).option("-y, --yes","skip confirmation prompt.",true).option("-d, --defaults,","use default configuration.",false).option("-f, --force","force overwrite of existing configuration.",false).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",false).option("--src-dir","use the src directory when creating a new project.",false).option("--no-src-dir","do not use the src directory when creating a new project.").option("--css-variables","use css variables for theming.",true).option("--no-css-variables","do not use css variables for theming.").option("--no-base-style","do not install the base shadcn style.").action(async(t,e)=>{try{e.defaults&&(e.template=e.template||"next",e.baseColor=e.baseColor||"neutral");let r=Ae.parse({cwd:D__default.resolve(e.cwd),isNewProject:!1,components:t,...e});if(await T(r.cwd),t.length>0){let i=J(v({resolvedPaths:{cwd:r.cwd}})),n=D__default.resolve(r.cwd,"components.json");if(Q.existsSync(n)){let s=await Q.readJson(n),c$1=c.partial().parse(s),m=v({resolvedPaths:{cwd:r.cwd}});i=J({...c$1,resolvedPaths:{...m.resolvedPaths,cwd:r.cwd}}),wt(n);}let{config:o}=await F(t,i,{silent:!0,writeFile:!1});i=o,M(t[0],i);let[a]=await S([t[0]],{config:i});a?.type==="registry:base"&&(a.config&&(i=J(Rr(i,a.config)),r.registryBaseConfig=a.config),r.baseStyle=a.extends==="none"?!1:r.baseStyle),a?.type==="registry:style"&&(r.baseColor="neutral",r.baseStyle=a.extends==="none"?!1:r.baseStyle);}r.baseStyle||(r.baseColor="neutral"),await ne(r),C.log(`${p.success("Success!")} Project initialization completed.
4
- You may now add components.`),Oe(D__default.resolve(r.cwd,"components.json")),C.break();}catch(r){C.break(),Q$1(r);}finally{K();}});async function ne(t){let e=await q(t.cwd);console.log({config:e});[...t.baseStyle?["index"]:[],...t.components??[]];let i=await r(t.cwd,e);return console.log({fullConfig:i}),i}function Ct(t,e){if(t.includes("\0"))return false;let r;try{r=t;let d="";for(;r!==d&&r.includes("%");)d=r,r=decodeURIComponent(r);}catch{return false}let i=D__default.normalize(r.replace(/\\/g,"/")),n=D__default.normalize(e),o=d=>d.replace(/\[\.\.\..*?\]/g,"").includes("..");if(o(i)||o(r)||o(t))return false;let a=d=>d.replace(/\[\.\.\..*?\]/g,""),s=a(t),c=a(r);if([/\.\.[\/\\]/,/[\/\\]\.\./,/\.\./,/\.\.%/,/\x00/,/[\x01-\x1f]/].some(d=>d.test(s)||d.test(c))||(t.includes("~")||r.includes("~"))&&(t.includes("../")||r.includes("../")))return false;if(/^[a-zA-Z]:[\/\\]/.test(r))return process.platform==="win32"?r.toLowerCase().startsWith(e.toLowerCase()):false;if(D__default.isAbsolute(i))return i.startsWith(n+D__default.sep);let f=D__default.resolve(n,i);return f.startsWith(n+D__default.sep)||f===n}async function It(t,e,r){if(!e.resolvedPaths.tailwindCss||!t||Object.keys(t).length===0)return;r={silent:false,...r};let i=e.resolvedPaths.tailwindCss,n=D__default.relative(e.resolvedPaths.cwd,i),o=D$1(`Updating ${p.info(n)}`,{silent:r.silent}).start(),a=await promises.readFile(i,"utf8"),s=await kr(a,t);await promises.writeFile(i,s,"utf8"),o.succeed();}async function kr(t,e){let r=[Pr(e)],i=await x$1(r).process(t,{from:void 0}),n=i.css,o=i.root;if(o.nodes&&o.nodes.length>0){let a=o.nodes[o.nodes.length-1];a.type==="atrule"&&!a.nodes&&!n.trimEnd().endsWith(";")&&(n=n.trimEnd()+";");}return n=n.replace(/\/\* ---break--- \*\//g,""),n=n.replace(/(\n\s*\n)+/g,`
4
+ You may now add components.`),Oe(D__default.resolve(r.cwd,"components.json")),C.break();}catch(r){C.break(),Q$1(r);}finally{K();}});async function ne(t){console.log({config:e,options:t});let e=await q(t.cwd);[...t.baseStyle?["index"]:[],...t.components??[]];let i=await r(t.cwd,e);return console.log({fullConfig:i}),i}function Ct(t,e){if(t.includes("\0"))return false;let r;try{r=t;let d="";for(;r!==d&&r.includes("%");)d=r,r=decodeURIComponent(r);}catch{return false}let i=D__default.normalize(r.replace(/\\/g,"/")),n=D__default.normalize(e),o=d=>d.replace(/\[\.\.\..*?\]/g,"").includes("..");if(o(i)||o(r)||o(t))return false;let a=d=>d.replace(/\[\.\.\..*?\]/g,""),s=a(t),c=a(r);if([/\.\.[\/\\]/,/[\/\\]\.\./,/\.\./,/\.\.%/,/\x00/,/[\x01-\x1f]/].some(d=>d.test(s)||d.test(c))||(t.includes("~")||r.includes("~"))&&(t.includes("../")||r.includes("../")))return false;if(/^[a-zA-Z]:[\/\\]/.test(r))return process.platform==="win32"?r.toLowerCase().startsWith(e.toLowerCase()):false;if(D__default.isAbsolute(i))return i.startsWith(n+D__default.sep);let f=D__default.resolve(n,i);return f.startsWith(n+D__default.sep)||f===n}async function It(t,e,r){if(!e.resolvedPaths.tailwindCss||!t||Object.keys(t).length===0)return;r={silent:false,...r};let i=e.resolvedPaths.tailwindCss,n=D__default.relative(e.resolvedPaths.cwd,i),o=D$1(`Updating ${p.info(n)}`,{silent:r.silent}).start(),a=await promises.readFile(i,"utf8"),s=await kr(a,t);await promises.writeFile(i,s,"utf8"),o.succeed();}async function kr(t,e){let r=[Pr(e)],i=await x$1(r).process(t,{from:void 0}),n=i.css,o=i.root;if(o.nodes&&o.nodes.length>0){let a=o.nodes[o.nodes.length-1];a.type==="atrule"&&!a.nodes&&!n.trimEnd().endsWith(";")&&(n=n.trimEnd()+";");}return n=n.replace(/\/\* ---break--- \*\//g,""),n=n.replace(/(\n\s*\n)+/g,`
5
5
 
6
6
  `),n=n.trimEnd(),n}function Pr(t){return {postcssPlugin:"update-css",Once(e){for(let[r,i]of Object.entries(t))if(r.startsWith("@")){let n=r.match(/@([a-zA-Z-]+)\s*(.*)/);if(!n)continue;let[,o,a]=n;if(o==="import"){if(!e.nodes?.find(c=>c.type==="atrule"&&c.name==="import"&&c.params===a)){let c=x$1.atRule({name:"import",params:a,raws:{semicolon:true}}),m=e.nodes?.filter(l=>l.type==="atrule"&&l.name==="import");if(m&&m.length>0){let l=m[m.length-1];c.raws.before=`
7
7
  `,e.insertAfter(l,c);}else !e.nodes||e.nodes.length,c.raws.before="",e.prepend(c);}}else if(o==="plugin"){let s=a;a&&!a.startsWith('"')&&!a.startsWith("'")&&(s=`"${a}"`);let c=l=>l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'")?l.slice(1,-1):l;if(!e.nodes?.find(l=>l.type!=="atrule"||l.name!=="plugin"?false:c(l.params)===c(a))){let l=x$1.atRule({name:"plugin",params:s,raws:{semicolon:true,before:`
@@ -41,7 +41,7 @@ Some packages may fail to install due to peer dependency issues in npm (see http
41
41
  `),l=[],f=null,d=null;if(s){let g=await promises.readFile(o,"utf-8"),h=B(g,m);if(l=A(g,m),l.length>0){if(await promises.writeFile(o,h,"utf-8"),f=D__default.relative(n,o),i?.succeed(`Added the following variables to ${p.info(c)}:`),!r.silent)for(let y of l)C.log(` ${p.success("+")} ${y}`);}else i?.stop();}else if(await promises.writeFile(o,m+`
42
42
  `,"utf-8"),d=D__default.relative(n,o),l=Object.keys(t),i?.succeed(`Added the following variables to ${p.info(c)}:`),!r.silent)for(let g of l)C.log(` ${p.success("+")} ${g}`);return !r.silent&&l.length>0&&C.break(),{envVarsAdded:l,envFileUpdated:f,envFileCreated:d}}async function Ot(t,e,r){if(!t?.length)return;let i=await x(e.resolvedPaths.cwd);if(!i||i.framework.name!=="next-app"&&i.framework.name!=="next-pages")return;let n=D$1("Updating fonts.",{silent:r.silent})?.start();try{await ri(t,e,i),n?.succeed("Updating fonts.");}catch(o){throw n?.fail("Failed to update fonts."),o}}async function ri(t,e,r){let i=await ii(e,r);if(!i)return;let n=await promises.readFile(i,"utf-8"),o=await oi(n,t);o!==n&&await promises.writeFile(i,o,"utf-8");}async function ii(t,e){let r=t.resolvedPaths.cwd,i=e.isSrcDir,o=e.isTsx?"tsx":"jsx",a=i?[`src/app/layout.${o}`,`app/layout.${o}`]:[`app/layout.${o}`];for(let s of a){let c=D__default.join(r,s);if(existsSync(c))return c}return null}async function oi(t,e,r){let n=new Project({compilerOptions:{}}).createSourceFile("layout.tsx",t,{scriptKind:ScriptKind.TSX}),o=e.filter(s=>s.font.provider==="google"),a=[];for(let s of o){let c=s.font.import;if(!c)continue;let m=si(c),l=n.getImportDeclaration(g=>g.getModuleSpecifierValue()==="next/font/google"),f=ni(s);l?l.getNamedImports().some(y=>y.getName()===c)||l.addNamedImport(c):n.addImportDeclaration({moduleSpecifier:"next/font/google",namedImports:[c]});let d=ai(n,s.font.variable);if(d)d.setInitializer(`${c}(${f})`),d.getName()!==m&&d.rename(m);else {let g=ci(n);n.insertVariableStatement(g,{declarationKind:VariableDeclarationKind.Const,declarations:[{name:m,initializer:`${c}(${f})`}]}).appendWhitespace(`
43
43
  `);}a.push(m);}return a.length>0&&li(n,a),n.getFullText()}function ni(t){let e={};return t.font.subsets?.length&&(e.subsets=t.font.subsets),t.font.weight?.length&&(e.weight=t.font.weight),e.variable=t.font.variable,JSON.stringify(e).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'")}function si(t){return t.split("_").map((e,r)=>r===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function ai(t,e){let r=t.getVariableStatements();for(let i of r)for(let n of i.getDeclarations()){let o=n.getInitializer();if(!o||o.getKind()!==SyntaxKind.CallExpression)continue;let s=o.getArguments();if(s.length===0)continue;let c=s[0].getText();if(c.includes("variable:")&&c.includes(e))return n}return null}function ci(t){let e=t.getImportDeclarations();return e.length>0?e[e.length-1].getChildIndex()+1:0}function li(t,e){let r=t.getDescendantsOfKind(SyntaxKind.JsxOpeningElement);for(let i of r){if(i.getTagNameNode().getText()!=="html")continue;let o=i.getAttribute("className");if(!o){let m=e.map(l=>`${l}.variable`).join(", ");e.length===1?i.addAttribute({name:"className",initializer:`{${m}}`}):(se(t),i.addAttribute({name:"className",initializer:`{cn(${m})}`}));return}if(o.getKind()!==SyntaxKind.JsxAttribute)return;let a=o.asKindOrThrow(SyntaxKind.JsxAttribute),s=a.getInitializer();if(!s)return;let c=e.map(m=>`${m}.variable`);if(s.getKind()===SyntaxKind.StringLiteral){let m=s.getText().slice(1,-1);se(t),a.setInitializer(`{cn("${m}", ${c.join(", ")})}`);}else if(s.getKind()===SyntaxKind.JsxExpression){let m=s.asKindOrThrow(SyntaxKind.JsxExpression),l=m.getExpression();if(!l)return;let f=l.getText();if(f.startsWith("cn(")){if(c.every(y=>f.includes(y)))continue;let g=pi(f),h=fi(g,c);m.replaceWithText(`{${h}}`);}else if(/^\w+\.variable$/.test(f)){if(c.includes(f))continue;c.length===1?m.replaceWithText(`{${c[0]}}`):(se(t),m.replaceWithText(`{cn(${c.join(", ")})}`));}else if(f.startsWith("`")&&f.endsWith("`")){let d=mi(f);se(t),m.replaceWithText(`{cn(${[...d,...c].join(", ")})}`);}else se(t),m.replaceWithText(`{cn(${f}, ${c.join(", ")})}`);}}}function se(t){if(!t.getImportDeclaration(r=>r.getNamedImports().some(n=>n.getName()==="cn"))){let r=t.getImportDeclaration(i=>i.getModuleSpecifierValue().includes("/lib/utils"));r?r.getNamedImports().some(n=>n.getName()==="cn")||r.addNamedImport("cn"):t.addImportDeclaration({moduleSpecifier:"@/lib/utils",namedImports:["cn"]});}}function mi(t){let e=[],r=[],n=t.slice(1,-1).split(/(\$\{[^}]+\})/);for(let o of n)if(o)if(o.startsWith("${")&&o.endsWith("}")){let a=o.slice(2,-1).trim();a&&r.push(a);}else {let a=o.trim().split(/\s+/).filter(Boolean);for(let s of a)e.push(`"${s}"`);}return [...e,...r]}function pi(t){return t.replace(/,?\s*\w+\.variable/g,"").replace(/cn\(\s*,/,"cn(")}function fi(t,e){let r=e.join(", ");return t.replace(/\)$/,`, ${r})`)}async function ve(t,e,r){r={overwrite:false,silent:false,isNewProject:false,baseStyle:true,...r};let i=await s(e);return i&&i.ui&&i.ui.resolvedPaths.cwd!==e.resolvedPaths.cwd?await gi(t,e,i,{...r,isRemote:t?.length===1&&!!t[0].match(/\/chat\/b\//)}):await ui(t,e,r)}async function ui(t,e,r){if(!r.baseStyle&&!t.length)return;let i=D$1("Checking registry.",{silent:r.silent})?.start(),n=await P(t,J(e));if(!n)return i?.fail(),Q$1(new Error("Failed to fetch components from registry."));try{At(n.files??[],e.resolvedPaths.cwd);}catch(o){return i?.fail(),Q$1(o)}i?.succeed(),await O(n.dependencies,n.devDependencies,e,{silent:r.silent}),await F$1(n.files,e,{overwrite:r.overwrite,silent:r.silent,path:r.path}),n.docs&&C.info(n.docs);}async function gi(t$1,e,r,i){if(!i.baseStyle&&!t$1.length)return;let n=D$1("Checking registry.",{silent:i.silent})?.start(),o=await P(t$1,J(e));if(!o)return n?.fail(),Q$1(new Error("Failed to fetch components from registry."));try{At(o.files??[],e.resolvedPaths.cwd);}catch(y){return n?.fail(),Q$1(y)}n?.succeed();let a=[],s=[],c=[],m=D$1("Installing components.")?.start(),l=r.ui,f=await y(l),d=u(e.resolvedPaths.cwd,l.resolvedPaths.ui);if(o.tailwind?.config&&(await N(o.tailwind?.config,l,{silent:true,tailwindVersion:f}),s.push(D__default.relative(d,l.resolvedPaths.tailwindConfig))),o.cssVars){let y=await hi(t$1,e);await $t(o.cssVars,l,{silent:true,tailwindVersion:f,tailwindConfig:o.tailwind?.config,overwriteCssVars:y}),s.push(D__default.relative(d,l.resolvedPaths.tailwindCss));}o.css&&(await It(o.css,l,{silent:true}),s.push(D__default.relative(d,l.resolvedPaths.tailwindCss))),o.envVars&&await Tt(o.envVars,l,{silent:true}),await O(o.dependencies,o.devDependencies,l,{silent:true}),await Ot(o.fonts,l,{silent:true});let g=new Map;for(let y of o.files??[]){let C=y.type||"registry:ui";g.has(C)||g.set(C,[]),g.get(C).push(y);}for(let y of Array.from(g.keys())){let C=g.get(y),v=y==="registry:ui"?r.ui:e,L=u(e.resolvedPaths.cwd,v.resolvedPaths.ui||v.resolvedPaths.cwd),E=await t(L,v.resolvedPaths.cwd)??v.resolvedPaths.cwd,B=await F$1(C,v,{overwrite:i.overwrite,silent:true,rootSpinner:m,isRemote:i.isRemote,isWorkspace:true,path:i.path});a.push(...B.filesCreated.map(j=>D__default.relative(L,D__default.join(E,j)))),s.push(...B.filesUpdated.map(j=>D__default.relative(L,D__default.join(E,j)))),c.push(...B.filesSkipped.map(j=>D__default.relative(L,D__default.join(E,j))));}if(m?.succeed(),a.sort(),s.sort(),c.sort(),!(a.length||s.length)&&!c.length&&D$1("No files updated.",{silent:i.silent})?.info(),a.length){D$1(`Created ${a.length} ${a.length===1?"file":"files"}:`,{silent:i.silent})?.succeed();for(let y of a)C.log(` - ${y}`);}if(s.length){D$1(`Updated ${s.length} ${s.length===1?"file":"files"}:`,{silent:i.silent})?.info();for(let y of s)C.log(` - ${y}`);}if(c.length){D$1(`Skipped ${c.length} ${s.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:i.silent})?.info();for(let y of c)C.log(` - ${y}`);}o.docs&&C.info(o.docs);}async function hi(t,e){let r=await S(t,{config:e});return z$1.array(n).parse(r).some(n=>n.type==="registry:theme"||n.type==="registry:style"||n.type==="registry:font"||n.type==="registry:base")}function At(t,e){for(let r of t)if(r?.target&&!Ct(r.target,e))throw new Error(`We found an unsafe file path "${r.target} in the registry item. Installation aborted.`)}var bi=z$1.object({components:z$1.array(z$1.string()).optional(),yes:z$1.boolean(),overwrite:z$1.boolean(),cwd:z$1.string(),all:z$1.boolean(),path:z$1.string().optional(),silent:z$1.boolean(),srcDir:z$1.boolean().optional(),cssVariables:z$1.boolean()}),_t=new Command().name("add").description("add a component to your project").argument("[components...]","names, url or local path to component").option("-y, --yes","skip confirmation prompt.",false).option("-o, --overwrite","overwrite existing files.",false).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-a, --all","add all available components",false).option("-p, --path <path>","the path to add the component to.").option("-s, --silent","mute output.",false).option("--src-dir","use the src directory when creating a new project.",false).option("--no-src-dir","do not use the src directory when creating a new project.").option("--css-variables","use css variables for theming.",true).option("--no-css-variables","do not use css variables for theming.").action(async(t,e)=>{try{let r=bi.parse({components:t,cwd:D__default.resolve(e.cwd),...e});await T(r.cwd);let i=await q(r.cwd);i||(i=v({style:"new-york",resolvedPaths:{cwd:r.cwd}}));let n=["sidebar-","login-","signup-","otp-","calendar-"],o=["base-","radix-"];if(t.length>0&&i?.style&&o.some(f=>i?.style.startsWith(f))){let f=t.filter(d=>n.some(g=>d.startsWith(g)));f.length&&(C.warn(`The ${p.info(f.map(d=>d).join(", "))} component(s) are not available for the ${p.info(i.style)} style yet. They are coming soon.`),C.warn("In the meantime, you can visit the blocks page on https://ui.shadcn.com/blocks and copy the code."),C.break(),process.exit(1));}let a=!1;if(t.length>0){let{config:l,newRegistries:f}=await F(t,i,{silent:r.silent,writeFile:!1});i=l,a=f.length>0;}let s,c=!0;if(t.length>0){let[l]=await S([t[0]],{config:i});if(s=l?.type,c=s!=="registry:theme"&&s!=="registry:style",I(l)){await ve(t,i,{...r,baseStyle:c});return}if(!r.yes&&(s==="registry:style"||s==="registry:theme")){C.break();let{confirm:f}=await Ce({type:"confirm",name:"confirm",message:p.warn(`You are about to install a new ${s.replace("registry:","")}.
44
- Existing CSS variables and components will be overwritten. Continue?`)});f||(C.break(),C.log("Installation cancelled."),C.break(),process.exit(1));}}if(r.components?.length||(r.components=await xi(r)),(await x(r.cwd))?.tailwindVersion==="v4"){let l=c$1.filter(f=>r.components?.includes(f.name));l?.length&&(C.break(),l.forEach(f=>{C.warn(p.warn(f.message));}),C.break(),process.exit(1));}await ne({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!1,silent:r.silent&&!a,isNewProject:!1,srcDir:r.srcDir,cssVariables:r.cssVariables,baseStyle:c,baseColor:c?void 0:"neutral",components:r.components});}catch(r){console.log("add error"),C.break(),Q$1(r);}finally{K();}});async function xi(t){let e=await V();if(!e)return C.break(),Q$1(new Error("Failed to fetch registry index.")),[];if(t.all)return e.map(n=>n.name).filter(n=>!c$1.some(o=>o.name===n));if(t.components?.length)return t.components;let{components:r}=await Ce({type:"multiselect",name:"components",message:"Which components would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:false,choices:e.filter(n=>n.type==="registry:ui"&&!c$1.some(o=>o.name===n.name)).map(n=>({title:n.name,value:n.name,selected:t.all?true:t.components?.includes(n.name)}))});r?.length||(C.warn("No components selected. Exiting."),C.info(""),process.exit(1));let i=z$1.array(z$1.string()).safeParse(r);return i.success?i.data:(C.error(""),Q$1(new Error("Something went wrong. Please try again.")),[])}async function Wt(t){let e={},r={cwd:t.cwd,registryFile:D__default.resolve(t.cwd,t.registryFile),outputDir:D__default.resolve(t.cwd,t.outputDir)};return Q.existsSync(r.registryFile)||(e["13"]=true),await Q.mkdir(r.outputDir,{recursive:true}),Object.keys(e).length>0&&(e["13"]&&(C.break(),C.error(`The path ${p.info(r.registryFile)} does not exist.`)),C.break(),process.exit(1)),{errors:e,resolvePaths:r}}var Si=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string()}),Mt=new Command().name("build").description("build components for a shadcn registry").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(t,e)=>{try{let r=Si.parse({cwd:D.resolve(e.cwd),registryFile:t,outputDir:e.output}),{resolvePaths:i}=await Wt(r),n$1=await _.readFile(i.registryFile,"utf-8"),o$1=o.safeParse(JSON.parse(n$1));o$1.success||(C.error(`Invalid registry file found at ${p.info(i.registryFile)}.`),process.exit(1));let a=D$1("Building registry...");for(let s of o$1.data.items){a.start(`Building ${s.name}...`),s.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let m of s.files??[])m.content=await _.readFile(D.resolve(i.cwd,m.path),"utf-8");let c=n.safeParse(s);if(!c.success){C.error(`Invalid registry item found for ${p.info(s.name)}.`);continue}await _.writeFile(D.resolve(i.outputDir,`${c.data.name}.json`),JSON.stringify(c.data,null,2));}await _.copyFile(i.registryFile,D.resolve(i.outputDir,"registry.json")),a.succeed("Building registry.");}catch(r){C.break(),Q$1(r);}});var Bt="https://ui.shadcn.com",Ii={next:"Next.js",vite:"Vite",start:"TanStack Start"},Ut=new Command().name("create").description("create a new project with shadcn/ui").argument("[name]","the name of your project").option("-t, --template <template>","the template to use. e.g. next, start or vite").option("-p, --preset [name]","use a preset configuration").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("--src-dir","use the src directory when creating a new project.",false).option("--no-src-dir","do not use the src directory when creating a new project.").option("-y, --yes","skip confirmation prompt.",true).action(async(t,e)=>{try{if(!t&&!e.template&&!e.preset){let h=Gt();C.log("Build your own shadcn/ui."),C.log(`You will be taken to ${p.info(h)} to build your custom design system.`),C.break();let{proceed:y}=await Ce({type:"confirm",name:"proceed",message:"Open in browser?",initial:!0});y&&await zt(h),process.exit(0);}let i=t;if(!i){let{enteredName:h}=await Ce({type:"text",name:"enteredName",message:"What is your project named?",initial:e.template?`${e.template}-app`:"my-app",format:y=>y.trim(),validate:y=>y.length>128?"Name should be less than 128 characters.":!0});h||process.exit(0),i=h;}let n=e.template;if(!n){let{selectedTemplate:h}=await Ce({type:"select",name:"selectedTemplate",message:`Which ${p.info("template")} would you like to use?`,choices:Object.entries(Ii).map(([y,C])=>({title:C,value:y}))});h||process.exit(0),n=h;}let o=await Pi(e.preset??!0);o||process.exit(0);let a,s;"_isUrl"in o?(a=o.url,s=new URL(o.url).searchParams.get("baseColor")??"neutral"):(a=ki(o),s=o.baseColor);let c=J({}),{config:m}=await F([a],c,{silent:!0});c=m;let[l]=await S([a],{config:c}),f;l?.type==="registry:base"&&l.config&&(f=l.config);let d=Ae.parse({cwd:D__default.resolve(e.cwd),name:i,components:[a],yes:e.yes,defaults:!1,force:!1,silent:!1,isNewProject:!0,srcDir:e.srcDir,cssVariables:!0,template:n,baseColor:s,baseStyle:!1,registryBaseConfig:f,skipPreflight:!1}),g=await ne(d);if(g){await ve(["component-example"],g,{baseStyle:!1,silent:!0,overwrite:!0});let h=Ei(n);h.length>0&&await F$1(h,g,{overwrite:!0,silent:!0});}C.log(`${p.success("Success!")} Project initialization completed.
44
+ Existing CSS variables and components will be overwritten. Continue?`)});f||(C.break(),C.log("Installation cancelled."),C.break(),process.exit(1));}}if(r.components?.length||(r.components=await xi(r)),(await x(r.cwd))?.tailwindVersion==="v4"){let l=c$1.filter(f=>r.components?.includes(f.name));l?.length&&(C.break(),l.forEach(f=>{C.warn(p.warn(f.message));}),C.break(),process.exit(1));}console.log({options:r}),await ne({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!1,silent:r.silent&&!a,isNewProject:!1,srcDir:r.srcDir,cssVariables:r.cssVariables,baseStyle:c,baseColor:c?void 0:"neutral",components:r.components});}catch(r){console.log("add error"),C.break(),Q$1(r);}finally{K();}});async function xi(t){let e=await V();if(!e)return C.break(),Q$1(new Error("Failed to fetch registry index.")),[];if(t.all)return e.map(n=>n.name).filter(n=>!c$1.some(o=>o.name===n));if(t.components?.length)return t.components;let{components:r}=await Ce({type:"multiselect",name:"components",message:"Which components would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:false,choices:e.filter(n=>n.type==="registry:ui"&&!c$1.some(o=>o.name===n.name)).map(n=>({title:n.name,value:n.name,selected:t.all?true:t.components?.includes(n.name)}))});r?.length||(C.warn("No components selected. Exiting."),C.info(""),process.exit(1));let i=z$1.array(z$1.string()).safeParse(r);return i.success?i.data:(C.error(""),Q$1(new Error("Something went wrong. Please try again.")),[])}async function Wt(t){let e={},r={cwd:t.cwd,registryFile:D__default.resolve(t.cwd,t.registryFile),outputDir:D__default.resolve(t.cwd,t.outputDir)};return Q.existsSync(r.registryFile)||(e["13"]=true),await Q.mkdir(r.outputDir,{recursive:true}),Object.keys(e).length>0&&(e["13"]&&(C.break(),C.error(`The path ${p.info(r.registryFile)} does not exist.`)),C.break(),process.exit(1)),{errors:e,resolvePaths:r}}var Si=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string()}),Mt=new Command().name("build").description("build components for a shadcn registry").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(t,e)=>{try{let r=Si.parse({cwd:D.resolve(e.cwd),registryFile:t,outputDir:e.output}),{resolvePaths:i}=await Wt(r),n$1=await _.readFile(i.registryFile,"utf-8"),o$1=o.safeParse(JSON.parse(n$1));o$1.success||(C.error(`Invalid registry file found at ${p.info(i.registryFile)}.`),process.exit(1));let a=D$1("Building registry...");for(let s of o$1.data.items){a.start(`Building ${s.name}...`),s.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let m of s.files??[])m.content=await _.readFile(D.resolve(i.cwd,m.path),"utf-8");let c=n.safeParse(s);if(!c.success){C.error(`Invalid registry item found for ${p.info(s.name)}.`);continue}await _.writeFile(D.resolve(i.outputDir,`${c.data.name}.json`),JSON.stringify(c.data,null,2));}await _.copyFile(i.registryFile,D.resolve(i.outputDir,"registry.json")),a.succeed("Building registry.");}catch(r){C.break(),Q$1(r);}});var Bt="https://ui.shadcn.com",Ii={next:"Next.js",vite:"Vite",start:"TanStack Start"},Ut=new Command().name("create").description("create a new project with shadcn/ui").argument("[name]","the name of your project").option("-t, --template <template>","the template to use. e.g. next, start or vite").option("-p, --preset [name]","use a preset configuration").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("--src-dir","use the src directory when creating a new project.",false).option("--no-src-dir","do not use the src directory when creating a new project.").option("-y, --yes","skip confirmation prompt.",true).action(async(t,e)=>{try{if(!t&&!e.template&&!e.preset){let h=Gt();C.log("Build your own shadcn/ui."),C.log(`You will be taken to ${p.info(h)} to build your custom design system.`),C.break();let{proceed:y}=await Ce({type:"confirm",name:"proceed",message:"Open in browser?",initial:!0});y&&await zt(h),process.exit(0);}let i=t;if(!i){let{enteredName:h}=await Ce({type:"text",name:"enteredName",message:"What is your project named?",initial:e.template?`${e.template}-app`:"my-app",format:y=>y.trim(),validate:y=>y.length>128?"Name should be less than 128 characters.":!0});h||process.exit(0),i=h;}let n=e.template;if(!n){let{selectedTemplate:h}=await Ce({type:"select",name:"selectedTemplate",message:`Which ${p.info("template")} would you like to use?`,choices:Object.entries(Ii).map(([y,C])=>({title:C,value:y}))});h||process.exit(0),n=h;}let o=await Pi(e.preset??!0);o||process.exit(0);let a,s;"_isUrl"in o?(a=o.url,s=new URL(o.url).searchParams.get("baseColor")??"neutral"):(a=ki(o),s=o.baseColor);let c=J({}),{config:m}=await F([a],c,{silent:!0});c=m;let[l]=await S([a],{config:c}),f;l?.type==="registry:base"&&l.config&&(f=l.config);let d=Ae.parse({cwd:D__default.resolve(e.cwd),name:i,components:[a],yes:e.yes,defaults:!1,force:!1,silent:!1,isNewProject:!0,srcDir:e.srcDir,cssVariables:!0,template:n,baseColor:s,baseStyle:!1,registryBaseConfig:f,skipPreflight:!1}),g=await ne(d);if(g){await ve(["component-example"],g,{baseStyle:!1,silent:!0,overwrite:!0});let h=Ei(n);h.length>0&&await F$1(h,g,{overwrite:!0,silent:!0});}C.log(`${p.success("Success!")} Project initialization completed.
45
45
  You may now add components.`),C.break();}catch(r){C.break(),Q$1(r);}finally{K();}});function ki(t){let e=new URLSearchParams({base:t.base,style:t.style,baseColor:t.baseColor,theme:t.theme,iconLibrary:t.iconLibrary,font:t.font,menuAccent:t.menuAccent,menuColor:t.menuColor,radius:t.radius});return `${ji()}?${e.toString()}`}async function Pi(t){if(t===true){let e=await ca(),{selectedPreset:r}=await Ce({type:"select",name:"selectedPreset",message:`Which ${p.info("preset")} would you like to use?`,choices:[...e.map(i=>({title:i.title,description:i.description,value:i.name})),{title:"Custom",description:"Build your own on https://ui.shadcn.com",value:"custom"}]});if(!r)return null;if(r==="custom"){let i=Gt();return C.info(`
46
46
  Opening ${p.info(i)} in your browser...
47
47
  `),await zt(i),null}return e.find(i=>i.name===r)??null}if(typeof t=="string"){if(H(t))return {_isUrl:true,url:t};let e=await da(t);if(!e){let i=(await ca()).map(n=>n.name).join(", ");C.error(`Preset "${t}" not found. Available presets: ${i}`),process.exit(1);}return e}return null}function Ei(t){switch(t){case "vite":return [{type:"registry:file",path:"src/App.tsx",target:"src/App.tsx",content:_e`import { ComponentExample } from "@/components/component-example";
@@ -79,5 +79,5 @@ args = ["shadcn@${re}", "mcp"]`),C.break(),C.info("3. Restart Codex to load the
79
79
  `).map(C=>{if(C.trim().startsWith("import "))return C;let v=C;return v=v.replace(/\b(asChild\s*\?\s*)Slot(\s*:)/g,"$1__SLOT_PLACEHOLDER__$2"),v=v.replace(/\bReact\.ComponentProps<typeof\s+Slot>/g,"React.ComponentProps<typeof __SLOT_PLACEHOLDER__>"),v=v.replace(/\bComponentProps<typeof\s+Slot>/g,"ComponentProps<typeof __SLOT_PLACEHOLDER__>"),v=v.replace(/(<\/?)Slot(\s*\/?>)/g,"$1__SLOT_PLACEHOLDER__$2"),v=v.replace(/\bSlot\b/g,(L,E,B)=>{let j=B.substring(0,E),Pe=(j.match(/"/g)||[]).length,hr=(j.match(/'/g)||[]).length;return Pe%2!==0||hr%2!==0?L:"__SLOT_PLACEHOLDER__"}),v=v.replace(/__SLOT_PLACEHOLDER__/g,"SlotPrimitive.Slot"),v}).join(`
80
80
  `));let g=Array.from(new Set(n));return {content:s,replacedPackages:g}}async function rr(t){let e={};if(!Q.existsSync(t.cwd)||!Q.existsSync(D__default.resolve(t.cwd,"package.json")))return e["1"]=true,{errors:e,config:null};if(!Q.existsSync(D__default.resolve(t.cwd,"components.json")))return e["3"]=true,{errors:e,config:null};try{let r=await q(t.cwd);return {errors:e,config:r}}catch{C.break(),C.error(`An invalid ${p.info("components.json")} file was found at ${p.info(t.cwd)}.
81
81
  Before you can run a migration, you must create a valid ${p.info("components.json")} file by running the ${p.info("init")} command.`),C.error(`Learn more at ${p.info("https://ui.shadcn.com/docs/components-json")}.`),C.break(),process.exit(1);}}var ir=[{name:"icons",description:"migrate your ui components to a different icon library."},{name:"radix",description:"migrate to radix-ui."}],oo=z$1.object({cwd:z$1.string(),list:z$1.boolean(),yes:z$1.boolean(),migration:z$1.string().refine(t=>t&&ir.some(e=>e.name===t),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional()}),or=new Command().name("migrate").description("run a migration.").argument("[migration]","the migration to run.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-l, --list","list all migrations.",false).option("-y, --yes","skip confirmation prompt.",false).action(async(t,e)=>{try{let r=oo.parse({cwd:D__default.resolve(e.cwd),migration:t,list:e.list,yes:e.yes});if(r.list||!r.migration){C.info("Available migrations:");for(let o of ir)C.info(`- ${o.name}: ${o.description}`);return}if(!r.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:i,config:n}=await rr(r);if(i["1"]||i["3"])throw new Error("No `components.json` file found. Ensure you are at the root of your project.");if(!n)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");r.migration==="icons"&&await Qt(n),r.migration==="radix"&&await er(n,{yes:r.yes});}catch(r){C.break(),Q$1(r);}});async function nr(t){let e={},r={cwd:t.cwd,registryFile:D__default.resolve(t.cwd,t.registryFile),outputDir:D__default.resolve(t.cwd,t.outputDir)};if(!Q.existsSync(r.registryFile))return e["13"]=true,{errors:e,resolvePaths:null,config:null};if(!Q.existsSync(D__default.resolve(t.cwd,"components.json")))return e["3"]=true,{errors:e,resolvePaths:null,config:null};await Q.mkdir(r.outputDir,{recursive:true});try{let i=await q(t.cwd);return {errors:e,config:i,resolvePaths:r}}catch{C.break(),C.error(`An invalid ${p.info("components.json")} file was found at ${p.info(t.cwd)}.
82
- Before you can build the registry, you must create a valid ${p.info("components.json")} file by running the ${p.info("init")} command.`),C.break(),process.exit(1);}}var so=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),sr=new Command().name("registry:build").description("builds the registry [EXPERIMENTAL]").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-v, --verbose","verbose output").action(async(t,e)=>{await ao({cwd:D.resolve(e.cwd),registryFile:t,outputDir:e.output,verbose:e.verbose});});async function ao(t){try{let e=so.parse(t),[{errors:r,resolvePaths:i,config:n$1},o$1]=await Promise.all([nr(e),x(e.cwd)]);(r["3"]||!n$1||!o$1)&&(C.error(`A ${p.info("components.json")} file is required to build the registry. Run ${p.info("shadcn init")} to create one.`),C.break(),process.exit(1)),(r["13"]||!i)&&(C.error(`We could not find a registry file at ${p.info(D.resolve(e.cwd,e.registryFile))}.`),C.break(),process.exit(1));let a=await _.readFile(i.registryFile,"utf-8"),s=o.safeParse(JSON.parse(a));s.success||(C.error(`Invalid registry file found at ${p.info(i.registryFile)}.`),C.break(),process.exit(1));let c=D$1("Building registry..."),m=await co(s.data,n$1,o$1);for(let l of m.items)l.files=l.files?.filter((f,d,g)=>d===g.findIndex(h=>h.path===f.path)),l.dependencies&&(l.dependencies=l.dependencies.filter((f,d,g)=>d===g.findIndex(h=>h===f)));for(let l of m.items){if(!l.files)continue;c.start(`Building ${l.name}...`),l.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let d of l.files){let g=D.resolve(i.cwd,d.path);try{if(!(await _.stat(g)).isFile())continue;d.content=await _.readFile(g,"utf-8");}catch(h){console.error("Error reading file in registry build:",g,h);continue}}let f=n.safeParse(l);if(!f.success){C.error(`Invalid registry item found for ${p.info(l.name)}.`);continue}await _.writeFile(D.resolve(i.outputDir,`${f.data.name}.json`),JSON.stringify(f.data,null,2));}if(await _.copyFile(i.registryFile,D.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),e.verbose){D$1(`The registry has ${p.info(m.items.length.toString())} items:`).succeed();for(let l of m.items){C.log(` - ${l.name} (${p.info(l.type)})`);for(let f of l.files??[])C.log(` - ${f.path}`);}}}catch(e){C.break(),Q$1(e);}}async function co(t,e,r){for(let i of t.items)if(i.files?.length)for(let n of i.files){let o=await G(n.path,e,r);o.files=o.files?.filter(a=>a.path!==n.path),o.files&&i.files.push(...o.files),o.dependencies&&(i.dependencies=i.dependencies?i.dependencies.concat(o.dependencies):o.dependencies);}return t}var ar=new Command().name("registry:mcp").description("starts the registry MCP server [DEPRECATED]").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async()=>{C.warn(`The ${p.info("shadcn registry:mcp")} command is deprecated. Use the ${p.info("shadcn mcp")} command instead.`),C.break();});var po=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),mr=new Command().name("search").alias("list").description("search items from registries").argument("<registries...>","the registry names or urls to search items from. Names must be prefixed with @.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-q, --query <query>","query string").option("-l, --limit <number>","maximum number of items to display per registry","100").option("-o, --offset <number>","number of items to skip","0").action(async(t,e)=>{try{let r=po.parse({cwd:D__default.resolve(e.cwd),query:e.query,limit:e.limit?parseInt(e.limit,10):void 0,offset:e.offset?parseInt(e.offset,10):void 0});await T(r.cwd);let i=v({style:"new-york",resolvedPaths:{cwd:r.cwd}}),n=J(i),o=D__default.resolve(r.cwd,"components.json");if(Q.existsSync(o)){let l=await Q.readJson(o),f=c.partial().parse(l);n=J({...i,...f});}let a=n;try{let l=await q(r.cwd);l&&(a=J(l));}catch{}let{config:s,newRegistries:c$1}=await F(t.map(l=>`${l}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),L(t,a);let m=await ea(t,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(m,null,2)),process.exit(0);}catch(r){Q$1(r);}finally{K();}});var uo=z$1.object({cwd:z$1.string()}),ur=new Command().name("view").description("view items from the registry").argument("<items...>","the item names or URLs to view").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(t,e)=>{try{let r=uo.parse({cwd:D__default.resolve(e.cwd)});await T(r.cwd);let i=J({}),n=D__default.resolve(r.cwd,"components.json");if(Q.existsSync(n)){let m=await Q.readJson(n),l=c.partial().parse(m);i=J(l);}let o=i;try{let m=await q(r.cwd);m&&(o=J(m));}catch{}let{config:a,newRegistries:s}=await F(t,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),L(t,o);let c$1=await S(t,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){Q$1(r);}finally{K();}});var gr={version:"3.6.20"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function yo(){let t=new Command().name("shadcn").description("add items from registries to your project").version(gr.version,"-v, --version","display the version number");t.addCommand(St).addCommand(Ut).addCommand(_t).addCommand(Yt).addCommand(ur).addCommand(mr).addCommand(or).addCommand(Kt).addCommand(Mt).addCommand(Me),t.addCommand(sr).addCommand(ar),t.parse();}yo();//# sourceMappingURL=index.js.map
82
+ Before you can build the registry, you must create a valid ${p.info("components.json")} file by running the ${p.info("init")} command.`),C.break(),process.exit(1);}}var so=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),sr=new Command().name("registry:build").description("builds the registry [EXPERIMENTAL]").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-v, --verbose","verbose output").action(async(t,e)=>{await ao({cwd:D.resolve(e.cwd),registryFile:t,outputDir:e.output,verbose:e.verbose});});async function ao(t){try{let e=so.parse(t),[{errors:r,resolvePaths:i,config:n$1},o$1]=await Promise.all([nr(e),x(e.cwd)]);(r["3"]||!n$1||!o$1)&&(C.error(`A ${p.info("components.json")} file is required to build the registry. Run ${p.info("shadcn init")} to create one.`),C.break(),process.exit(1)),(r["13"]||!i)&&(C.error(`We could not find a registry file at ${p.info(D.resolve(e.cwd,e.registryFile))}.`),C.break(),process.exit(1));let a=await _.readFile(i.registryFile,"utf-8"),s=o.safeParse(JSON.parse(a));s.success||(C.error(`Invalid registry file found at ${p.info(i.registryFile)}.`),C.break(),process.exit(1));let c=D$1("Building registry..."),m=await co(s.data,n$1,o$1);for(let l of m.items)l.files=l.files?.filter((f,d,g)=>d===g.findIndex(h=>h.path===f.path)),l.dependencies&&(l.dependencies=l.dependencies.filter((f,d,g)=>d===g.findIndex(h=>h===f)));for(let l of m.items){if(!l.files)continue;c.start(`Building ${l.name}...`),l.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let d of l.files){let g=D.resolve(i.cwd,d.path);try{if(!(await _.stat(g)).isFile())continue;d.content=await _.readFile(g,"utf-8");}catch(h){console.error("Error reading file in registry build:",g,h);continue}}let f=n.safeParse(l);if(!f.success){C.error(`Invalid registry item found for ${p.info(l.name)}.`);continue}await _.writeFile(D.resolve(i.outputDir,`${f.data.name}.json`),JSON.stringify(f.data,null,2));}if(await _.copyFile(i.registryFile,D.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),e.verbose){D$1(`The registry has ${p.info(m.items.length.toString())} items:`).succeed();for(let l of m.items){C.log(` - ${l.name} (${p.info(l.type)})`);for(let f of l.files??[])C.log(` - ${f.path}`);}}}catch(e){C.break(),Q$1(e);}}async function co(t,e,r){for(let i of t.items)if(i.files?.length)for(let n of i.files){let o=await G(n.path,e,r);o.files=o.files?.filter(a=>a.path!==n.path),o.files&&i.files.push(...o.files),o.dependencies&&(i.dependencies=i.dependencies?i.dependencies.concat(o.dependencies):o.dependencies);}return t}var ar=new Command().name("registry:mcp").description("starts the registry MCP server [DEPRECATED]").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async()=>{C.warn(`The ${p.info("shadcn registry:mcp")} command is deprecated. Use the ${p.info("shadcn mcp")} command instead.`),C.break();});var po=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),mr=new Command().name("search").alias("list").description("search items from registries").argument("<registries...>","the registry names or urls to search items from. Names must be prefixed with @.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-q, --query <query>","query string").option("-l, --limit <number>","maximum number of items to display per registry","100").option("-o, --offset <number>","number of items to skip","0").action(async(t,e)=>{try{let r=po.parse({cwd:D__default.resolve(e.cwd),query:e.query,limit:e.limit?parseInt(e.limit,10):void 0,offset:e.offset?parseInt(e.offset,10):void 0});await T(r.cwd);let i=v({style:"new-york",resolvedPaths:{cwd:r.cwd}}),n=J(i),o=D__default.resolve(r.cwd,"components.json");if(Q.existsSync(o)){let l=await Q.readJson(o),f=c.partial().parse(l);n=J({...i,...f});}let a=n;try{let l=await q(r.cwd);l&&(a=J(l));}catch{}let{config:s,newRegistries:c$1}=await F(t.map(l=>`${l}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),L(t,a);let m=await ea(t,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(m,null,2)),process.exit(0);}catch(r){Q$1(r);}finally{K();}});var uo=z$1.object({cwd:z$1.string()}),ur=new Command().name("view").description("view items from the registry").argument("<items...>","the item names or URLs to view").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(t,e)=>{try{let r=uo.parse({cwd:D__default.resolve(e.cwd)});await T(r.cwd);let i=J({}),n=D__default.resolve(r.cwd,"components.json");if(Q.existsSync(n)){let m=await Q.readJson(n),l=c.partial().parse(m);i=J(l);}let o=i;try{let m=await q(r.cwd);m&&(o=J(m));}catch{}let{config:a,newRegistries:s}=await F(t,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),L(t,o);let c$1=await S(t,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){Q$1(r);}finally{K();}});var gr={version:"3.6.21"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function yo(){let t=new Command().name("shadcn").description("add items from registries to your project").version(gr.version,"-v, --version","display the version number");t.addCommand(St).addCommand(Ut).addCommand(_t).addCommand(Yt).addCommand(ur).addCommand(mr).addCommand(or).addCommand(Kt).addCommand(Mt).addCommand(Me),t.addCommand(sr).addCommand(ar),t.parse();}yo();//# sourceMappingURL=index.js.map
83
83
  //# sourceMappingURL=index.js.map