hghcn 3.6.23 → 3.6.25

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
@@ -5,7 +5,7 @@ Visit ${d.info(o$1?.framework.links.installation)} to manually configure your pr
5
5
  Once configured, you can use the cli to add components.`),r.break(),process.exit(1)),r$1?.succeed(`Verifying framework. Found ${d.info(o$1.framework.label)}.`);let n="Validating Tailwind CSS.";o$1.tailwindVersion==="v4"&&(n=`Validating Tailwind CSS config. Found ${d.info("v4")}.`);let a=s(n,{silent:e.silent}).start();o$1.tailwindVersion==="v3"&&(!o$1?.tailwindConfigFile||!o$1?.tailwindCssFile)?(t["5"]=true,a?.fail()):o$1.tailwindVersion==="v4"&&!o$1?.tailwindCssFile?(t["5"]=true,a?.fail()):o$1.tailwindVersion?a?.succeed():(t["5"]=true,a?.fail());let s$1=s("Validating import alias.",{silent:e.silent}).start();return o$1?.aliasPrefix?s$1?.succeed():(t["6"]=true,s$1?.fail()),Object.keys(t).length>0&&(t["5"]&&(r.break(),r.error(`No Tailwind CSS configuration found at ${d.info(e.cwd)}.`),r.error("It is likely you do not have Tailwind CSS installed or have an invalid configuration."),r.error("Install Tailwind CSS then try again."),o$1?.framework.links.tailwind&&r.error(`Visit ${d.info(o$1?.framework.links.tailwind)} to get started.`)),t["6"]&&(r.break(),r.error("No import alias found in your tsconfig.json file."),o$1?.framework.links.installation&&r.error(`Visit ${d.info(o$1?.framework.links.installation)} to learn how to set an import alias.`)),r.break(),process.exit(1)),{errors:t,projectInfo:o$1}}var Ue="https://codeload.github.com/shadcn-ui/ui/tar.gz/main",A={next:"next","next-monorepo":"next-monorepo",vite:"vite",start:"start"};async function Dt(e){e={srcDir:false,...e};let t=e.template&&A[e.template]?e.template:"next",i=e.name??(t===A.next||t===A.vite||t===A.start?"my-app":"my-monorepo"),r$1="latest",o=e.components?.length===1&&!!e.components[0].match(/\/chat\/b\//);if(e.components&&o)try{let[s]=await R(e.components),{meta:c}=z$1.object({meta:z$1.object({nextVersion:z$1.string()})}).parse(s);r$1=c.nextVersion,t=A.next;}catch(s){r.break(),V$1(s);}if(!e.force){let{type:s,name:c}=await Ne([{type:e.template||o?null:"select",name:"type",message:`The path ${d.info(e.cwd)} does not contain a package.json file.
6
6
  Would you like to start a new project?`,choices:[{title:"Next.js",value:"next"},{title:"Next.js (Monorepo)",value:"next-monorepo"},{title:"Vite",value:"vite"},{title:"TanStack Start",value:"start"}],initial:0},{type:e.name?null:"text",name:"name",message:"What is your project named?",initial:i,format:m=>m.trim(),validate:m=>m.length>128?"Name should be less than 128 characters.":true}]);t=s??t,i=c??i;}let n=await a$1(e.cwd,{withFallback:true}),a=`${e.cwd}/${i}`;try{await v.access(e.cwd,v.constants.W_OK);}catch{r.break(),r.error(`The path ${d.info(e.cwd)} is not writable.`),r.error(`It is likely you do not have write permissions for this folder or the path ${d.info(e.cwd)} does not exist.`),r.break(),process.exit(1);}return v.existsSync(E__default.resolve(e.cwd,i,"package.json"))&&(r.break(),r.error(`A project with the name ${d.info(i)} already exists.`),r.error("Please choose a different name and try again."),r.break(),process.exit(1)),t===A.next&&await Vr(a,{version:r$1,cwd:e.cwd,packageManager:n,srcDir:!!e.srcDir}),t===A["next-monorepo"]&&await Wr(a,{packageManager:n}),t===A.vite&&await Mr(a,{packageManager:n}),t===A.start&&await zr(a,{packageManager:n}),{projectPath:a,projectName:i,template:t}}async function Vr(e,t){let i=s("Creating a new Next.js project. This may take a few minutes.").start(),r$1=["--tailwind","--eslint","--typescript","--app",t.srcDir?"--src-dir":"--no-src-dir","--no-import-alias",`--use-${t.packageManager}`];(t.version.startsWith("15")||t.version.startsWith("latest")||t.version.startsWith("canary"))&&r$1.push("--turbopack"),(t.version.startsWith("latest")||t.version.startsWith("canary"))&&r$1.push("--no-react-compiler");try{await execa("npx",[`create-next-app@${t.version}`,e,"--silent",...r$1],{cwd:t.cwd});}catch{r.break(),r.error("Something went wrong creating a new Next.js project. Please try again."),process.exit(1);}i?.succeed("Creating a new Next.js project.");}async function Wr(e,t){let i=s("Creating a new Next.js monorepo. This may take a few minutes.").start();try{let r=E__default.join(Be.tmpdir(),`shadcn-template-${Date.now()}`);await v.ensureDir(r);let o=await fetch(Ue);if(!o.ok)throw new Error(`Failed to download template: ${o.statusText}`);let n=E__default.resolve(r,"template.tar.gz");await v.writeFile(n,Buffer.from(await o.arrayBuffer())),await execa("tar",["-xzf",n,"-C",r,"--strip-components=2","ui-main/templates/monorepo-next"]);let a=E__default.resolve(r,"monorepo-next");await v.move(a,e),await v.remove(r),await execa(t.packageManager,["install"],{cwd:e});let s=E__default.join(e,"package.json");if(v.existsSync(s)){let m=await v.readFile(s,"utf8"),l=JSON.parse(m);l.name=e.split("/").pop(),await v.writeFile(s,JSON.stringify(l,null,2));}let c=process.cwd();await execa("git",["--version"],{cwd:e}),await execa("git",["init"],{cwd:e}),await execa("git",["add","-A"],{cwd:e}),await execa("git",["commit","-m","Initial commit"],{cwd:e}),i?.succeed("Creating a new Next.js monorepo.");}catch(r){i?.fail("Something went wrong creating a new Next.js monorepo."),V$1(r);}}async function Mr(e,t){let i=s("Creating a new Vite project. This may take a few minutes.").start();try{let r=E__default.join(Be.tmpdir(),`shadcn-template-${Date.now()}`);await v.ensureDir(r);let o=await fetch(Ue);if(!o.ok)throw new Error(`Failed to download template: ${o.statusText}`);let n=E__default.resolve(r,"template.tar.gz");await v.writeFile(n,Buffer.from(await o.arrayBuffer())),await execa("tar",["-xzf",n,"-C",r,"--strip-components=2","ui-main/templates/vite-app"]);let a=E__default.resolve(r,"vite-app");if(await v.move(a,e),await v.remove(r),t.packageManager!=="pnpm"){let c=E__default.join(e,"pnpm-lock.yaml");v.existsSync(c)&&await v.remove(c);}await execa(t.packageManager,["install"],{cwd:e});let s=E__default.join(e,"package.json");if(v.existsSync(s)){let c=await v.readFile(s,"utf8"),m=JSON.parse(c);m.name=e.split("/").pop(),await v.writeFile(s,JSON.stringify(m,null,2));}await execa("git",["--version"],{cwd:e}),await execa("git",["init"],{cwd:e}),await execa("git",["add","-A"],{cwd:e}),await execa("git",["commit","-m","Initial commit"],{cwd:e}),i?.succeed("Creating a new Vite project.");}catch(r){i?.fail("Something went wrong creating a new Vite project."),V$1(r);}}async function zr(e,t){let i=s("Creating a new TanStack Start project. This may take a few minutes.").start();try{let r=E__default.join(Be.tmpdir(),`shadcn-template-${Date.now()}`);await v.ensureDir(r);let o=await fetch(Ue);if(!o.ok)throw new Error(`Failed to download template: ${o.statusText}`);let n=E__default.resolve(r,"template.tar.gz");await v.writeFile(n,Buffer.from(await o.arrayBuffer())),await execa("tar",["-xzf",n,"-C",r,"--strip-components=2","ui-main/templates/start-app"]);let a=E__default.resolve(r,"start-app");if(await v.move(a,e),await v.remove(r),t.packageManager!=="pnpm"){let c=E__default.join(e,"pnpm-lock.yaml");v.existsSync(c)&&await v.remove(c);}await execa(t.packageManager,["install"],{cwd:e});let s=E__default.join(e,"package.json");if(v.existsSync(s)){let c=await v.readFile(s,"utf8"),m=JSON.parse(c);m.name=e.split("/").pop(),await v.writeFile(s,JSON.stringify(m,null,2));}await execa("git",["--version"],{cwd:e}),await execa("git",["init"],{cwd:e}),await execa("git",["add","-A"],{cwd:e}),await execa("git",["commit","-m","Initial commit"],{cwd:e}),i?.succeed("Creating a new TanStack Start project.");}catch(r){i?.fail("Something went wrong creating a new TanStack Start project."),V$1(r);}}async function L(e=process.cwd()){try{let{config:t}=await import('@dotenvx/dotenvx'),i=[".env.local",".env.development.local",".env.development",".env"];for(let r of i){let o=join(e,r);existsSync(o)&&t({path:o,overload:!1,quiet:!0});}}catch(t){r.warn("Failed to load env files:",t);}}var Ge=".bak";function _t(e){if(!v.existsSync(e))return null;let t=`${e}${Ge}`;try{return v.renameSync(e,t),t}catch(i){return console.error(`Failed to create backup of ${e}: ${i}`),null}}function Lt(e){let t=`${e}${Ge}`;if(!v.existsSync(t))return false;try{return v.renameSync(t,e),!0}catch(i){return console.error(`Warning: Could not restore backup file ${t}: ${i}`),false}}function Je(e){let t=`${e}${Ge}`;if(!v.existsSync(t))return false;try{return v.unlinkSync(t),!0}catch{return false}}async function Vt(e,t){let i=new Set,r=new Set,o=[...e];for(;o.length>0;){let n=o.shift();if(r.has(n))continue;r.add(n);let{registry:a}=E$1(n);a&&!b$1[a]&&i.add(a);try{let[s]=await T([n],t,{useCache:!0});if(s?.registryDependencies)for(let c of s.registryDependencies){let{registry:m}=E$1(c);m&&!b$1[m]&&i.add(m),r.has(c)||o.push(c);}}catch(s){if(s instanceof y){let{registry:c}=E$1(n);c&&!b$1[c]&&i.add(c);continue}continue}}return Array.from(i)}async function V(e,t,i={}){i={silent:false,writeFile:true,...i};let o=(await Vt(e,t)).filter(m=>!t.registries?.[m]&&!Object.keys(b$1).includes(m));if(o.length===0)return {config:t,newRegistries:[]};let n=await ga({useCache:process.env.NODE_ENV!=="development"});if(!n)return {config:t,newRegistries:[]};let a={};for(let m of o)n[m]&&(a[m]=n[m]);if(Object.keys(a).length===0)return {config:t,newRegistries:[]};let s$1=Object.fromEntries(Object.entries(t.registries||{}).filter(([m])=>!Object.keys(b$1).includes(m))),c$1={...t,registries:{...s$1,...a}};if(i.writeFile){let{resolvedPaths:m,...l}=c$1,p=s("Updating components.json.",{silent:i.silent}).start(),u=c.parse(l);await v.writeFile(E__default.resolve(t.resolvedPaths.cwd,"components.json"),JSON.stringify(u,null,2)+`
7
7
  `,"utf-8"),p.succeed();}return {config:c$1,newRegistries:Object.keys(a)}}process.on("exit",e=>{let t=E__default.resolve(process.cwd(),"components.json");return e===0?Je(t):Lt(t)});var Ye=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(e=>e?A[e]:true,{message:"Invalid template. Please use 'next', 'vite', 'start' or 'next-monorepo'."}),baseColor:z$1.string().optional().refine(e=>e?a.find(t=>t.name===e):true,{message:`Invalid base color. Please use '${a.map(e=>e.name).join("', '")}'`}),baseStyle:z$1.boolean(),registryBaseConfig:c.deepPartial().optional()}),zt=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(e,t)=>{try{t.defaults&&(t.template=t.template||"next",t.baseColor=t.baseColor||"neutral");let i=Ye.parse({cwd:E__default.resolve(t.cwd),isNewProject:!1,components:e,...t});if(await L(i.cwd),e.length>0){let r=N(m({resolvedPaths:{cwd:i.cwd}})),o=E__default.resolve(i.cwd,"components.json");if(v.existsSync(o)){let s=await v.readJson(o),c$1=c.partial().parse(s),m$1=m({resolvedPaths:{cwd:i.cwd}});r=N({...c$1,resolvedPaths:{...m$1.resolvedPaths,cwd:i.cwd}}),_t(o);}let{config:n}=await V(e,r,{silent:!0,writeFile:!1});r=n,Q(e[0],r);let[a]=await X([e[0]],{config:r});a?.type==="registry:base"&&(a.config&&(r=N(Kr(r,a.config)),i.registryBaseConfig=a.config),i.baseStyle=a.extends==="none"?!1:i.baseStyle),a?.type==="registry:style"&&(i.baseColor="neutral",i.baseStyle=a.extends==="none"?!1:i.baseStyle);}i.baseStyle||(i.baseColor="neutral"),await pe(i),r.log(`${d.success("Success!")} Project initialization completed.
8
- You may now add components.`),Je(E__default.resolve(i.cwd,"components.json")),r.break();}catch(i){r.break(),V$1(i);}finally{O();}});async function pe(e){let t,i$1;if(e.skipPreflight)t=await o(e.cwd);else {let a=await At(e);if(a.errors["1"]){let{projectPath:s,template:c}=await Dt(e);s||process.exit(1),e.cwd=s,e.isNewProject=true,i$1=c,t=await o(e.cwd);}else t=a.projectInfo;}if(i$1==="next-monorepo")return e.cwd=E__default.resolve(e.cwd,"apps/web"),await i(e.cwd);let r=await p(e.cwd,t),o$1=r?await Hr(r,e):await qr(await i(e.cwd));console.log({config:o$1,options:e});[...e.baseStyle?["index"]:[],...e.components??[]];}async function qr(e$1=null){let[t,i]=await Promise.all([$(),ba()]);r.info("");let r$1=await Ne([{type:"toggle",name:"typescript",message:`Would you like to use ${d.info("TypeScript")} (recommended)?`,initial:e$1?.tsx??true,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${d.info("style")} would you like to use?`,choices:t.map(o=>({title:o.label,value:o.name}))},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${d.info("base color")}?`,choices:i.map(o=>({title:o.label,value:o.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${d.info("global CSS")} file?`,initial:e$1?.tailwind.css??g},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${d.info("CSS variables")} for theming?`,initial:e$1?.tailwind.cssVariables??true,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${d.info("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${d.info("tailwind.config.js")} located?`,initial:e$1?.tailwind.config??h},{type:"text",name:"components",message:`Configure the import alias for ${d.info("components")}:`,initial:e$1?.aliases.components??e},{type:"text",name:"utils",message:`Configure the import alias for ${d.info("utils")}:`,initial:e$1?.aliases.utils??f},{type:"toggle",name:"rsc",message:`Are you using ${d.info("React Server Components")}?`,initial:e$1?.rsc??true,active:"yes",inactive:"no"}]);return c.parse({$schema:"https://ui.shadcn.com/schema.json",style:r$1.style,tailwind:{config:r$1.tailwindConfig,css:r$1.tailwindCss,baseColor:r$1.tailwindBaseColor,cssVariables:r$1.tailwindCssVariables,prefix:r$1.tailwindPrefix},rsc:r$1.rsc,tsx:r$1.typescript,aliases:{utils:r$1.utils,components:r$1.components,lib:r$1.components.replace(/\/components$/,"lib"),hooks:r$1.components.replace(/\/components$/,"hooks")}})}async function Hr(e,t){let i=e.style,r=t.baseColor,o=e.tailwind.cssVariables,n=e.iconLibrary??"lucide";if(!t.defaults){let[a,s,c]=await Promise.all([$(),ba(),q(e)]),m=await Ne([{type:c==="v4"||i?null:"select",name:"style",message:`Which ${d.info("style")} would you like to use?`,choices:a.map(l=>({title:l.name==="new-york"?"New York (Recommended)":l.label,value:l.name})),initial:0},{type:t.baseColor?null:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${d.info("base color")}?`,choices:s.map(l=>({title:l.label,value:l.name}))}]);i=m.style??i??"new-york",r=m.tailwindBaseColor??r,o=t.cssVariables;}return c.parse({$schema:e?.$schema,style:i,tailwind:{...e?.tailwind,baseColor:r,cssVariables:o},rsc:e?.rsc,tsx:e?.tsx,iconLibrary:n,aliases:e?.aliases})}function Bt(e,t){if(e.includes("\0"))return false;let i;try{i=e;let u="";for(;i!==u&&i.includes("%");)u=i,i=decodeURIComponent(i);}catch{return false}let r=E__default.normalize(i.replace(/\\/g,"/")),o=E__default.normalize(t),n=u=>u.replace(/\[\.\.\..*?\]/g,"").includes("..");if(n(r)||n(i)||n(e))return false;let a=u=>u.replace(/\[\.\.\..*?\]/g,""),s=a(e),c=a(i);if([/\.\.[\/\\]/,/[\/\\]\.\./,/\.\./,/\.\.%/,/\x00/,/[\x01-\x1f]/].some(u=>u.test(s)||u.test(c))||(e.includes("~")||i.includes("~"))&&(e.includes("../")||i.includes("../")))return false;if(/^[a-zA-Z]:[\/\\]/.test(i))return process.platform==="win32"?i.toLowerCase().startsWith(t.toLowerCase()):false;if(E__default.isAbsolute(r))return r.startsWith(o+E__default.sep);let p=E__default.resolve(o,r);return p.startsWith(o+E__default.sep)||p===o}async function Gt(e,t,i){if(!t.resolvedPaths.tailwindCss||!e||Object.keys(e).length===0)return;i={silent:false,...i};let r=t.resolvedPaths.tailwindCss,o=E__default.relative(t.resolvedPaths.cwd,r),n=s(`Updating ${d.info(o)}`,{silent:i.silent}).start(),a=await promises.readFile(r,"utf8"),s$1=await Zr(a,e);await promises.writeFile(r,s$1,"utf8"),n.succeed();}async function Zr(e,t){let i=[Qr(t)],r=await x(i).process(e,{from:void 0}),o=r.css,n=r.root;if(n.nodes&&n.nodes.length>0){let a=n.nodes[n.nodes.length-1];a.type==="atrule"&&!a.nodes&&!o.trimEnd().endsWith(";")&&(o=o.trimEnd()+";");}return o=o.replace(/\/\* ---break--- \*\//g,""),o=o.replace(/(\n\s*\n)+/g,`
8
+ You may now add components.`),Je(E__default.resolve(i.cwd,"components.json")),r.break();}catch(i){r.break(),V$1(i);}finally{O();}});async function pe(e){let t,i$1;if(e.skipPreflight)t=await o(e.cwd);else {let a=await At(e);if(a.errors["1"]){let{projectPath:s,template:c}=await Dt(e);s||process.exit(1),e.cwd=s,e.isNewProject=true,i$1=c,t=await o(e.cwd);}else t=a.projectInfo;}if(i$1==="next-monorepo")return e.cwd=E__default.resolve(e.cwd,"apps/web"),await i(e.cwd);let r=await p(e.cwd,t);console.log({projectConfig:r});let o$1=r?await Hr(r,e):await qr(await i(e.cwd));console.log({config:o$1,options:e});[...e.baseStyle?["index"]:[],...e.components??[]];}async function qr(e$1=null){let[t,i]=await Promise.all([$(),ba()]);r.info("");let r$1=await Ne([{type:"toggle",name:"typescript",message:`Would you like to use ${d.info("TypeScript")} (recommended)?`,initial:e$1?.tsx??true,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${d.info("style")} would you like to use?`,choices:t.map(o=>({title:o.label,value:o.name}))},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${d.info("base color")}?`,choices:i.map(o=>({title:o.label,value:o.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${d.info("global CSS")} file?`,initial:e$1?.tailwind.css??g},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${d.info("CSS variables")} for theming?`,initial:e$1?.tailwind.cssVariables??true,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${d.info("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${d.info("tailwind.config.js")} located?`,initial:e$1?.tailwind.config??h},{type:"text",name:"components",message:`Configure the import alias for ${d.info("components")}:`,initial:e$1?.aliases.components??e},{type:"text",name:"utils",message:`Configure the import alias for ${d.info("utils")}:`,initial:e$1?.aliases.utils??f},{type:"toggle",name:"rsc",message:`Are you using ${d.info("React Server Components")}?`,initial:e$1?.rsc??true,active:"yes",inactive:"no"}]);return c.parse({$schema:"https://ui.shadcn.com/schema.json",style:r$1.style,tailwind:{config:r$1.tailwindConfig,css:r$1.tailwindCss,baseColor:r$1.tailwindBaseColor,cssVariables:r$1.tailwindCssVariables,prefix:r$1.tailwindPrefix},rsc:r$1.rsc,tsx:r$1.typescript,aliases:{utils:r$1.utils,components:r$1.components,lib:r$1.components.replace(/\/components$/,"lib"),hooks:r$1.components.replace(/\/components$/,"hooks")}})}async function Hr(e,t){let i=e.style,r=t.baseColor,o=e.tailwind.cssVariables,n=e.iconLibrary??"lucide";if(!t.defaults){let[a,s,c]=await Promise.all([$(),ba(),q(e)]),m=await Ne([{type:c==="v4"||i?null:"select",name:"style",message:`Which ${d.info("style")} would you like to use?`,choices:a.map(l=>({title:l.name==="new-york"?"New York (Recommended)":l.label,value:l.name})),initial:0},{type:t.baseColor?null:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${d.info("base color")}?`,choices:s.map(l=>({title:l.label,value:l.name}))}]);i=m.style??i??"new-york",r=m.tailwindBaseColor??r,o=t.cssVariables;}return c.parse({$schema:e?.$schema,style:i,tailwind:{...e?.tailwind,baseColor:r,cssVariables:o},rsc:e?.rsc,tsx:e?.tsx,iconLibrary:n,aliases:e?.aliases})}function Bt(e,t){if(e.includes("\0"))return false;let i;try{i=e;let u="";for(;i!==u&&i.includes("%");)u=i,i=decodeURIComponent(i);}catch{return false}let r=E__default.normalize(i.replace(/\\/g,"/")),o=E__default.normalize(t),n=u=>u.replace(/\[\.\.\..*?\]/g,"").includes("..");if(n(r)||n(i)||n(e))return false;let a=u=>u.replace(/\[\.\.\..*?\]/g,""),s=a(e),c=a(i);if([/\.\.[\/\\]/,/[\/\\]\.\./,/\.\./,/\.\.%/,/\x00/,/[\x01-\x1f]/].some(u=>u.test(s)||u.test(c))||(e.includes("~")||i.includes("~"))&&(e.includes("../")||i.includes("../")))return false;if(/^[a-zA-Z]:[\/\\]/.test(i))return process.platform==="win32"?i.toLowerCase().startsWith(t.toLowerCase()):false;if(E__default.isAbsolute(r))return r.startsWith(o+E__default.sep);let p=E__default.resolve(o,r);return p.startsWith(o+E__default.sep)||p===o}async function Gt(e,t,i){if(!t.resolvedPaths.tailwindCss||!e||Object.keys(e).length===0)return;i={silent:false,...i};let r=t.resolvedPaths.tailwindCss,o=E__default.relative(t.resolvedPaths.cwd,r),n=s(`Updating ${d.info(o)}`,{silent:i.silent}).start(),a=await promises.readFile(r,"utf8"),s$1=await Zr(a,e);await promises.writeFile(r,s$1,"utf8"),n.succeed();}async function Zr(e,t){let i=[Qr(t)],r=await x(i).process(e,{from:void 0}),o=r.css,n=r.root;if(n.nodes&&n.nodes.length>0){let a=n.nodes[n.nodes.length-1];a.type==="atrule"&&!a.nodes&&!o.trimEnd().endsWith(";")&&(o=o.trimEnd()+";");}return o=o.replace(/\/\* ---break--- \*\//g,""),o=o.replace(/(\n\s*\n)+/g,`
9
9
 
10
10
  `),o=o.trimEnd(),o}function Qr(e){return {postcssPlugin:"update-css",Once(t){for(let[i,r]of Object.entries(e))if(i.startsWith("@")){let o=i.match(/@([a-zA-Z-]+)\s*(.*)/);if(!o)continue;let[,n,a]=o;if(n==="import"){if(!t.nodes?.find(c=>c.type==="atrule"&&c.name==="import"&&c.params===a)){let c=x.atRule({name:"import",params:a,raws:{semicolon:true}}),m=t.nodes?.filter(l=>l.type==="atrule"&&l.name==="import");if(m&&m.length>0){let l=m[m.length-1];c.raws.before=`
11
11
  `,t.insertAfter(l,c);}else !t.nodes||t.nodes.length,c.raws.before="",t.prepend(c);}}else if(n==="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(!t.nodes?.find(l=>l.type!=="atrule"||l.name!=="plugin"?false:c(l.params)===c(a))){let l=x.atRule({name:"plugin",params:s,raws:{semicolon:true,before:`
@@ -83,5 +83,5 @@ args = ["shadcn@${ce}", "mcp"]`),r.break(),r.info("3. Restart Codex to load the
83
83
  `).map(k=>{if(k.trim().startsWith("import "))return k;let S=k;return S=S.replace(/\b(asChild\s*\?\s*)Slot(\s*:)/g,"$1__SLOT_PLACEHOLDER__$2"),S=S.replace(/\bReact\.ComponentProps<typeof\s+Slot>/g,"React.ComponentProps<typeof __SLOT_PLACEHOLDER__>"),S=S.replace(/\bComponentProps<typeof\s+Slot>/g,"ComponentProps<typeof __SLOT_PLACEHOLDER__>"),S=S.replace(/(<\/?)Slot(\s*\/?>)/g,"$1__SLOT_PLACEHOLDER__$2"),S=S.replace(/\bSlot\b/g,(B,T,Y)=>{let O=Y.substring(0,T),Fe=(O.match(/"/g)||[]).length,Dr=(O.match(/'/g)||[]).length;return Fe%2!==0||Dr%2!==0?B:"__SLOT_PLACEHOLDER__"}),S=S.replace(/__SLOT_PLACEHOLDER__/g,"SlotPrimitive.Slot"),S}).join(`
84
84
  `));let g=Array.from(new Set(o));return {content:s,replacedPackages:g}}async function Sr(e){let t={};if(!v.existsSync(e.cwd)||!v.existsSync(E__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,config:null};if(!v.existsSync(E__default.resolve(e.cwd,"components.json")))return t["3"]=true,{errors:t,config:null};try{let i$1=await i(e.cwd);return {errors:t,config:i$1}}catch{r.break(),r.error(`An invalid ${d.info("components.json")} file was found at ${d.info(e.cwd)}.
85
85
  Before you can run a migration, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),r.error(`Learn more at ${d.info("https://ui.shadcn.com/docs/components-json")}.`),r.break(),process.exit(1);}}var Rr=[{name:"icons",description:"migrate your ui components to a different icon library."},{name:"radix",description:"migrate to radix-ui."}],$o=z$1.object({cwd:z$1.string(),list:z$1.boolean(),yes:z$1.boolean(),migration:z$1.string().refine(e=>e&&Rr.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional()}),Cr=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(e,t)=>{try{let i=$o.parse({cwd:E__default.resolve(t.cwd),migration:e,list:t.list,yes:t.yes});if(i.list||!i.migration){r.info("Available migrations:");for(let n of Rr)r.info(`- ${n.name}: ${n.description}`);return}if(!i.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:r$1,config:o}=await Sr(i);if(r$1["1"]||r$1["3"])throw new Error("No `components.json` file found. Ensure you are at the root of your project.");if(!o)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");i.migration==="icons"&&await br(o),i.migration==="radix"&&await xr(o,{yes:i.yes});}catch(i){r.break(),V$1(i);}});async function Ir(e){let t={},i$1={cwd:e.cwd,registryFile:E__default.resolve(e.cwd,e.registryFile),outputDir:E__default.resolve(e.cwd,e.outputDir)};if(!v.existsSync(i$1.registryFile))return t["13"]=true,{errors:t,resolvePaths:null,config:null};if(!v.existsSync(E__default.resolve(e.cwd,"components.json")))return t["3"]=true,{errors:t,resolvePaths:null,config:null};await v.mkdir(i$1.outputDir,{recursive:true});try{let r=await i(e.cwd);return {errors:t,config:r,resolvePaths:i$1}}catch{r.break(),r.error(`An invalid ${d.info("components.json")} file was found at ${d.info(e.cwd)}.
86
- Before you can build the registry, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),r.break(),process.exit(1);}}var Oo=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),kr=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(e,t)=>{await Fo({cwd:E.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function Fo(e){try{let t=Oo.parse(e),[{errors:i,resolvePaths:r$1,config:o$2},n$1]=await Promise.all([Ir(t),o(t.cwd)]);(i["3"]||!o$2||!n$1)&&(r.error(`A ${d.info("components.json")} file is required to build the registry. Run ${d.info("shadcn init")} to create one.`),r.break(),process.exit(1)),(i["13"]||!r$1)&&(r.error(`We could not find a registry file at ${d.info(E.resolve(t.cwd,t.registryFile))}.`),r.break(),process.exit(1));let a=await z.readFile(r$1.registryFile,"utf-8"),s$1=o$1.safeParse(JSON.parse(a));s$1.success||(r.error(`Invalid registry file found at ${d.info(r$1.registryFile)}.`),r.break(),process.exit(1));let c=s("Building registry..."),m=await Ao(s$1.data,o$2,n$1);for(let l of m.items)l.files=l.files?.filter((p,u,g)=>u===g.findIndex(h=>h.path===p.path)),l.dependencies&&(l.dependencies=l.dependencies.filter((p,u,g)=>u===g.findIndex(h=>h===p)));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 u of l.files){let g=E.resolve(r$1.cwd,u.path);try{if(!(await z.stat(g)).isFile())continue;u.content=await z.readFile(g,"utf-8");}catch(h){console.error("Error reading file in registry build:",g,h);continue}}let p=n.safeParse(l);if(!p.success){r.error(`Invalid registry item found for ${d.info(l.name)}.`);continue}await z.writeFile(E.resolve(r$1.outputDir,`${p.data.name}.json`),JSON.stringify(p.data,null,2));}if(await z.copyFile(r$1.registryFile,E.resolve(r$1.outputDir,"registry.json")),c.succeed("Building registry."),t.verbose){s(`The registry has ${d.info(m.items.length.toString())} items:`).succeed();for(let l of m.items){r.log(` - ${l.name} (${d.info(l.type)})`);for(let p of l.files??[])r.log(` - ${p.path}`);}}}catch(t){r.break(),V$1(t);}}async function Ao(e,t,i){for(let r of e.items)if(r.files?.length)for(let o of r.files){let n=await K(o.path,t,i);n.files=n.files?.filter(a=>a.path!==o.path),n.files&&r.files.push(...n.files),n.dependencies&&(r.dependencies=r.dependencies?r.dependencies.concat(n.dependencies):n.dependencies);}return e}var Pr=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()=>{r.warn(`The ${d.info("shadcn registry:mcp")} command is deprecated. Use the ${d.info("shadcn mcp")} command instead.`),r.break();});var Lo=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),Nr=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(e,t)=>{try{let i$1=Lo.parse({cwd:E__default.resolve(t.cwd),query:t.query,limit:t.limit?parseInt(t.limit,10):void 0,offset:t.offset?parseInt(t.offset,10):void 0});await L(i$1.cwd);let r=m({style:"new-york",resolvedPaths:{cwd:i$1.cwd}}),o=N(r),n=E__default.resolve(i$1.cwd,"components.json");if(v.existsSync(n)){let l=await v.readJson(n),p=c.partial().parse(l);o=N({...r,...p});}let a=o;try{let l=await i(i$1.cwd);l&&(a=N(l));}catch{}let{config:s,newRegistries:c$1}=await V(e.map(l=>`${l}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),P(e,a);let m$1=await ja(e,{query:i$1.query,limit:i$1.limit,offset:i$1.offset,config:a});console.log(JSON.stringify(m$1,null,2)),process.exit(0);}catch(i){V$1(i);}finally{O();}});var Wo=z$1.object({cwd:z$1.string()}),Fr=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(e,t)=>{try{let i$1=Wo.parse({cwd:E__default.resolve(t.cwd)});await L(i$1.cwd);let r=N({}),o=E__default.resolve(i$1.cwd,"components.json");if(v.existsSync(o)){let m=await v.readJson(o),l=c.partial().parse(m);r=N(l);}let n=r;try{let m=await i(i$1.cwd);m&&(n=N(m));}catch{}let{config:a,newRegistries:s}=await V(e,n,{silent:!0,writeFile:!1});s.length>0&&(n.registries=a.registries),P(e,n);let c$1=await X(e,{config:n});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(i){V$1(i);}finally{O();}});var Ar={version:"3.6.22"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Bo(){let e=new Command().name("shadcn").description("add items from registries to your project").version(Ar.version,"-v, --version","display the version number");e.addCommand(zt).addCommand(mr).addCommand(ir).addCommand(dr).addCommand(Fr).addCommand(Nr).addCommand(Cr).addCommand(ur).addCommand(ar).addCommand(Qe),e.addCommand(kr).addCommand(Pr),e.parse();}Bo();//# sourceMappingURL=index.js.map
86
+ Before you can build the registry, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),r.break(),process.exit(1);}}var Oo=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),kr=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(e,t)=>{await Fo({cwd:E.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function Fo(e){try{let t=Oo.parse(e),[{errors:i,resolvePaths:r$1,config:o$2},n$1]=await Promise.all([Ir(t),o(t.cwd)]);(i["3"]||!o$2||!n$1)&&(r.error(`A ${d.info("components.json")} file is required to build the registry. Run ${d.info("shadcn init")} to create one.`),r.break(),process.exit(1)),(i["13"]||!r$1)&&(r.error(`We could not find a registry file at ${d.info(E.resolve(t.cwd,t.registryFile))}.`),r.break(),process.exit(1));let a=await z.readFile(r$1.registryFile,"utf-8"),s$1=o$1.safeParse(JSON.parse(a));s$1.success||(r.error(`Invalid registry file found at ${d.info(r$1.registryFile)}.`),r.break(),process.exit(1));let c=s("Building registry..."),m=await Ao(s$1.data,o$2,n$1);for(let l of m.items)l.files=l.files?.filter((p,u,g)=>u===g.findIndex(h=>h.path===p.path)),l.dependencies&&(l.dependencies=l.dependencies.filter((p,u,g)=>u===g.findIndex(h=>h===p)));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 u of l.files){let g=E.resolve(r$1.cwd,u.path);try{if(!(await z.stat(g)).isFile())continue;u.content=await z.readFile(g,"utf-8");}catch(h){console.error("Error reading file in registry build:",g,h);continue}}let p=n.safeParse(l);if(!p.success){r.error(`Invalid registry item found for ${d.info(l.name)}.`);continue}await z.writeFile(E.resolve(r$1.outputDir,`${p.data.name}.json`),JSON.stringify(p.data,null,2));}if(await z.copyFile(r$1.registryFile,E.resolve(r$1.outputDir,"registry.json")),c.succeed("Building registry."),t.verbose){s(`The registry has ${d.info(m.items.length.toString())} items:`).succeed();for(let l of m.items){r.log(` - ${l.name} (${d.info(l.type)})`);for(let p of l.files??[])r.log(` - ${p.path}`);}}}catch(t){r.break(),V$1(t);}}async function Ao(e,t,i){for(let r of e.items)if(r.files?.length)for(let o of r.files){let n=await K(o.path,t,i);n.files=n.files?.filter(a=>a.path!==o.path),n.files&&r.files.push(...n.files),n.dependencies&&(r.dependencies=r.dependencies?r.dependencies.concat(n.dependencies):n.dependencies);}return e}var Pr=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()=>{r.warn(`The ${d.info("shadcn registry:mcp")} command is deprecated. Use the ${d.info("shadcn mcp")} command instead.`),r.break();});var Lo=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),Nr=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(e,t)=>{try{let i$1=Lo.parse({cwd:E__default.resolve(t.cwd),query:t.query,limit:t.limit?parseInt(t.limit,10):void 0,offset:t.offset?parseInt(t.offset,10):void 0});await L(i$1.cwd);let r=m({style:"new-york",resolvedPaths:{cwd:i$1.cwd}}),o=N(r),n=E__default.resolve(i$1.cwd,"components.json");if(v.existsSync(n)){let l=await v.readJson(n),p=c.partial().parse(l);o=N({...r,...p});}let a=o;try{let l=await i(i$1.cwd);l&&(a=N(l));}catch{}let{config:s,newRegistries:c$1}=await V(e.map(l=>`${l}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),P(e,a);let m$1=await ja(e,{query:i$1.query,limit:i$1.limit,offset:i$1.offset,config:a});console.log(JSON.stringify(m$1,null,2)),process.exit(0);}catch(i){V$1(i);}finally{O();}});var Wo=z$1.object({cwd:z$1.string()}),Fr=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(e,t)=>{try{let i$1=Wo.parse({cwd:E__default.resolve(t.cwd)});await L(i$1.cwd);let r=N({}),o=E__default.resolve(i$1.cwd,"components.json");if(v.existsSync(o)){let m=await v.readJson(o),l=c.partial().parse(m);r=N(l);}let n=r;try{let m=await i(i$1.cwd);m&&(n=N(m));}catch{}let{config:a,newRegistries:s}=await V(e,n,{silent:!0,writeFile:!1});s.length>0&&(n.registries=a.registries),P(e,n);let c$1=await X(e,{config:n});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(i){V$1(i);}finally{O();}});var Ar={version:"3.6.24"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Bo(){let e=new Command().name("shadcn").description("add items from registries to your project").version(Ar.version,"-v, --version","display the version number");e.addCommand(zt).addCommand(mr).addCommand(ir).addCommand(dr).addCommand(Fr).addCommand(Nr).addCommand(Cr).addCommand(ur).addCommand(ar).addCommand(Qe),e.addCommand(kr).addCommand(Pr),e.parse();}Bo();//# sourceMappingURL=index.js.map
87
87
  //# sourceMappingURL=index.js.map