shadcn 0.0.0-beta.58be5c4 → 0.0.0-beta.8ea4ab5

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,22 +1,29 @@
1
1
  #!/usr/bin/env node
2
- import jr from"path";import{promises as vr}from"fs";import rt from"path";import Ie from"path";var R="1";var V="3";var ne="5",se="6",Se="7";import oe from"path";var C={"next-app":{name:"next-app",label:"Next.js",links:{installation:"https://ui.shadcn.com/docs/installation/next",tailwind:"https://tailwindcss.com/docs/guides/nextjs"}},"next-pages":{name:"next-pages",label:"Next.js",links:{installation:"https://ui.shadcn.com/docs/installation/next",tailwind:"https://tailwindcss.com/docs/guides/nextjs"}},remix:{name:"remix",label:"Remix",links:{installation:"https://ui.shadcn.com/docs/installation/remix",tailwind:"https://tailwindcss.com/docs/guides/remix"}},vite:{name:"vite",label:"Vite",links:{installation:"https://ui.shadcn.com/docs/installation/vite",tailwind:"https://tailwindcss.com/docs/guides/vite"}},astro:{name:"astro",label:"Astro",links:{installation:"https://ui.shadcn.com/docs/installation/astro",tailwind:"https://tailwindcss.com/docs/guides/astro"}},laravel:{name:"laravel",label:"Laravel",links:{installation:"https://ui.shadcn.com/docs/installation/laravel",tailwind:"https://tailwindcss.com/docs/guides/laravel"}},gatsby:{name:"gatsby",label:"Gatsby",links:{installation:"https://ui.shadcn.com/docs/installation/gatsby",tailwind:"https://tailwindcss.com/docs/guides/gatsby"}},manual:{name:"manual",label:"Manual",links:{installation:"https://ui.shadcn.com/docs/installation/manual",tailwind:"https://tailwindcss.com/docs/installation"}}};import $ from"path";import{cyan as dt,green as ut,red as gt,yellow as ht}from"kleur/colors";var l={error:gt,warn:ht,info:dt,success:ut};import{createMatchPath as yt}from"tsconfig-paths";async function P(e,t){return yt(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}import{cosmiconfig as wt}from"cosmiconfig";import{loadConfig as xt}from"tsconfig-paths";import{z as g}from"zod";var Ce="@/components",Pe="@/lib/utils",ve="app/globals.css",Re="tailwind.config.js";var bt=wt("components",{searchPlaces:["components.json"]}),O=g.object({$schema:g.string().optional(),style:g.string(),rsc:g.coerce.boolean().default(!1),tsx:g.coerce.boolean().default(!0),tailwind:g.object({config:g.string(),css:g.string(),baseColor:g.string(),cssVariables:g.boolean().default(!0),prefix:g.string().default("").optional()}),aliases:g.object({components:g.string(),utils:g.string(),ui:g.string().optional(),lib:g.string().optional(),hooks:g.string().optional()})}).strict(),St=O.extend({resolvedPaths:g.object({cwd:g.string(),tailwindConfig:g.string(),tailwindCss:g.string(),utils:g.string(),components:g.string(),lib:g.string(),hooks:g.string(),ui:g.string()})});async function T(e){let t=await Ct(e);return t?await N(e,t):null}async function N(e,t){let r=await xt(e);if(r.resultType==="failed")throw new Error(`Failed to load ${t.tsx?"tsconfig":"jsconfig"}.json. ${r.message??""}`.trim());return St.parse({...t,resolvedPaths:{cwd:e,tailwindConfig:$.resolve(e,t.tailwind.config),tailwindCss:$.resolve(e,t.tailwind.css),utils:await P(t.aliases.utils,r),components:await P(t.aliases.components,r),ui:t.aliases.ui?await P(t.aliases.ui,r):$.resolve(await P(t.aliases.components,r)??e,"ui"),lib:t.aliases.lib?await P(t.aliases.lib,r):$.resolve(await P(t.aliases.utils,r)??e,".."),hooks:t.aliases.hooks?await P(t.aliases.hooks,r):$.resolve(await P(t.aliases.components,r)??e,"..","hooks")}})}async function Ct(e){try{let t=await bt.search(e);return t?O.parse(t.config):null}catch{let r=`${e}/component.json`;throw new Error(`Invalid configuration found in ${l.info(r)}.`)}}import U from"fast-glob";import ae from"fs-extra";import{loadConfig as Pt}from"tsconfig-paths";var G=["**/node_modules/**",".next","public","dist","build"];async function A(e){let[t,r,i,n,s,a]=await Promise.all([U.glob("**/{next,vite,astro}.config.*|gatsby-config.*|composer.json",{cwd:e,deep:3,ignore:G}),ae.pathExists(oe.resolve(e,"src")),It(e),Rt(e),vt(e),Tt(e)]),c=await ae.pathExists(oe.resolve(e,`${r?"src/":""}app`)),m={framework:C.manual,isSrcDir:r,isRSC:!1,isTsx:i,tailwindConfigFile:n,tailwindCssFile:s,aliasPrefix:a};return t.length?t.find(f=>f.startsWith("next.config."))?.length?(m.framework=c?C["next-app"]:C["next-pages"],m.isRSC=c,m):t.find(f=>f.startsWith("astro.config."))?.length?(m.framework=C.astro,m):t.find(f=>f.startsWith("gatsby-config."))?.length?(m.framework=C.gatsby,m):t.find(f=>f.startsWith("composer.json"))?.length?(m.framework=C.laravel,m):(t.find(f=>f.startsWith("vite.config."))?.length&&(m.framework=c?C.remix:C.vite),m):m}async function vt(e){let t=await U.glob("**/*.css",{cwd:e,deep:5,ignore:G});if(!t.length)return null;for(let r of t)if((await ae.readFile(oe.resolve(e,r),"utf8")).includes("@tailwind base"))return r;return null}async function Rt(e){let t=await U.glob("tailwind.config.*",{cwd:e,deep:3,ignore:G});return t.length?t[0]:null}async function Tt(e){let t=await Pt(e);if(t?.resultType==="failed"||!t?.paths)return null;for(let[r,i]of Object.entries(t.paths))if(i.includes("./*")||i.includes("./src/*")||i.includes("./app/*")||i.includes("./resources/js/*"))return r.at(0)??null;return null}async function It(e){return(await U.glob("tsconfig.*",{cwd:e,deep:1,ignore:G})).length>0}async function Te(e,t=null){let[r,i]=await Promise.all([T(e),t?Promise.resolve(t):A(e)]);if(r)return r;if(!i||!i.tailwindConfigFile||!i.tailwindCssFile)return null;let n={$schema:"https://ui.shadcn.com/schema.json",rsc:i.isRSC,tsx:i.isTsx,style:"new-york",tailwind:{config:i.tailwindConfigFile,baseColor:"zinc",css:i.tailwindCssFile,cssVariables:!0,prefix:""},aliases:{components:`${i.aliasPrefix}/components`,ui:`${i.aliasPrefix}/components/ui`,hooks:`${i.aliasPrefix}/hooks`,lib:`${i.aliasPrefix}/lib`,utils:`${i.aliasPrefix}/lib/utils`}};return await N(e,n)}var o={error(...e){console.log(l.error(e.join(" ")))},warn(...e){console.log(l.warn(e.join(" ")))},info(...e){console.log(l.info(e.join(" ")))},success(...e){console.log(l.success(e.join(" ")))},log(...e){console.log(e.join(" "))},break(){console.log("")}};import kt from"ora";function w(e,t){return kt({text:e,isSilent:t?.silent})}import le from"fs-extra";async function ke(e){let t={};if(!le.existsSync(e.cwd)||!le.existsSync(Ie.resolve(e.cwd,"package.json")))return t[R]=!0,{errors:t,projectInfo:null};let r=w("Preflight checks.",{silent:e.silent}).start();le.existsSync(Ie.resolve(e.cwd,"components.json"))&&!e.force&&(r?.fail(),o.break(),o.error(`A ${l.info("components.json")} file already exists at ${l.info(e.cwd)}.
3
- To start over, remove the ${l.info("components.json")} file and run ${l.info("init")} again.`),o.break(),process.exit(1)),r?.succeed();let i=w("Verifying framework.",{silent:e.silent}).start(),n=await A(e.cwd);(!n||n?.framework.name==="manual")&&(t[Se]=!0,i?.fail(),o.break(),n?.framework.links.installation&&o.error(`We could not detect a supported framework at ${l.info(e.cwd)}.
4
- Visit ${l.info(n?.framework.links.installation)} to manually configure your project.
5
- Once configured, you can use the cli to add components.`),o.break(),process.exit(1)),i?.succeed(`Verifying framework. Found ${l.info(n.framework.label)}.`);let s=w("Validating Tailwind CSS.",{silent:e.silent}).start();!n?.tailwindConfigFile||!n?.tailwindCssFile?(t[ne]=!0,s?.fail()):s?.succeed();let a=w("Validating import alias.",{silent:e.silent}).start();return n?.aliasPrefix?a?.succeed():(t[se]=!0,a?.fail()),Object.keys(t).length>0&&(t[ne]&&(o.break(),o.error(`No Tailwind CSS configuration found at ${l.info(e.cwd)}.`),o.error("It is likely you do not have Tailwind CSS installed or have an invalid configuration."),o.error("Install Tailwind CSS then try again."),n?.framework.links.tailwind&&o.error(`Visit ${l.info(n?.framework.links.tailwind)} to get started.`)),t[se]&&(o.break(),o.error("No import alias found in your tsconfig.json file."),n?.framework.links.installation&&o.error(`Visit ${l.info(n?.framework.links.installation)} to learn how to set an import alias.`)),o.break(),process.exit(1)),{errors:t,projectInfo:n}}import{z as Et}from"zod";function b(e){if(o.error("Something went wrong. Please check the error below for more details."),o.error("If the problem persists, please open an issue on GitHub."),o.error(""),typeof e=="string"&&(o.error(e),o.break(),process.exit(1)),e instanceof Et.ZodError){o.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))o.error(`- ${l.info(t)}: ${r}`);o.break(),process.exit(1)}e instanceof Error&&(o.error(e.message),o.break(),process.exit(1)),o.break(),process.exit(1)}import Mt from"path";import{z as p}from"zod";var Ee=p.enum(["registry:style","registry:lib","registry:example","registry:block","registry:component","registry:ui","registry:hook","registry:theme","registry:page"]),je=p.object({path:p.string(),content:p.string().optional(),type:Ee,target:p.string().optional()}),jt=p.object({config:p.object({content:p.array(p.string()).optional(),theme:p.record(p.string(),p.any()).optional(),plugins:p.array(p.string()).optional()}).optional()}),$t=p.object({light:p.record(p.string(),p.string()).optional(),dark:p.record(p.string(),p.string()).optional()}),F=p.object({name:p.string(),type:Ee,description:p.string().optional(),dependencies:p.array(p.string()).optional(),devDependencies:p.array(p.string()).optional(),registryDependencies:p.array(p.string()).optional(),files:p.array(je).optional(),tailwind:jt.optional(),cssVars:$t.optional(),meta:p.record(p.string(),p.any()).optional()}),ce=p.array(F.extend({files:p.array(p.union([p.string(),je])).optional()})),$e=p.array(p.object({name:p.string(),label:p.string()})),Oe=p.object({inlineColors:p.object({light:p.record(p.string(),p.string()),dark:p.record(p.string(),p.string())}),cssVars:p.object({light:p.record(p.string(),p.string()),dark:p.record(p.string(),p.string())}),inlineColorsTemplate:p.string(),cssVarsTemplate:p.string()}),Ne=F.pick({dependencies:!0,devDependencies:!0,files:!0,tailwind:!0,cssVars:!0});import{promises as pe}from"fs";import{tmpdir as Ot}from"os";import L from"path";import Nt from"deepmerge";import At from"stringify-object";import{Project as Ft,QuoteKind as Lt,ScriptKind as Ae,SyntaxKind as u}from"ts-morph";async function Fe(e,t,r){if(!e)return;r={silent:!1,...r};let i=L.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=w(`Updating ${l.info(i)}`,{silent:r.silent}).start(),s=await pe.readFile(t.resolvedPaths.tailwindConfig,"utf8"),a=await _t(s,e,t);await pe.writeFile(t.resolvedPaths.tailwindConfig,a,"utf8"),n?.succeed()}async function _t(e,t,r){let i=await Le(e,r),n=i.getDescendantsOfKind(u.ObjectLiteralExpression).find(a=>a.getProperties().some(c=>c.isKind(u.PropertyAssignment)&&c.getName()==="content"));if(!n)return e;let s=Wt(n);return Dt(n,{name:"darkMode",value:"class"},{quoteChar:s}),t.plugins?.forEach(a=>{Kt(n,a)}),t.theme&&await zt(n,t.theme),i.getFullText()}function Dt(e,t,{quoteChar:r}){let i=e.getProperty("darkMode");if(!i){let n={name:t.name,initializer:`[${r}${t.value}${r}]`};return t.name==="darkMode"?(e.insertPropertyAssignment(0,n),e):(e.addPropertyAssignment(n),e)}if(i.isKind(u.PropertyAssignment)){let n=i.getInitializer(),s=`${r}${t.value}${r}`;if(n?.isKind(u.StringLiteral)){let a=n.getText();return n.replaceWithText(`[${a}, ${s}]`),e}if(n?.isKind(u.ArrayLiteralExpression)){if(n.getElements().map(a=>a.getText()).includes(s))return e;n.addElement(s)}return e}return e}async function zt(e,t){e.getProperty("theme")||e.addPropertyAssignment({name:"theme",initializer:"{}"}),_e(e);let i=(e.getPropertyOrThrow("theme")?.asKindOrThrow(u.PropertyAssignment)).getInitializer();if(i?.isKind(u.ObjectLiteralExpression)){let n=i.getText(),s=await Vt(n),a=Nt(s,t),c=At(a).replace(/\'\"/g,"'").replace(/\"\'/g,"'").replace(/\'\[/g,"[").replace(/\]\'/g,"]").replace(/\\\'/g,"").replace(/\\\'/g,"");i.replaceWithText(c)}De(e)}function Kt(e,t){let r=e.getProperty("plugins");if(!r)return e.addPropertyAssignment({name:"plugins",initializer:`[${t}]`}),e;if(r.isKind(u.PropertyAssignment)){let i=r.getInitializer();if(i?.isKind(u.ArrayLiteralExpression)){if(i.getElements().map(n=>n.getText().replace(/["']/g,"")).includes(t.replace(/["']/g,"")))return e;i.addElement(t)}return e}return e}async function Le(e,t){let r=await pe.mkdtemp(L.join(Ot(),"shadcn-")),i=t?.resolvedPaths?.tailwindConfig||"tailwind.config.ts",n=L.join(r,`shadcn-${L.basename(i)}`);return new Ft({compilerOptions:{}}).createSourceFile(n,e,{scriptKind:L.extname(i)===".ts"?Ae.TS:Ae.JS})}function Wt(e){return e.getFirstDescendantByKind(u.StringLiteral)?.getQuoteKind()===Lt.Single?"'":'"'}function _e(e){let t=e.getProperties();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(u.SpreadAssignment)){let n=i.asKindOrThrow(u.SpreadAssignment),s=n.getExpression().getText();e.insertPropertyAssignment(r,{name:`___${s.replace(/^\.\.\./,"")}`,initializer:`"...${s.replace(/^\.\.\./,"")}"`}),n.remove()}else if(i.isKind(u.PropertyAssignment)){let s=i.asKindOrThrow(u.PropertyAssignment).getInitializer();s&&s.isKind(u.ObjectLiteralExpression)&&_e(s.asKindOrThrow(u.ObjectLiteralExpression))}}}function De(e){let t=e.getProperties();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(u.PropertyAssignment)){let n=i,s=n.getInitializer();if(s?.isKind(u.StringLiteral)){let a=s.getLiteralValue();a.startsWith("...")&&(e.insertSpreadAssignment(r,{expression:a.slice(3)}),n.remove())}else s?.isKind(u.ObjectLiteralExpression)&&De(s)}}}async function Vt(e){let r=(await Le(`const theme = ${e}`,null)).getStatements()[0];if(r?.getKind()===u.VariableStatement){let n=(r.getDeclarationList()?.getDeclarations()[0]).getInitializer();if(n?.isKind(u.ObjectLiteralExpression))return await ze(n)}throw new Error("Invalid input: not an object literal")}function ze(e){let t={};for(let r of e.getProperties())if(r.isKind(u.PropertyAssignment)){let i=r.getName().replace(/\'/g,"");r.getInitializer()?.isKind(u.ObjectLiteralExpression)?t[i]=ze(r.getInitializer()):t[i]=Ke(r.getInitializer())}return t}function Ke(e){switch(e.kind){case u.StringLiteral:return e.text;case u.NumericLiteral:return Number(e.text);case u.TrueKeyword:return!0;case u.FalseKeyword:return!1;case u.NullKeyword:return null;case u.ArrayLiteralExpression:return e.elements.map(Ke);default:return e.getText()}}function We(e){let t={};for(let r of Object.keys(e)){let i=r.split("-"),n=i[0],s=i.slice(1).join("-");s===""?typeof t[n]=="object"?t[n].DEFAULT=`hsl(var(--${r}))`:t[n]=`hsl(var(--${r}))`:(typeof t[n]!="object"&&(t[n]={DEFAULT:`hsl(var(--${n}))`}),t[n][s]=`hsl(var(--${r}))`)}for(let[r,i]of Object.entries(t))typeof i=="object"&&i.DEFAULT===`hsl(var(--${r}))`&&!(r in e)&&delete i.DEFAULT;return t}import _ from"deepmerge";import{HttpsProxyAgent as Ut}from"https-proxy-agent";import Gt from"node-fetch";import{z as Bt}from"zod";var Jt=process.env.REGISTRY_URL??"https://ui-private-www-git-shadcn-cli-2-shadcn-pro.vercel.app/r",Yt=process.env.https_proxy?new Ut(process.env.https_proxy):void 0;async function D(){try{let[e]=await E(["index.json"]);return ce.parse(e)}catch(e){o.error(`
6
- `),b(e)}}async function me(){try{let[e]=await E(["styles/index.json"]);return $e.parse(e)}catch(e){return o.error(`
7
- `),b(e),[]}}async function B(e,t){try{let[r]=await E([de(e)?e:`styles/${t}/${e}.json`]);return F.parse(r)}catch(r){return o.break(),b(r),null}}async function fe(){return[{name:"neutral",label:"Neutral"},{name:"gray",label:"Gray"},{name:"zinc",label:"Zinc"},{name:"stone",label:"Stone"},{name:"slate",label:"Slate"}]}async function z(e){try{let[t]=await E([`colors/${e}.json`]);return Oe.parse(t)}catch(t){b(t)}}async function Ve(e,t){try{let r=t.map(n=>`styles/${e}/${n.name}.json`),i=await E(r);return ce.parse(i)}catch(r){b(r)}}async function Me(e,t,r){if(r)return r;if(t.type==="registry:ui")return e.resolvedPaths.ui??e.resolvedPaths.components;let[i,n]=t.type?.split(":")??[];return i in e.resolvedPaths?Mt.join(e.resolvedPaths[i],n):null}async function E(e){try{return await Promise.all(e.map(async r=>{let i=Be(r),n=await Gt(i,{agent:Yt});if(!n.ok){let s={400:"Bad request",401:"Unauthorized",403:"Forbidden",404:"Not found",500:"Internal server error"},a=await n.json(),c=a&&typeof a=="object"&&"error"in a?a.error:n.statusText||s[n.status];throw new Error(`Failed to fetch from ${l.info(i)}.
8
- ${c}`)}return n.json()}))}catch(t){return o.error(`
9
- `),b(t),[]}}function Ue(e,t,r){return r||(e.type==="registry:ui"?t.resolvedPaths.ui:e.type==="registry:lib"?t.resolvedPaths.lib:e.type==="registry:block"||e.type==="registry:component"?t.resolvedPaths.components:e.type==="registry:hook"?t.resolvedPaths.hooks:(e.type==="registry:page",t.resolvedPaths.components))}async function Ge(e,t){try{if(!await D())return null;let i=(await Promise.all(e.map(async d=>await B(d,t.style)))).filter(d=>d!==null);if(!i.length)return null;let n=i.map(d=>d.registryDependencies??[]).flat(),s=Array.from(new Set(n)),a=Array.from([...e,...s]).map(d=>Be(de(d)?d:`styles/${t.style}/${d}.json`)),c=await E(a),m=Bt.array(F).parse(c);if(!m)return null;if(e.includes("index")){let d=await B("index",t.style);if(d&&m.unshift(d),t.tailwind.baseColor){let y=await Ht(t.tailwind.baseColor,t);y&&m.unshift(y)}}let f={};m.forEach(d=>{f=_(f,d.tailwind??{})});let x={};return m.forEach(d=>{x=_(x,d.cssVars??{})}),Ne.parse({dependencies:_.all(m.map(d=>d.dependencies??[])),devDependencies:_.all(m.map(d=>d.devDependencies??[])),files:_.all(m.map(d=>d.files??[])),tailwind:f,cssVars:x})}catch(r){return b(r),null}}async function Ht(e,t){let r=await z(e);if(!r)return null;let i={name:e,type:"registry:theme",tailwind:{config:{theme:{extend:{borderRadius:{lg:"var(--radius)",md:"calc(var(--radius) - 2px)",sm:"calc(var(--radius) - 4px)"},colors:{}}}}},cssVars:{light:{radius:"0.5rem"},dark:{}}};return t.tailwind.cssVariables&&(i.tailwind.config.theme.extend.colors={...i.tailwind.config.theme.extend.colors,...We(r.cssVars.dark)},i.cssVars={light:{...r.cssVars.light,...i.cssVars.light},dark:{...r.cssVars.dark,...i.cssVars.dark}}),i}function Be(e){if(de(e)){let t=new URL(e);return t.pathname.match(/\/chat\/b\//)&&!t.pathname.endsWith("/json")&&(t.pathname=`${t.pathname}/json`),t.toString()}return`${Jt}/${e}`}function de(e){try{return new URL(e),!0}catch{return!1}}import{promises as Je}from"fs";import Qt from"path";import k from"postcss";import Xt from"postcss/lib/at-rule";async function Ye(e,t,r){if(!e||!Object.keys(e).length||!t.resolvedPaths.tailwindCss)return;r={cleanupDefaultNextStyles:!1,silent:!1,...r};let i=t.resolvedPaths.tailwindCss,n=Qt.relative(t.resolvedPaths.cwd,i),s=w(`Updating ${l.info(n)}`,{silent:r.silent}).start(),a=await Je.readFile(i,"utf8"),c=await Zt(a,e,t,{cleanupDefaultNextStyles:r.cleanupDefaultNextStyles});await Je.writeFile(i,c,"utf8"),s.succeed()}async function Zt(e,t,r,i){i={cleanupDefaultNextStyles:!1,...i};let n=[er(t)];return i.cleanupDefaultNextStyles&&n.push(tr()),r.tailwind.cssVariables&&n.push(qt()),(await k(n).process(e,{from:void 0})).css}function qt(){return{postcssPlugin:"update-base-layer",Once(e){let t=[{selector:"*",apply:"border-border"},{selector:"body",apply:"bg-background text-foreground"}],r=e.nodes.find(i=>i.type==="atrule"&&i.name==="layer"&&i.params==="base"&&t.every(({selector:n,apply:s})=>i.nodes?.some(a=>a.type==="rule"&&a.selector===n&&a.nodes.some(c=>c.type==="atrule"&&c.name==="apply"&&c.params===s))));r||(r=k.atRule({name:"layer",params:"base",raws:{semicolon:!0,between:" ",before:`
10
- `}}),e.append(r)),t.forEach(({selector:i,apply:n})=>{r?.nodes?.find(a=>a.type==="rule"&&a.selector===i)||r?.append(k.rule({selector:i,nodes:[k.atRule({name:"apply",params:n,raws:{semicolon:!0,before:`
2
+ import Br from"path";import{promises as Kr}from"fs";import ct from"path";import $e from"path";var k="1";var V="3";var oe="5",ae="6",Re="7";import le from"path";var v={"next-app":{name:"next-app",label:"Next.js",links:{installation:"https://ui.shadcn.com/docs/installation/next",tailwind:"https://tailwindcss.com/docs/guides/nextjs"}},"next-pages":{name:"next-pages",label:"Next.js",links:{installation:"https://ui.shadcn.com/docs/installation/next",tailwind:"https://tailwindcss.com/docs/guides/nextjs"}},remix:{name:"remix",label:"Remix",links:{installation:"https://ui.shadcn.com/docs/installation/remix",tailwind:"https://tailwindcss.com/docs/guides/remix"}},vite:{name:"vite",label:"Vite",links:{installation:"https://ui.shadcn.com/docs/installation/vite",tailwind:"https://tailwindcss.com/docs/guides/vite"}},astro:{name:"astro",label:"Astro",links:{installation:"https://ui.shadcn.com/docs/installation/astro",tailwind:"https://tailwindcss.com/docs/guides/astro"}},laravel:{name:"laravel",label:"Laravel",links:{installation:"https://ui.shadcn.com/docs/installation/laravel",tailwind:"https://tailwindcss.com/docs/guides/laravel"}},gatsby:{name:"gatsby",label:"Gatsby",links:{installation:"https://ui.shadcn.com/docs/installation/gatsby",tailwind:"https://tailwindcss.com/docs/guides/gatsby"}},manual:{name:"manual",label:"Manual",links:{installation:"https://ui.shadcn.com/docs/installation/manual",tailwind:"https://tailwindcss.com/docs/installation"}}};import A from"path";import{cyan as bt,green as St,red as Ct,yellow as Pt}from"kleur/colors";var c={error:Ct,warn:Pt,info:bt,success:St};import{createMatchPath as vt}from"tsconfig-paths";async function R(e,t){return vt(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}import{cosmiconfig as Rt}from"cosmiconfig";import{loadConfig as kt}from"tsconfig-paths";import{z as g}from"zod";var ke="@/components",Ie="@/lib/utils",Te="app/globals.css",Ee="tailwind.config.js";var It=Rt("components",{searchPlaces:["components.json"]}),F=g.object({$schema:g.string().optional(),style:g.string(),rsc:g.coerce.boolean().default(!1),tsx:g.coerce.boolean().default(!0),tailwind:g.object({config:g.string(),css:g.string(),baseColor:g.string(),cssVariables:g.boolean().default(!0),prefix:g.string().default("").optional()}),aliases:g.object({components:g.string(),utils:g.string(),ui:g.string().optional(),lib:g.string().optional(),hooks:g.string().optional()})}).strict(),Tt=F.extend({resolvedPaths:g.object({cwd:g.string(),tailwindConfig:g.string(),tailwindCss:g.string(),utils:g.string(),components:g.string(),lib:g.string(),hooks:g.string(),ui:g.string()})});async function I(e){let t=await Et(e);return t?await D(e,t):null}async function D(e,t){let r=await kt(e);if(r.resultType==="failed")throw new Error(`Failed to load ${t.tsx?"tsconfig":"jsconfig"}.json. ${r.message??""}`.trim());return Tt.parse({...t,resolvedPaths:{cwd:e,tailwindConfig:A.resolve(e,t.tailwind.config),tailwindCss:A.resolve(e,t.tailwind.css),utils:await R(t.aliases.utils,r),components:await R(t.aliases.components,r),ui:t.aliases.ui?await R(t.aliases.ui,r):A.resolve(await R(t.aliases.components,r)??e,"ui"),lib:t.aliases.lib?await R(t.aliases.lib,r):A.resolve(await R(t.aliases.utils,r)??e,".."),hooks:t.aliases.hooks?await R(t.aliases.hooks,r):A.resolve(await R(t.aliases.components,r)??e,"..","hooks")}})}async function Et(e){try{let t=await It.search(e);return t?F.parse(t.config):null}catch{let r=`${e}/components.json`;throw new Error(`Invalid configuration found in ${c.info(r)}.`)}}import jt from"path";import $t from"fs-extra";function M(e="",t=!0){let r=jt.join(e,"package.json");return $t.readJSONSync(r,{throws:t})}import G from"fast-glob";import ce from"fs-extra";import{loadConfig as Ot}from"tsconfig-paths";var B=["**/node_modules/**",".next","public","dist","build"];async function j(e){let[t,r,i,n,s,o,l]=await Promise.all([G.glob("**/{next,vite,astro}.config.*|gatsby-config.*|composer.json",{cwd:e,deep:3,ignore:B}),ce.pathExists(le.resolve(e,"src")),Dt(e),At(e),Nt(e),Ft(e),M(e,!1)]),f=await ce.pathExists(le.resolve(e,`${r?"src/":""}app`)),d={framework:v.manual,isSrcDir:r,isRSC:!1,isTsx:i,tailwindConfigFile:n,tailwindCssFile:s,aliasPrefix:o};return t.find(m=>m.startsWith("next.config."))?.length?(d.framework=f?v["next-app"]:v["next-pages"],d.isRSC=f,d):t.find(m=>m.startsWith("astro.config."))?.length?(d.framework=v.astro,d):t.find(m=>m.startsWith("gatsby-config."))?.length?(d.framework=v.gatsby,d):t.find(m=>m.startsWith("composer.json"))?.length?(d.framework=v.laravel,d):Object.keys(l?.dependencies??{}).find(m=>m.startsWith("@remix-run/"))?(d.framework=v.remix,d):(t.find(m=>m.startsWith("vite.config."))?.length&&(d.framework=v.vite),d)}async function Nt(e){let t=await G.glob(["**/*.css","**/*.scss"],{cwd:e,deep:5,ignore:B});if(!t.length)return null;for(let r of t)if((await ce.readFile(le.resolve(e,r),"utf8")).includes("@tailwind base"))return r;return null}async function At(e){let t=await G.glob("tailwind.config.*",{cwd:e,deep:3,ignore:B});return t.length?t[0]:null}async function Ft(e){let t=await Ot(e);if(t?.resultType==="failed"||!t?.paths)return null;for(let[r,i]of Object.entries(t.paths))if(i.includes("./*")||i.includes("./src/*")||i.includes("./app/*")||i.includes("./resources/js/*"))return r.at(0)??null;return null}async function Dt(e){return(await G.glob("tsconfig.*",{cwd:e,deep:1,ignore:B})).length>0}async function je(e,t=null){let[r,i]=await Promise.all([I(e),t?Promise.resolve(t):j(e)]);if(r)return r;if(!i||!i.tailwindConfigFile||!i.tailwindCssFile)return null;let n={$schema:"https://ui.shadcn.com/schema.json",rsc:i.isRSC,tsx:i.isTsx,style:"new-york",tailwind:{config:i.tailwindConfigFile,baseColor:"zinc",css:i.tailwindCssFile,cssVariables:!0,prefix:""},aliases:{components:`${i.aliasPrefix}/components`,ui:`${i.aliasPrefix}/components/ui`,hooks:`${i.aliasPrefix}/hooks`,lib:`${i.aliasPrefix}/lib`,utils:`${i.aliasPrefix}/lib/utils`}};return await D(e,n)}var a={error(...e){console.log(c.error(e.join(" ")))},warn(...e){console.log(c.warn(e.join(" ")))},info(...e){console.log(c.info(e.join(" ")))},success(...e){console.log(c.success(e.join(" ")))},log(...e){console.log(e.join(" "))},break(){console.log("")}};import Lt from"ora";function h(e,t){return Lt({text:e,isSilent:t?.silent})}import pe from"fs-extra";async function Oe(e){let t={};if(!pe.existsSync(e.cwd)||!pe.existsSync($e.resolve(e.cwd,"package.json")))return t[k]=!0,{errors:t,projectInfo:null};let r=h("Preflight checks.",{silent:e.silent}).start();pe.existsSync($e.resolve(e.cwd,"components.json"))&&!e.force&&(r?.fail(),a.break(),a.error(`A ${c.info("components.json")} file already exists at ${c.info(e.cwd)}.
3
+ To start over, remove the ${c.info("components.json")} file and run ${c.info("init")} again.`),a.break(),process.exit(1)),r?.succeed();let i=h("Verifying framework.",{silent:e.silent}).start(),n=await j(e.cwd);(!n||n?.framework.name==="manual")&&(t[Re]=!0,i?.fail(),a.break(),n?.framework.links.installation&&a.error(`We could not detect a supported framework at ${c.info(e.cwd)}.
4
+ Visit ${c.info(n?.framework.links.installation)} to manually configure your project.
5
+ Once configured, you can use the cli to add components.`),a.break(),process.exit(1)),i?.succeed(`Verifying framework. Found ${c.info(n.framework.label)}.`);let s=h("Validating Tailwind CSS.",{silent:e.silent}).start();!n?.tailwindConfigFile||!n?.tailwindCssFile?(t[oe]=!0,s?.fail()):s?.succeed();let o=h("Validating import alias.",{silent:e.silent}).start();return n?.aliasPrefix?o?.succeed():(t[ae]=!0,o?.fail()),Object.keys(t).length>0&&(t[oe]&&(a.break(),a.error(`No Tailwind CSS configuration found at ${c.info(e.cwd)}.`),a.error("It is likely you do not have Tailwind CSS installed or have an invalid configuration."),a.error("Install Tailwind CSS then try again."),n?.framework.links.tailwind&&a.error(`Visit ${c.info(n?.framework.links.tailwind)} to get started.`)),t[ae]&&(a.break(),a.error("No import alias found in your tsconfig.json file."),n?.framework.links.installation&&a.error(`Visit ${c.info(n?.framework.links.installation)} to learn how to set an import alias.`)),a.break(),process.exit(1)),{errors:t,projectInfo:n}}import{z as _t}from"zod";function x(e){if(a.error("Something went wrong. Please check the error below for more details."),a.error("If the problem persists, please open an issue on GitHub."),a.error(""),typeof e=="string"&&(a.error(e),a.break(),process.exit(1)),e instanceof _t.ZodError){a.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))a.error(`- ${c.info(t)}: ${r}`);a.break(),process.exit(1)}e instanceof Error&&(a.error(e.message),a.break(),process.exit(1)),a.break(),process.exit(1)}import Xt from"path";import{z as p}from"zod";var Ne=p.enum(["registry:style","registry:lib","registry:example","registry:block","registry:component","registry:ui","registry:hook","registry:theme","registry:page"]),Ae=p.object({path:p.string(),content:p.string().optional(),type:Ne,target:p.string().optional()}),zt=p.object({config:p.object({content:p.array(p.string()).optional(),theme:p.record(p.string(),p.any()).optional(),plugins:p.array(p.string()).optional()}).optional()}),Kt=p.object({light:p.record(p.string(),p.string()).optional(),dark:p.record(p.string(),p.string()).optional()}),N=p.object({name:p.string(),type:Ne,description:p.string().optional(),dependencies:p.array(p.string()).optional(),devDependencies:p.array(p.string()).optional(),registryDependencies:p.array(p.string()).optional(),files:p.array(Ae).optional(),tailwind:zt.optional(),cssVars:Kt.optional(),meta:p.record(p.string(),p.any()).optional(),docs:p.string().optional()}),me=p.array(N.extend({files:p.array(p.union([p.string(),Ae])).optional()})),Fe=p.array(p.object({name:p.string(),label:p.string()})),De=p.object({inlineColors:p.object({light:p.record(p.string(),p.string()),dark:p.record(p.string(),p.string())}),cssVars:p.object({light:p.record(p.string(),p.string()),dark:p.record(p.string(),p.string())}),inlineColorsTemplate:p.string(),cssVarsTemplate:p.string()}),Le=N.pick({dependencies:!0,devDependencies:!0,files:!0,tailwind:!0,cssVars:!0,docs:!0});import{promises as fe}from"fs";import{tmpdir as Wt}from"os";import L from"path";import Vt from"deepmerge";import Ut from"stringify-object";import{Project as Mt,QuoteKind as Gt,ScriptKind as _e,SyntaxKind as u}from"ts-morph";async function ze(e,t,r){if(!e)return;r={silent:!1,...r};let i=L.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=h(`Updating ${c.info(i)}`,{silent:r.silent}).start(),s=await fe.readFile(t.resolvedPaths.tailwindConfig,"utf8"),o=await Bt(s,e,t);await fe.writeFile(t.resolvedPaths.tailwindConfig,o,"utf8"),n?.succeed()}async function Bt(e,t,r){let i=await J(e,r),n=i.getDescendantsOfKind(u.ObjectLiteralExpression).find(o=>o.getProperties().some(l=>l.isKind(u.PropertyAssignment)&&l.getName()==="content"));if(!n)return e;let s=de(n);return Jt(n,{name:"darkMode",value:"class"},{quoteChar:s}),t.plugins?.forEach(o=>{Ht(n,o)}),t.theme&&await Yt(n,t.theme),i.getFullText()}function Jt(e,t,{quoteChar:r}){let i=e.getProperty("darkMode");if(!i){let n={name:t.name,initializer:`[${r}${t.value}${r}]`};return t.name==="darkMode"?(e.insertPropertyAssignment(0,n),e):(e.addPropertyAssignment(n),e)}if(i.isKind(u.PropertyAssignment)){let n=i.getInitializer(),s=`${r}${t.value}${r}`;if(n?.isKind(u.StringLiteral)){let o=n.getText();return n.replaceWithText(`[${o}, ${s}]`),e}if(n?.isKind(u.ArrayLiteralExpression)){if(n.getElements().map(o=>o.getText()).includes(s))return e;n.addElement(s)}return e}return e}async function Yt(e,t){e.getProperty("theme")||e.addPropertyAssignment({name:"theme",initializer:"{}"}),Ke(e);let i=(e.getPropertyOrThrow("theme")?.asKindOrThrow(u.PropertyAssignment)).getInitializer();if(i?.isKind(u.ObjectLiteralExpression)){let n=i.getText(),s=await Qt(n),o=Vt(s,t),l=Ut(o).replace(/\'\"/g,"'").replace(/\"\'/g,"'").replace(/\'\[/g,"[").replace(/\]\'/g,"]").replace(/\'\\\'/g,"'").replace(/\\\'/g,"'").replace(/\\\'\'/g,"'").replace(/\'\'/g,"'");i.replaceWithText(l)}We(e)}function Ht(e,t){let r=e.getProperty("plugins");if(!r)return e.addPropertyAssignment({name:"plugins",initializer:`[${t}]`}),e;if(r.isKind(u.PropertyAssignment)){let i=r.getInitializer();if(i?.isKind(u.ArrayLiteralExpression)){if(i.getElements().map(n=>n.getText().replace(/["']/g,"")).includes(t.replace(/["']/g,"")))return e;i.addElement(t)}return e}return e}async function J(e,t){let r=await fe.mkdtemp(L.join(Wt(),"shadcn-")),i=t?.resolvedPaths?.tailwindConfig||"tailwind.config.ts",n=L.join(r,`shadcn-${L.basename(i)}`);return new Mt({compilerOptions:{}}).createSourceFile(n,e,{scriptKind:L.extname(i)===".ts"?_e.TS:_e.JS})}function de(e){return e.getFirstDescendantByKind(u.StringLiteral)?.getQuoteKind()===Gt.Single?"'":'"'}function Ke(e){let t=e.getProperties();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(u.SpreadAssignment)){let n=i.asKindOrThrow(u.SpreadAssignment),s=n.getExpression().getText();e.insertPropertyAssignment(r,{name:`___${s.replace(/^\.\.\./,"")}`,initializer:`"...${s.replace(/^\.\.\./,"")}"`}),n.remove()}else if(i.isKind(u.PropertyAssignment)){let s=i.asKindOrThrow(u.PropertyAssignment).getInitializer();s&&s.isKind(u.ObjectLiteralExpression)&&Ke(s.asKindOrThrow(u.ObjectLiteralExpression))}}}function We(e){let t=e.getProperties();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(u.PropertyAssignment)){let n=i,s=n.getInitializer();if(s?.isKind(u.StringLiteral)){let o=s.getLiteralValue();o.startsWith("...")&&(e.insertSpreadAssignment(r,{expression:o.slice(3)}),n.remove())}else s?.isKind(u.ObjectLiteralExpression)&&We(s)}}}async function Qt(e){let r=(await J(`const theme = ${e}`,null)).getStatements()[0];if(r?.getKind()===u.VariableStatement){let n=(r.getDeclarationList()?.getDeclarations()[0]).getInitializer();if(n?.isKind(u.ObjectLiteralExpression))return await Ve(n)}throw new Error("Invalid input: not an object literal")}function Ve(e){let t={};for(let r of e.getProperties())if(r.isKind(u.PropertyAssignment)){let i=r.getName().replace(/\'/g,"");r.getInitializer()?.isKind(u.ObjectLiteralExpression)?t[i]=Ve(r.getInitializer()):t[i]=Ue(r.getInitializer())}return t}function Ue(e){switch(e.kind){case u.StringLiteral:return e.text;case u.NumericLiteral:return Number(e.text);case u.TrueKeyword:return!0;case u.FalseKeyword:return!1;case u.NullKeyword:return null;case u.ArrayLiteralExpression:return e.elements.map(Ue);default:return e.getText()}}function Me(e){let t={};for(let r of Object.keys(e)){let i=r.split("-"),n=i[0],s=i.slice(1).join("-");s===""?typeof t[n]=="object"?t[n].DEFAULT=`hsl(var(--${r}))`:t[n]=`hsl(var(--${r}))`:(typeof t[n]!="object"&&(t[n]={DEFAULT:`hsl(var(--${n}))`}),t[n][s]=`hsl(var(--${r}))`)}for(let[r,i]of Object.entries(t))typeof i=="object"&&i.DEFAULT===`hsl(var(--${r}))`&&!(r in e)&&delete i.DEFAULT;return t}import _ from"deepmerge";import{HttpsProxyAgent as qt}from"https-proxy-agent";import Zt from"node-fetch";import{z as er}from"zod";var tr=process.env.REGISTRY_URL??"https://ui.shadcn.com/r",rr=process.env.https_proxy?new qt(process.env.https_proxy):void 0;async function z(){try{let[e]=await $(["index.json"]);return me.parse(e)}catch(e){a.error(`
6
+ `),x(e)}}async function ue(){try{let[e]=await $(["styles/index.json"]);return Fe.parse(e)}catch(e){return a.error(`
7
+ `),x(e),[]}}async function Ge(e,t){try{let[r]=await $([he(e)?e:`styles/${t}/${e}.json`]);return N.parse(r)}catch(r){return a.break(),x(r),null}}async function ge(){return[{name:"neutral",label:"Neutral"},{name:"gray",label:"Gray"},{name:"zinc",label:"Zinc"},{name:"stone",label:"Stone"},{name:"slate",label:"Slate"}]}async function K(e){try{let[t]=await $([`colors/${e}.json`]);return De.parse(t)}catch(t){x(t)}}async function Be(e,t){try{let r=t.map(n=>`styles/${e}/${n.name}.json`),i=await $(r);return me.parse(i)}catch(r){x(r)}}async function Je(e,t,r){if(r)return r;if(t.type==="registry:ui")return e.resolvedPaths.ui??e.resolvedPaths.components;let[i,n]=t.type?.split(":")??[];return i in e.resolvedPaths?Xt.join(e.resolvedPaths[i],n):null}async function $(e){try{return await Promise.all(e.map(async r=>{let i=Qe(r),n=await Zt(i,{agent:rr});if(!n.ok){let s={400:"Bad request",401:"Unauthorized",403:"Forbidden",404:"Not found",500:"Internal server error"};if(n.status===401)throw new Error(`You are not authorized to access the component at ${c.info(i)}.
8
+ If this is a remote registry, you may need to authenticate.`);if(n.status===404)throw new Error(`The component at ${c.info(i)} was not found.
9
+ It may not exist at the registry. Please make sure it is a valid component.`);if(n.status===403)throw new Error(`You do not have access to the component at ${c.info(i)}.
10
+ If this is a remote registry, you may need to authenticate or a token.`);let o=await n.json(),l=o&&typeof o=="object"&&"error"in o?o.error:n.statusText||s[n.status];throw new Error(`Failed to fetch from ${c.info(i)}.
11
+ ${l}`)}return n.json()}))}catch(t){return a.error(`
12
+ `),x(t),[]}}function Ye(e,t,r){return r||(e.type==="registry:ui"?t.resolvedPaths.ui:e.type==="registry:lib"?t.resolvedPaths.lib:e.type==="registry:block"||e.type==="registry:component"?t.resolvedPaths.components:e.type==="registry:hook"?t.resolvedPaths.hooks:(e.type==="registry:page",t.resolvedPaths.components))}async function He(e,t){try{if(!await z())return null;e.includes("index")&&e.unshift("index");let i=[];for(let m of e){let w=await ir(m,t);i.push(...w)}let n=Array.from(new Set(i)),s=await $(n),o=er.array(N).parse(s);if(!o)return null;if(e.includes("index")&&t.tailwind.baseColor){let m=await nr(t.tailwind.baseColor,t);m&&o.unshift(m)}let l={};o.forEach(m=>{l=_(l,m.tailwind??{})});let f={};o.forEach(m=>{f=_(f,m.cssVars??{})});let d="";return o.forEach(m=>{m.docs&&(d+=`${m.docs}
13
+ `)}),Le.parse({dependencies:_.all(o.map(m=>m.dependencies??[])),devDependencies:_.all(o.map(m=>m.devDependencies??[])),files:_.all(o.map(m=>m.files??[])),tailwind:l,cssVars:f,docs:d})}catch(r){return x(r),null}}async function ir(e,t){let r=new Set,i=[];async function n(s){let o=Qe(he(s)?s:`styles/${t.style}/${s}.json`);if(!r.has(o)){r.add(o);try{let[l]=await $([o]),f=N.parse(l);if(i.push(o),f.registryDependencies)for(let d of f.registryDependencies)await n(d)}catch(l){console.error(`Error fetching or parsing registry item at ${s}:`,l)}}}return await n(e),Array.from(new Set(i))}async function nr(e,t){let r=await K(e);if(!r)return null;let i={name:e,type:"registry:theme",tailwind:{config:{theme:{extend:{borderRadius:{lg:"var(--radius)",md:"calc(var(--radius) - 2px)",sm:"calc(var(--radius) - 4px)"},colors:{}}}}},cssVars:{light:{radius:"0.5rem"},dark:{}}};return t.tailwind.cssVariables&&(i.tailwind.config.theme.extend.colors={...i.tailwind.config.theme.extend.colors,...Me(r.cssVars.dark)},i.cssVars={light:{...r.cssVars.light,...i.cssVars.light},dark:{...r.cssVars.dark,...i.cssVars.dark}}),i}function Qe(e){if(he(e)){let t=new URL(e);return t.pathname.match(/\/chat\/b\//)&&!t.pathname.endsWith("/json")&&(t.pathname=`${t.pathname}/json`),t.toString()}return`${tr}/${e}`}function he(e){try{return new URL(e),!0}catch{return!1}}import{promises as Xe}from"fs";import sr from"path";import O from"postcss";import or from"postcss/lib/at-rule";async function Ze(e,t,r){if(!e||!Object.keys(e).length||!t.resolvedPaths.tailwindCss)return;r={cleanupDefaultNextStyles:!1,silent:!1,...r};let i=t.resolvedPaths.tailwindCss,n=sr.relative(t.resolvedPaths.cwd,i),s=h(`Updating ${c.info(n)}`,{silent:r.silent}).start(),o=await Xe.readFile(i,"utf8"),l=await ar(o,e,t,{cleanupDefaultNextStyles:r.cleanupDefaultNextStyles});await Xe.writeFile(i,l,"utf8"),s.succeed()}async function ar(e,t,r,i){i={cleanupDefaultNextStyles:!1,...i};let n=[cr(t)];return i.cleanupDefaultNextStyles&&n.push(pr()),r.tailwind.cssVariables&&n.push(lr()),(await O(n).process(e,{from:void 0})).css}function lr(){return{postcssPlugin:"update-base-layer",Once(e){let t=[{selector:"*",apply:"border-border"},{selector:"body",apply:"bg-background text-foreground"}],r=e.nodes.find(i=>i.type==="atrule"&&i.name==="layer"&&i.params==="base"&&t.every(({selector:n,apply:s})=>i.nodes?.some(o=>o.type==="rule"&&o.selector===n&&o.nodes.some(l=>l.type==="atrule"&&l.name==="apply"&&l.params===s))));r||(r=O.atRule({name:"layer",params:"base",raws:{semicolon:!0,between:" ",before:`
14
+ `}}),e.append(r)),t.forEach(({selector:i,apply:n})=>{r?.nodes?.find(o=>o.type==="rule"&&o.selector===i)||r?.append(O.rule({selector:i,nodes:[O.atRule({name:"apply",params:n,raws:{semicolon:!0,before:`
11
15
  `}})],raws:{semicolon:!0,between:" ",before:`
12
- `}}))})}}}function er(e){return{postcssPlugin:"update-css-vars",Once(t){let r=t.nodes.find(i=>i.type==="atrule"&&i.name==="layer"&&i.params==="base");r instanceof Xt||(r=k.atRule({name:"layer",params:"base",nodes:[],raws:{semicolon:!0,before:`
13
- `,between:" "}}),t.append(r)),r!==void 0&&Object.entries(e).forEach(([i,n])=>{let s=i==="light"?":root":`.${i}`;rr(r,s,n)})}}}function tr(){return{postcssPlugin:"cleanup-default-next-styles",Once(e){let t=e.nodes.find(r=>r.type==="rule"&&r.selector==="body");t&&(t.nodes.find(r=>r.type==="decl"&&r.prop==="color"&&r.value==="rgb(var(--foreground-rgb))")?.remove(),t.nodes.find(r=>r.type==="decl"&&r.prop==="background"&&r.value.startsWith("linear-gradient"))?.remove(),t.nodes.length===0&&t.remove())}}}function rr(e,t,r){let i=e.nodes?.find(n=>n.type==="rule"&&n.selector===t);i||Object.keys(r).length>0&&(i=k.rule({selector:t,raws:{between:" ",before:`
14
- `}}),e.append(i)),Object.entries(r).forEach(([n,s])=>{let a=`--${n.replace(/^--/,"")}`,c=k.decl({prop:a,value:s,raws:{semicolon:!0}}),m=i?.nodes.find(f=>f.type==="decl"&&f.prop===a);m?m.replaceWith(c):i?.append(c)})}import{detect as ir}from"@antfu/ni";async function J(e,{withFallback:t}={withFallback:!1}){let r=await ir({programmatic:!0,cwd:e});if(r==="yarn@berry")return"yarn";if(r==="pnpm@6")return"pnpm";if(r==="bun")return"bun";if(!t)return r??"npm";let i=process.env.npm_config_user_agent||"";return i.startsWith("yarn")?"yarn":i.startsWith("pnpm")?"pnpm":i.startsWith("bun")?"bun":"npm"}import{execa as nr}from"execa";async function He(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let i=w("Installing dependencies.",{silent:r.silent})?.start(),n=await J(t.resolvedPaths.cwd);await nr(n,[n==="npm"?"install":"add",...e],{cwd:t.resolvedPaths.cwd}),i?.succeed()}import{existsSync as Ze,promises as qe}from"fs";import j,{basename as br}from"path";import{promises as ur}from"fs";import{tmpdir as gr}from"os";import Xe from"path";import{SyntaxKind as sr}from"ts-morph";var Y=async({sourceFile:e,config:t,baseColor:r})=>(t.tailwind?.cssVariables||!r?.inlineColors||e.getDescendantsOfKind(sr.StringLiteral).forEach(i=>{let n=i.getText();if(n){let s=ar(n.replace(/"/g,""),r.inlineColors);i.replaceWithText(`"${s.trim()}"`)}}),e);function ue(e){if(!e.includes("/")&&!e.includes(":"))return[null,e,null];let t=[],[r,i]=e.split("/");if(!r.includes(":"))return[null,r,i];let n=r.split(":"),s=n.pop(),a=n.join(":");return t.push(a??null,s??null,i??null),t}var or=["bg-","text-","border-","ring-offset-","ring-"];function ar(e,t){e.includes(" border ")&&(e=e.replace(" border "," border border-border "));let r=e.split(" "),i=new Set,n=new Set;for(let s of r){let[a,c,m]=ue(s),f=or.find(d=>c?.startsWith(d));if(!f){i.has(s)||i.add(s);continue}let x=c?.replace(f,"");if(x&&x in t.light){i.add([a,`${f}${t.light[x]}`].filter(Boolean).join(":")+(m?`/${m}`:"")),n.add(["dark",a,`${f}${t.dark[x]}`].filter(Boolean).join(":")+(m?`/${m}`:""));continue}i.has(s)||i.add(s)}return[...Array.from(i),...Array.from(n)].join(" ").trim()}var H=async({sourceFile:e,config:t})=>{let r=e.getImportDeclarations();for(let i of r){let n=lr(i.getModuleSpecifierValue(),t);i.setModuleSpecifier(n),n=="@/lib/utils"&&i.getNamedImports().find(c=>c.getName()==="cn")&&i.setModuleSpecifier(n.replace(/^@\/lib\/utils/,t.aliases.utils))}return e};function lr(e,t){if(!e.startsWith("@/"))return e;if(!e.startsWith("@/registry/")){let r=t.aliases.components.charAt(0);return e.replace(/^@\//,`${r}/`)}return e.match(/^@\/registry\/(.+)\/ui/)?e.replace(/^@\/registry\/(.+)\/ui/,t.aliases.ui??`${t.aliases.components}/ui`):t.aliases.components&&e.match(/^@\/registry\/(.+)\/components/)?e.replace(/^@\/registry\/(.+)\/components/,t.aliases.components):t.aliases.lib&&e.match(/^@\/registry\/(.+)\/lib/)?e.replace(/^@\/registry\/(.+)\/lib/,t.aliases.lib):t.aliases.hooks&&e.match(/^@\/registry\/(.+)\/hooks/)?e.replace(/^@\/registry\/(.+)\/hooks/,t.aliases.hooks):e.replace(/^@\/registry\/[^/]+/,t.aliases.components)}import{transformFromAstSync as cr}from"@babel/core";import{parse as pr}from"@babel/parser";import mr from"@babel/plugin-transform-typescript";import*as Q from"recast";var fr={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,plugins:["asyncGenerators","bigInt","classPrivateMethods","classPrivateProperties","classProperties","classStaticBlock","decimal","decorators-legacy","doExpressions","dynamicImport","exportDefaultFrom","exportNamespaceFrom","functionBind","functionSent","importAssertions","importMeta","nullishCoalescingOperator","numericSeparator","objectRestSpread","optionalCatchBinding","optionalChaining",["pipelineOperator",{proposal:"minimal"}],["recordAndTuple",{syntaxType:"hash"}],"throwExpressions","topLevelAwait","v8intrinsic","typescript","jsx"]},Qe=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let i=Q.parse(r,{parser:{parse:s=>pr(s,fr)}}),n=cr(i,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[mr],configFile:!1});if(!n||!n.ast)throw new Error("Failed to transform JSX");return Q.print(n.ast).code};import{SyntaxKind as dr}from"ts-morph";var X=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(dr.ExpressionStatement);return r?.getText()==='"use client"'&&r.remove(),e};import{Project as hr,ScriptKind as yr}from"ts-morph";import{SyntaxKind as h}from"ts-morph";var Z=async({sourceFile:e,config:t})=>(t.tailwind?.prefix&&(e.getDescendantsOfKind(h.CallExpression).filter(r=>r.getExpression().getText()==="cva").forEach(r=>{if(r.getArguments()[0]?.isKind(h.StringLiteral)){let i=r.getArguments()[0];i&&i.replaceWithText(`"${I(i.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}r.getArguments()[1]?.isKind(h.ObjectLiteralExpression)&&r.getArguments()[1]?.getDescendantsOfKind(h.PropertyAssignment).find(i=>i.getName()==="variants")?.getDescendantsOfKind(h.PropertyAssignment).forEach(i=>{i.getDescendantsOfKind(h.PropertyAssignment).forEach(n=>{let s=n.getInitializerIfKind(h.StringLiteral);s&&s?.replaceWithText(`"${I(s.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)})})}),e.getDescendantsOfKind(h.JsxAttribute).forEach(r=>{if(r.getName()==="className"){if(r.getInitializer()?.isKind(h.StringLiteral)){let i=r.getInitializer();i&&i.replaceWithText(`"${I(i.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}if(r.getInitializer()?.isKind(h.JsxExpression)){let i=r.getInitializer()?.getDescendantsOfKind(h.CallExpression).find(n=>n.getExpression().getText()==="cn");i&&i.getArguments().forEach(n=>{(n.isKind(h.ConditionalExpression)||n.isKind(h.BinaryExpression))&&n.getChildrenOfKind(h.StringLiteral).forEach(s=>{s.replaceWithText(`"${I(s.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}),n.isKind(h.StringLiteral)&&n.replaceWithText(`"${I(n.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)})}}r.getName()==="classNames"&&r.getInitializer()?.isKind(h.JsxExpression)&&r.getDescendantsOfKind(h.PropertyAssignment).forEach(i=>{if(i.getInitializer()?.isKind(h.CallExpression)){let n=i.getInitializerIfKind(h.CallExpression);n&&n.getArguments().forEach(s=>{s.isKind(h.ConditionalExpression)&&s.getChildrenOfKind(h.StringLiteral).forEach(a=>{a.replaceWithText(`"${I(a.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}),s.isKind(h.StringLiteral)&&s.replaceWithText(`"${I(s.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)})}if(i.getInitializer()?.isKind(h.StringLiteral)&&i.getName()!=="variant"){let n=i.getInitializer();n&&n.replaceWithText(`"${I(n.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}})})),e);function I(e,t=""){let r=e.split(" "),i=[];for(let n of r){let[s,a,c]=ue(n);s?c?i.push(`${s}:${t}${a}/${c}`):i.push(`${s}:${t}${a}`):c?i.push(`${t}${a}/${c}`):i.push(`${t}${a}`)}return i.join(" ")}var wr=new hr({compilerOptions:{}});async function xr(e){let t=await ur.mkdtemp(Xe.join(gr(),"shadcn-"));return Xe.join(t,e)}async function q(e,t=[H,X,Y,Z]){let r=await xr(e.filename),i=wr.createSourceFile(r,e.raw,{scriptKind:yr.TSX});for(let n of t)n({sourceFile:i,...e});return e.transformJsx?await Qe({sourceFile:i,...e}):i.getText()}import Sr from"prompts";async function et(e,t,r){if(!e?.length)return;r={overwrite:!1,force:!1,silent:!1,...r};let i=w("Updating files.",{silent:r.silent})?.start(),n=await z(t.tailwind.baseColor),s=[],a=[],c=[];for(let f of e){if(!f.content)continue;let x=Ue(f,t),d=br(f.path),y=j.join(x,d);f.target&&(y=j.join(t.resolvedPaths.cwd,f.target),x=j.dirname(y)),t.tsx||(y=y.replace(/\.tsx?$/,ie=>ie===".tsx"?".jsx":".js"));let W=Ze(y);if(W&&!r.overwrite){i.stop();let{overwrite:ie}=await Sr({type:"confirm",name:"overwrite",message:`The file ${l.info(d)} already exists. Would you like to overwrite?`,initial:!1});if(!ie){c.push(j.relative(t.resolvedPaths.cwd,y));continue}i?.start()}Ze(x)||await qe.mkdir(x,{recursive:!0});let ft=await q({filename:f.path,raw:f.content,config:t,baseColor:n,transformJsx:!t.tsx},[H,X,Y,Z]);await qe.writeFile(y,ft,"utf-8"),W?a.push(j.relative(t.resolvedPaths.cwd,y)):s.push(j.relative(t.resolvedPaths.cwd,y))}if(!(s.length||a.length)&&!c.length&&i?.info("No files updated."),s.length){if(i?.succeed(`Created ${s.length} ${s.length===1?"file":"files"}:`),!r.silent)for(let f of s)o.log(` - ${f}`)}else i?.stop();if(a.length&&(w(`Updated ${a.length} ${a.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let f of a)o.log(` - ${f}`);if(c.length&&(w(`Skipped ${c.length} ${a.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let f of c)o.log(` - ${f}`);r.silent||o.break()}async function ee(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,...r};let i=w("Checking registry.",{silent:r.silent})?.start(),n=await Ge(e,t);if(!n)return i?.fail(),b(new Error("Failed to fetch components from registry."));i?.succeed(),await Fe(n.tailwind?.config,t,{silent:r.silent}),await Ye(n.cssVars,t,{cleanupDefaultNextStyles:r.isNewProject,silent:r.silent}),await He(n.dependencies,t,{silent:r.silent}),await et(n.files,t,{overwrite:r.overwrite,silent:r.silent})}import Cr from"path";import{execa as Pr}from"execa";import ge from"fs-extra";import tt from"prompts";async function te(e){if(!e.force){let{proceed:a}=await tt({type:"confirm",name:"proceed",message:`The path ${l.info(e.cwd)} is empty. Would you like to start a new ${l.info("Next.js")} project?`,initial:!0});if(!a)return{projectPath:null,projectName:null}}let t=await J(e.cwd),{name:r}=await tt({type:"text",name:"name",message:"What is your project named?",initial:"my-app",format:a=>a.trim(),validate:a=>a.length>128?"Name should be less than 128 characters.":!0}),i=`${e.cwd}/${r}`;try{await ge.access(e.cwd,ge.constants.W_OK)}catch{o.break(),o.error(`The path ${l.info(e.cwd)} is not writable.`),o.error(`It is likely you do not have write permissions for this folder or the path ${l.info(e.cwd)} does not exist.`),o.break(),process.exit(1)}ge.existsSync(Cr.resolve(e.cwd,r,"package.json"))&&(o.break(),o.error(`A project with the name ${l.info(r)} already exists.`),o.error("Please choose a different name and try again."),o.break(),process.exit(1));let n=w("Creating a new Next.js project. This may take a few minutes.").start(),s=["--tailwind","--eslint","--typescript","--app","--no-src-dir","--no-import-alias",`--use-${t}`];try{await Pr("npx",["create-next-app@latest",i,"--silent",...s],{cwd:e.cwd})}catch{o.break(),o.error("Something went wront creating a new Next.js project. Please try again."),process.exit(1)}return n?.succeed("Creating a new Next.js project."),{projectPath:i,projectName:r}}import{Command as Rr}from"commander";import he from"prompts";import{z as v}from"zod";var Tr=v.object({cwd:v.string(),components:v.array(v.string()).optional(),yes:v.boolean(),defaults:v.boolean(),force:v.boolean(),silent:v.boolean(),isNewProject:v.boolean()}),it=new Rr().name("init").description("initialize your project and install dependencies").argument("[components...]","the components to add or a url to the component.").option("-y, --yes","skip confirmation prompt.",!0).option("-d, --defaults,","use default configuration.",!1).option("-f, --force","force overwrite of existing configuration.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",!1).action(async(e,t)=>{try{let r=Tr.parse({cwd:rt.resolve(t.cwd),isNewProject:!1,components:e,...t});await re(r),o.log(`${l.success("Success!")} Project initialization completed.
15
- You may now add components.`),o.break()}catch(r){o.break(),b(r)}});async function re(e){let t;if(e.skipPreflight)t=await A(e.cwd);else{let m=await ke(e);if(m.errors[R]){let{projectPath:f}=await te(e);f||process.exit(1),e.cwd=f,e.isNewProject=!0}t=m.projectInfo}let r=await Te(e.cwd,t),i=r?await kr(r,e):await Ir(await T(e.cwd));if(!e.yes){let{proceed:m}=await he({type:"confirm",name:"proceed",message:`Write configuration to ${l.info("components.json")}. Proceed?`,initial:!0});m||process.exit(0)}let n=w("Writing components.json.").start(),s=rt.resolve(e.cwd,"components.json");await vr.writeFile(s,JSON.stringify(i,null,2),"utf8"),n.succeed();let a=await N(e.cwd,i),c=["index",...e.components||[]];return await ee(c,a,{overwrite:!0,silent:e.silent,isNewProject:e.isNewProject||t?.framework.name==="next-app"}),a}async function Ir(e=null){let[t,r]=await Promise.all([me(),fe()]);o.info("");let i=await he([{type:"toggle",name:"typescript",message:`Would you like to use ${l.info("TypeScript")} (recommended)?`,initial:e?.tsx??!0,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${l.info("style")} would you like to use?`,choices:t.map(n=>({title:n.label,value:n.name}))},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${l.info("base color")}?`,choices:r.map(n=>({title:n.label,value:n.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${l.info("global CSS")} file?`,initial:e?.tailwind.css??ve},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${l.info("CSS variables")} for theming?`,initial:e?.tailwind.cssVariables??!0,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${l.info("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${l.info("tailwind.config.js")} located?`,initial:e?.tailwind.config??Re},{type:"text",name:"components",message:`Configure the import alias for ${l.info("components")}:`,initial:e?.aliases.components??Ce},{type:"text",name:"utils",message:`Configure the import alias for ${l.info("utils")}:`,initial:e?.aliases.utils??Pe},{type:"toggle",name:"rsc",message:`Are you using ${l.info("React Server Components")}?`,initial:e?.rsc??!0,active:"yes",inactive:"no"}]);return O.parse({$schema:"https://ui.shadcn.com/schema.json",style:i.style,tailwind:{config:i.tailwindConfig,css:i.tailwindCss,baseColor:i.tailwindBaseColor,cssVariables:i.tailwindCssVariables,prefix:i.tailwindPrefix},rsc:i.rsc,tsx:i.typescript,aliases:{utils:i.utils,components:i.components,lib:i.components.replace(/\/components$/,"lib"),hooks:i.components.replace(/\/components$/,"hooks")}})}async function kr(e,t){let r=e.style,i=e.tailwind.baseColor,n=e.tailwind.cssVariables;if(!t.defaults){let[s,a]=await Promise.all([me(),fe()]),c=await he([{type:"select",name:"style",message:`Which ${l.info("style")} would you like to use?`,choices:s.map(m=>({title:m.label,value:m.name})),initial:s.findIndex(m=>m.name===r)},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${l.info("base color")}?`,choices:a.map(m=>({title:m.label,value:m.name}))},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${l.info("CSS variables")} for theming?`,initial:e?.tailwind.cssVariables,active:"yes",inactive:"no"}]);r=c.style,i=c.tailwindBaseColor,n=c.tailwindCssVariables}return O.parse({$schema:e?.$schema,style:r,tailwind:{...e?.tailwind,baseColor:i,cssVariables:n},rsc:e?.rsc,tsx:e?.tsx,aliases:e?.aliases})}import nt from"path";import ye from"fs-extra";async function st(e){let t={};if(!ye.existsSync(e.cwd)||!ye.existsSync(nt.resolve(e.cwd,"package.json")))return t[R]=!0,{errors:t,config:null};if(!ye.existsSync(nt.resolve(e.cwd,"components.json")))return t[V]=!0,{errors:t,config:null};try{let r=await T(e.cwd);return{errors:t,config:r}}catch{o.break(),o.error(`An invalid ${l.info("components.json")} file was found at ${l.info(e.cwd)}.
16
- Before you can add components, you must create a valid ${l.info("components.json")} file by running the ${l.info("init")} command.`),o.error(`Learn more at ${l.info("https://ui.shadcn.com/docs/components-json")}.`),o.break(),process.exit(1)}}import ot from"fs/promises";import Er from"path";async function at(e,t){let r=Er.join(t.resolvedPaths.cwd,"app/page.tsx");if(!(await ot.stat(r)).isFile())return;let i=await B(e,t.style);if(!i?.meta?.importSpecifier||!i?.meta?.moduleSpecifier)return;let n=`import { ${i?.meta?.importSpecifier} } from "${i.meta.moduleSpecifier}"
16
+ `}}))})}}}function cr(e){return{postcssPlugin:"update-css-vars",Once(t){let r=t.nodes.find(i=>i.type==="atrule"&&i.name==="layer"&&i.params==="base");r instanceof or||(r=O.atRule({name:"layer",params:"base",nodes:[],raws:{semicolon:!0,before:`
17
+ `,between:" "}}),t.append(r)),r!==void 0&&Object.entries(e).forEach(([i,n])=>{let s=i==="light"?":root":`.${i}`;mr(r,s,n)})}}}function qe(e){let t=e.nodes.find(r=>r.type==="rule"&&r.selector===":root");if(t){let r=["--background","--foreground"];t.nodes.filter(i=>i.type==="decl"&&r.includes(i.prop)).forEach(i=>i.remove()),t.nodes.length===0&&t.remove()}}function pr(){return{postcssPlugin:"cleanup-default-next-styles",Once(e){let t=e.nodes.find(i=>i.type==="rule"&&i.selector==="body");t&&(t.nodes.find(i=>i.type==="decl"&&i.prop==="color"&&["rgb(var(--foreground-rgb))","var(--foreground)"].includes(i.value))?.remove(),t.nodes.find(i=>i.type==="decl"&&i.prop==="background"&&(i.value.startsWith("linear-gradient")||i.value==="var(--background)"))?.remove(),t.nodes.length===0&&t.remove()),qe(e);let r=e.nodes.find(i=>i.type==="atrule"&&i.params==="(prefers-color-scheme: dark)");r&&(qe(r),r.nodes.length===0&&r.remove())}}}function mr(e,t,r){let i=e.nodes?.find(n=>n.type==="rule"&&n.selector===t);i||Object.keys(r).length>0&&(i=O.rule({selector:t,raws:{between:" ",before:`
18
+ `}}),e.append(i)),Object.entries(r).forEach(([n,s])=>{let o=`--${n.replace(/^--/,"")}`,l=O.decl({prop:o,value:s,raws:{semicolon:!0}}),f=i?.nodes.find(d=>d.type==="decl"&&d.prop===o);f?f.replaceWith(l):i?.append(l)})}import{detect as fr}from"@antfu/ni";async function Y(e,{withFallback:t}={withFallback:!1}){let r=await fr({programmatic:!0,cwd:e});if(r==="yarn@berry")return"yarn";if(r==="pnpm@6")return"pnpm";if(r==="bun")return"bun";if(!t)return r??"npm";let i=process.env.npm_config_user_agent||"";return i.startsWith("yarn")?"yarn":i.startsWith("pnpm")?"pnpm":i.startsWith("bun")?"bun":"npm"}import{execa as dr}from"execa";import ur from"prompts";async function et(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let i=h("Installing dependencies.",{silent:r.silent})?.start(),n=await Y(t.resolvedPaths.cwd),s="";if(gr(t)&&n==="npm"){i.stopAndPersist(),a.warn(`
19
+ It looks like you are using React 19.
20
+ Some packages may fail to install due to peer dependency issues (see https://ui.shadcn.com/react-19).
21
+ `);let o=await ur([{type:"select",name:"flag",message:"How would you like to proceed?",choices:[{title:"Use --force",value:"force"},{title:"Use --legacy-peer-deps",value:"legacy-peer-deps"}]}]);o&&(s=o.flag)}i?.start(),await dr(n,[n==="npm"?"install":"add",...n==="npm"&&s?[`--${s}`]:[],...e],{cwd:t.resolvedPaths.cwd}),i?.succeed()}function gr(e){let t=M(e.resolvedPaths.cwd);return t?.dependencies?.react?/^(?:\^|~)?19(?:\.\d+)*(?:-.*)?$/.test(t.dependencies.react):!1}import{existsSync as it,promises as nt}from"fs";import E,{basename as Or}from"path";import{promises as kr}from"fs";import{tmpdir as Ir}from"os";import rt from"path";import{SyntaxKind as hr}from"ts-morph";var H=async({sourceFile:e,config:t,baseColor:r})=>(t.tailwind?.cssVariables||!r?.inlineColors||e.getDescendantsOfKind(hr.StringLiteral).forEach(i=>{let n=i.getText();if(n){let s=wr(n.replace(/"/g,""),r.inlineColors);i.replaceWithText(`"${s.trim()}"`)}}),e);function ye(e){if(!e.includes("/")&&!e.includes(":"))return[null,e,null];let t=[],[r,i]=e.split("/");if(!r.includes(":"))return[null,r,i];let n=r.split(":"),s=n.pop(),o=n.join(":");return t.push(o??null,s??null,i??null),t}var yr=["bg-","text-","border-","ring-offset-","ring-"];function wr(e,t){e.includes(" border ")&&(e=e.replace(" border "," border border-border "));let r=e.split(" "),i=new Set,n=new Set;for(let s of r){let[o,l,f]=ye(s),d=yr.find(w=>l?.startsWith(w));if(!d){i.has(s)||i.add(s);continue}let m=l?.replace(d,"");if(m&&m in t.light){i.add([o,`${d}${t.light[m]}`].filter(Boolean).join(":")+(f?`/${f}`:"")),n.add(["dark",o,`${d}${t.dark[m]}`].filter(Boolean).join(":")+(f?`/${f}`:""));continue}i.has(s)||i.add(s)}return[...Array.from(i),...Array.from(n)].join(" ").trim()}var Q=async({sourceFile:e,config:t})=>{let r=e.getImportDeclarations();for(let i of r){let n=xr(i.getModuleSpecifierValue(),t);i.setModuleSpecifier(n),n=="@/lib/utils"&&i.getNamedImports().find(l=>l.getName()==="cn")&&i.setModuleSpecifier(n.replace(/^@\/lib\/utils/,t.aliases.utils))}return e};function xr(e,t){if(!e.startsWith("@/"))return e;if(!e.startsWith("@/registry/")){let r=t.aliases.components.charAt(0);return e.replace(/^@\//,`${r}/`)}return e.match(/^@\/registry\/(.+)\/ui/)?e.replace(/^@\/registry\/(.+)\/ui/,t.aliases.ui??`${t.aliases.components}/ui`):t.aliases.components&&e.match(/^@\/registry\/(.+)\/components/)?e.replace(/^@\/registry\/(.+)\/components/,t.aliases.components):t.aliases.lib&&e.match(/^@\/registry\/(.+)\/lib/)?e.replace(/^@\/registry\/(.+)\/lib/,t.aliases.lib):t.aliases.hooks&&e.match(/^@\/registry\/(.+)\/hooks/)?e.replace(/^@\/registry\/(.+)\/hooks/,t.aliases.hooks):e.replace(/^@\/registry\/[^/]+/,t.aliases.components)}import{transformFromAstSync as br}from"@babel/core";import{parse as Sr}from"@babel/parser";import Cr from"@babel/plugin-transform-typescript";import*as X from"recast";var Pr={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,plugins:["asyncGenerators","bigInt","classPrivateMethods","classPrivateProperties","classProperties","classStaticBlock","decimal","decorators-legacy","doExpressions","dynamicImport","exportDefaultFrom","exportNamespaceFrom","functionBind","functionSent","importAssertions","importMeta","nullishCoalescingOperator","numericSeparator","objectRestSpread","optionalCatchBinding","optionalChaining",["pipelineOperator",{proposal:"minimal"}],["recordAndTuple",{syntaxType:"hash"}],"throwExpressions","topLevelAwait","v8intrinsic","typescript","jsx"]},tt=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let i=X.parse(r,{parser:{parse:s=>Sr(s,Pr)}}),n=br(i,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[Cr],configFile:!1});if(!n||!n.ast)throw new Error("Failed to transform JSX");return X.print(n.ast).code};import{SyntaxKind as vr}from"ts-morph";var Rr=/^["']use client["']$/g,q=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(vr.ExpressionStatement);return r&&Rr.test(r.getText())&&r.remove(),e};import{Project as Tr,ScriptKind as Er}from"ts-morph";import{SyntaxKind as y}from"ts-morph";var Z=async({sourceFile:e,config:t})=>(t.tailwind?.prefix&&(e.getDescendantsOfKind(y.CallExpression).filter(r=>r.getExpression().getText()==="cva").forEach(r=>{if(r.getArguments()[0]?.isKind(y.StringLiteral)){let i=r.getArguments()[0];i&&i.replaceWithText(`"${T(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}r.getArguments()[1]?.isKind(y.ObjectLiteralExpression)&&r.getArguments()[1]?.getDescendantsOfKind(y.PropertyAssignment).find(i=>i.getName()==="variants")?.getDescendantsOfKind(y.PropertyAssignment).forEach(i=>{i.getDescendantsOfKind(y.PropertyAssignment).forEach(n=>{let s=n.getInitializerIfKind(y.StringLiteral);s&&s?.replaceWithText(`"${T(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)})})}),e.getDescendantsOfKind(y.JsxAttribute).forEach(r=>{if(r.getName()==="className"){if(r.getInitializer()?.isKind(y.StringLiteral)){let i=r.getInitializer();i&&i.replaceWithText(`"${T(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}if(r.getInitializer()?.isKind(y.JsxExpression)){let i=r.getInitializer()?.getDescendantsOfKind(y.CallExpression).find(n=>n.getExpression().getText()==="cn");i&&i.getArguments().forEach(n=>{(n.isKind(y.ConditionalExpression)||n.isKind(y.BinaryExpression))&&n.getChildrenOfKind(y.StringLiteral).forEach(s=>{s.replaceWithText(`"${T(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}),n.isKind(y.StringLiteral)&&n.replaceWithText(`"${T(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)})}}r.getName()==="classNames"&&r.getInitializer()?.isKind(y.JsxExpression)&&r.getDescendantsOfKind(y.PropertyAssignment).forEach(i=>{if(i.getInitializer()?.isKind(y.CallExpression)){let n=i.getInitializerIfKind(y.CallExpression);n&&n.getArguments().forEach(s=>{s.isKind(y.ConditionalExpression)&&s.getChildrenOfKind(y.StringLiteral).forEach(o=>{o.replaceWithText(`"${T(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}),s.isKind(y.StringLiteral)&&s.replaceWithText(`"${T(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)})}if(i.getInitializer()?.isKind(y.StringLiteral)&&i.getName()!=="variant"){let n=i.getInitializer();n&&n.replaceWithText(`"${T(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}})})),e);function T(e,t=""){let r=e.split(" "),i=[];for(let n of r){let[s,o,l]=ye(n);s?l?i.push(`${s}:${t}${o}/${l}`):i.push(`${s}:${t}${o}`):l?i.push(`${t}${o}/${l}`):i.push(`${t}${o}`)}return i.join(" ")}var jr=new Tr({compilerOptions:{}});async function $r(e){let t=await kr.mkdtemp(rt.join(Ir(),"shadcn-"));return rt.join(t,e)}async function ee(e,t=[Q,q,H,Z]){let r=await $r(e.filename),i=jr.createSourceFile(r,e.raw,{scriptKind:Er.TSX});for(let n of t)n({sourceFile:i,...e});return e.transformJsx?await tt({sourceFile:i,...e}):i.getText()}import Nr from"prompts";function Ar(e,t,r){return r.startsWith("~/")?E.join(t.resolvedPaths.cwd,r.replace("~/","")):e?.isSrcDir?E.join(t.resolvedPaths.cwd,"src",r):E.join(t.resolvedPaths.cwd,r)}async function st(e,t,r){if(!e?.length)return;r={overwrite:!1,force:!1,silent:!1,...r};let i=h("Updating files.",{silent:r.silent})?.start(),[n,s]=await Promise.all([j(t.resolvedPaths.cwd),K(t.tailwind.baseColor)]),o=[],l=[],f=[];for(let m of e){if(!m.content)continue;let w=Ye(m,t),S=Or(m.path),C=E.join(w,S);m.target&&(C=Ar(n,t,m.target),w=E.dirname(C)),t.tsx||(C=C.replace(/\.tsx?$/,se=>se===".tsx"?".jsx":".js"));let ve=it(C);if(ve&&!r.overwrite){i.stop();let{overwrite:se}=await Nr({type:"confirm",name:"overwrite",message:`The file ${c.info(S)} already exists. Would you like to overwrite?`,initial:!1});if(!se){f.push(E.relative(t.resolvedPaths.cwd,C));continue}i?.start()}it(w)||await nt.mkdir(w,{recursive:!0});let xt=await ee({filename:m.path,raw:m.content,config:t,baseColor:s,transformJsx:!t.tsx},[Q,q,H,Z]);await nt.writeFile(C,xt,"utf-8"),ve?l.push(E.relative(t.resolvedPaths.cwd,C)):o.push(E.relative(t.resolvedPaths.cwd,C))}if(!(o.length||l.length)&&!f.length&&i?.info("No files updated."),o.length){if(i?.succeed(`Created ${o.length} ${o.length===1?"file":"files"}:`),!r.silent)for(let m of o)a.log(` - ${m}`)}else i?.stop();if(l.length&&(h(`Updated ${l.length} ${l.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let m of l)a.log(` - ${m}`);if(f.length&&(h(`Skipped ${f.length} ${l.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let m of f)a.log(` - ${m}`);r.silent||a.break()}async function te(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,...r};let i=h("Checking registry.",{silent:r.silent})?.start(),n=await He(e,t);if(!n)return i?.fail(),x(new Error("Failed to fetch components from registry."));i?.succeed(),await ze(n.tailwind?.config,t,{silent:r.silent}),await Ze(n.cssVars,t,{cleanupDefaultNextStyles:r.isNewProject,silent:r.silent}),await et(n.dependencies,t,{silent:r.silent}),await st(n.files,t,{overwrite:r.overwrite,silent:r.silent}),n.docs&&a.info(n.docs)}import Fr from"path";import{execa as Dr}from"execa";import we from"fs-extra";import ot from"prompts";async function re(e){if(e={srcDir:!1,...e},!e.force){let{proceed:o}=await ot({type:"confirm",name:"proceed",message:`The path ${c.info(e.cwd)} does not contain a package.json file. Would you like to start a new ${c.info("Next.js")} project?`,initial:!0});if(!o)return{projectPath:null,projectName:null}}let t=await Y(e.cwd,{withFallback:!0}),{name:r}=await ot({type:"text",name:"name",message:"What is your project named?",initial:"my-app",format:o=>o.trim(),validate:o=>o.length>128?"Name should be less than 128 characters.":!0}),i=`${e.cwd}/${r}`;try{await we.access(e.cwd,we.constants.W_OK)}catch{a.break(),a.error(`The path ${c.info(e.cwd)} is not writable.`),a.error(`It is likely you do not have write permissions for this folder or the path ${c.info(e.cwd)} does not exist.`),a.break(),process.exit(1)}we.existsSync(Fr.resolve(e.cwd,r,"package.json"))&&(a.break(),a.error(`A project with the name ${c.info(r)} already exists.`),a.error("Please choose a different name and try again."),a.break(),process.exit(1));let n=h("Creating a new Next.js project. This may take a few minutes.").start(),s=["--tailwind","--eslint","--typescript","--app",e.srcDir?"--src-dir":"--no-src-dir","--no-import-alias",`--use-${t}`];try{await Dr("npx",["create-next-app@14.2.16",i,"--silent",...s],{cwd:e.cwd})}catch{a.break(),a.error("Something went wrong creating a new Next.js project. Please try again."),process.exit(1)}return n?.succeed("Creating a new Next.js project."),{projectPath:i,projectName:r}}import{promises as at}from"fs";import Lr from"path";import{SyntaxKind as ie}from"ts-morph";async function lt(e,t,r){if(!e)return;r={silent:!1,...r};let i=Lr.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=h(`Updating ${c.info(i)}`,{silent:r.silent}).start(),s=await at.readFile(t.resolvedPaths.tailwindConfig,"utf8"),o=await _r(s,e,t);await at.writeFile(t.resolvedPaths.tailwindConfig,o,"utf8"),n?.succeed()}async function _r(e,t,r){let i=await J(e,r),n=i.getDescendantsOfKind(ie.ObjectLiteralExpression).find(s=>s.getProperties().some(o=>o.isKind(ie.PropertyAssignment)&&o.getName()==="content"));return n?(zr(n,t),i.getFullText()):e}async function zr(e,t){let r=de(e),i=e.getProperty("content");if(!i){let n={name:"content",initializer:`[${r}${t.join(`${r}, ${r}`)}${r}]`};return e.addPropertyAssignment(n),e}if(i.isKind(ie.PropertyAssignment)){let n=i.getInitializer();if(n?.isKind(ie.ArrayLiteralExpression))for(let s of t){let o=`${r}${s}${r}`;n.getElements().map(l=>l.getText()).includes(o)||n.addElement(o)}return e}return e}import{Command as Wr}from"commander";import xe from"prompts";import{z as P}from"zod";var Vr=P.object({cwd:P.string(),components:P.array(P.string()).optional(),yes:P.boolean(),defaults:P.boolean(),force:P.boolean(),silent:P.boolean(),isNewProject:P.boolean(),srcDir:P.boolean().optional()}),pt=new Wr().name("init").description("initialize your project and install dependencies").argument("[components...]","the components to add or a url to the component.").option("-y, --yes","skip confirmation prompt.",!0).option("-d, --defaults,","use default configuration.",!1).option("-f, --force","force overwrite of existing configuration.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project.",!1).action(async(e,t)=>{try{let r=Vr.parse({cwd:ct.resolve(t.cwd),isNewProject:!1,components:e,...t});await ne(r),a.log(`${c.success("Success!")} Project initialization completed.
22
+ You may now add components.`),a.break()}catch(r){a.break(),x(r)}});async function ne(e){let t;if(e.skipPreflight)t=await j(e.cwd);else{let f=await Oe(e);if(f.errors[k]){let{projectPath:d}=await re(e);d||process.exit(1),e.cwd=d,e.isNewProject=!0}t=f.projectInfo}let r=await je(e.cwd,t),i=r?await Mr(r,e):await Ur(await I(e.cwd));if(!e.yes){let{proceed:f}=await xe({type:"confirm",name:"proceed",message:`Write configuration to ${c.info("components.json")}. Proceed?`,initial:!0});f||process.exit(0)}let n=h("Writing components.json.").start(),s=ct.resolve(e.cwd,"components.json");await Kr.writeFile(s,JSON.stringify(i,null,2),"utf8"),n.succeed();let o=await D(e.cwd,i),l=["index",...e.components||[]];return await te(l,o,{overwrite:!0,silent:e.silent,isNewProject:e.isNewProject||t?.framework.name==="next-app"}),e.isNewProject&&e.srcDir&&await lt(["./src/**/*.{js,ts,jsx,tsx,mdx}"],o,{silent:e.silent}),o}async function Ur(e=null){let[t,r]=await Promise.all([ue(),ge()]);a.info("");let i=await xe([{type:"toggle",name:"typescript",message:`Would you like to use ${c.info("TypeScript")} (recommended)?`,initial:e?.tsx??!0,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${c.info("style")} would you like to use?`,choices:t.map(n=>({title:n.label,value:n.name}))},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${c.info("base color")}?`,choices:r.map(n=>({title:n.label,value:n.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${c.info("global CSS")} file?`,initial:e?.tailwind.css??Te},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${c.info("CSS variables")} for theming?`,initial:e?.tailwind.cssVariables??!0,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${c.info("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${c.info("tailwind.config.js")} located?`,initial:e?.tailwind.config??Ee},{type:"text",name:"components",message:`Configure the import alias for ${c.info("components")}:`,initial:e?.aliases.components??ke},{type:"text",name:"utils",message:`Configure the import alias for ${c.info("utils")}:`,initial:e?.aliases.utils??Ie},{type:"toggle",name:"rsc",message:`Are you using ${c.info("React Server Components")}?`,initial:e?.rsc??!0,active:"yes",inactive:"no"}]);return F.parse({$schema:"https://ui.shadcn.com/schema.json",style:i.style,tailwind:{config:i.tailwindConfig,css:i.tailwindCss,baseColor:i.tailwindBaseColor,cssVariables:i.tailwindCssVariables,prefix:i.tailwindPrefix},rsc:i.rsc,tsx:i.typescript,aliases:{utils:i.utils,components:i.components,lib:i.components.replace(/\/components$/,"lib"),hooks:i.components.replace(/\/components$/,"hooks")}})}async function Mr(e,t){let r=e.style,i=e.tailwind.baseColor,n=e.tailwind.cssVariables;if(!t.defaults){let[s,o]=await Promise.all([ue(),ge()]),l=await xe([{type:"select",name:"style",message:`Which ${c.info("style")} would you like to use?`,choices:s.map(f=>({title:f.label,value:f.name})),initial:s.findIndex(f=>f.name===r)},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${c.info("base color")}?`,choices:o.map(f=>({title:f.label,value:f.name}))},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${c.info("CSS variables")} for theming?`,initial:e?.tailwind.cssVariables,active:"yes",inactive:"no"}]);r=l.style,i=l.tailwindBaseColor,n=l.tailwindCssVariables}return F.parse({$schema:e?.$schema,style:r,tailwind:{...e?.tailwind,baseColor:i,cssVariables:n},rsc:e?.rsc,tsx:e?.tsx,aliases:e?.aliases})}import mt from"path";import be from"fs-extra";async function ft(e){let t={};if(!be.existsSync(e.cwd)||!be.existsSync(mt.resolve(e.cwd,"package.json")))return t[k]=!0,{errors:t,config:null};if(!be.existsSync(mt.resolve(e.cwd,"components.json")))return t[V]=!0,{errors:t,config:null};try{let r=await I(e.cwd);return{errors:t,config:r}}catch{a.break(),a.error(`An invalid ${c.info("components.json")} file was found at ${c.info(e.cwd)}.
23
+ Before you can add components, you must create a valid ${c.info("components.json")} file by running the ${c.info("init")} command.`),a.error(`Learn more at ${c.info("https://ui.shadcn.com/docs/components-json")}.`),a.break(),process.exit(1)}}import dt from"fs/promises";import Gr from"path";async function ut(e,t){let r=Gr.join(t.resolvedPaths.cwd,"app/page.tsx");if(!(await dt.stat(r)).isFile())return;let i=await Ge(e,t.style);if(!i?.meta?.importSpecifier||!i?.meta?.moduleSpecifier)return;let n=`import { ${i?.meta?.importSpecifier} } from "${i.meta.moduleSpecifier}"
17
24
 
18
25
  export default function Page() {
19
26
  return <${i?.meta?.importSpecifier} />
20
- }`;await ot.writeFile(r,n,"utf8")}import{Command as $r}from"commander";import we from"prompts";import{z as S}from"zod";var Or=S.object({components:S.array(S.string()).optional(),yes:S.boolean(),overwrite:S.boolean(),cwd:S.string(),all:S.boolean(),path:S.string().optional(),silent:S.boolean()}),lt=new $r().name("add").description("add a component to your project").argument("[components...]","the components to add or a url to the component.").option("-y, --yes","skip confirmation prompt.",!1).option("-o, --overwrite","overwrite existing files.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-a, --all","add all available components",!1).option("-p, --path <path>","the path to add the component to.").option("-s, --silent","mute output.",!1).action(async(e,t)=>{try{let r=Or.parse({components:e,cwd:jr.resolve(t.cwd),...t}),i=r.components?.some(c=>c.includes("theme-"));if(!r.yes&&i){o.break();let{confirm:c}=await we({type:"confirm",name:"confirm",message:l.warn(`You are about to install a new theme.
21
- Existing CSS variables will be overwritten. Continue?`)});c||(o.break(),o.log("Theme installation cancelled."),o.break(),process.exit(1))}r.components?.length||(r.components=await Nr(r));let{errors:n,config:s}=await st(r);if(n[V]){let{proceed:c}=await we({type:"confirm",name:"proceed",message:`You need to create a ${l.info("component.json")} file to add components. Proceed?`,initial:!0});c||(o.break(),process.exit(1)),s=await re({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!1,silent:!0,isNewProject:!1})}let a=!1;if(n[R]){let{projectPath:c}=await te({cwd:r.cwd,force:r.overwrite});c||(o.break(),process.exit(1)),r.cwd=c,s=await re({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!0,silent:!0,isNewProject:!0}),a=r.components?.length===1&&!!r.components[0].match(/\/chat\/b\//)}if(!s)throw new Error(`Failed to read config at ${l.info(r.cwd)}.`);await ee(r.components,s,r),a&&await at(r.components[0],s)}catch(r){o.break(),b(r)}});async function Nr(e){let t=await D();if(!t)return o.break(),b(new Error("Failed to fetch registry index.")),[];if(e.all)return t.map(n=>n.name);if(e.components?.length)return e.components;let{components:r}=await we({type:"multiselect",name:"components",message:"Which components would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:!1,choices:t.filter(n=>n.type==="registry:ui").map(n=>({title:n.name,value:n.name,selected:e.all?!0:e.components?.includes(n.name)}))});r?.length||(o.warn("No components selected. Exiting."),o.info(""),process.exit(1));let i=S.array(S.string()).safeParse(r);return i.success?i.data:(o.error(""),b(new Error("Something went wrong. Please try again.")),[])}import{existsSync as xe,promises as Ar}from"fs";import be from"path";import{Command as Fr}from"commander";import{diffLines as Lr}from"diff";import{z as K}from"zod";var _r=K.object({component:K.string().optional(),yes:K.boolean(),cwd:K.string(),path:K.string().optional()}),pt=new Fr().name("diff").description("check for updates against the registry").argument("[component]","the component name").option("-y, --yes","skip confirmation prompt.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t)=>{try{let r=_r.parse({component:e,...t}),i=be.resolve(r.cwd);xe(i)||(o.error(`The path ${i} does not exist. Please try again.`),process.exit(1));let n=await T(i);n||(o.warn(`Configuration is missing. Please run ${l.success("init")} to create a components.json file.`),process.exit(1));let s=await D();if(s||(b(new Error("Failed to fetch registry index.")),process.exit(1)),!r.component){let m=n.resolvedPaths.components,f=s.filter(d=>{for(let y of d.files??[]){let W=be.resolve(m,typeof y=="string"?y:y.path);if(xe(W))return!0}return!1}),x=[];for(let d of f){let y=await ct(d,n);y.length&&x.push({name:d.name,changes:y})}x.length||(o.info("No updates found."),process.exit(0)),o.info("The following components have updates available:");for(let d of x){o.info(`- ${d.name}`);for(let y of d.changes)o.info(` - ${y.filePath}`)}o.break(),o.info(`Run ${l.success("diff <component>")} to see the changes.`),process.exit(0)}let a=s.find(m=>m.name===r.component);a||(o.error(`The component ${l.success(r.component)} does not exist.`),process.exit(1));let c=await ct(a,n);c.length||(o.info(`No updates found for ${r.component}.`),process.exit(0));for(let m of c)o.info(`- ${m.filePath}`),await Dr(m.patch),o.info("")}catch(r){b(r)}});async function ct(e,t){let r=await Ve(t.style,[e]),i=await z(t.tailwind.baseColor);if(!r)return[];let n=[];for(let s of r){let a=await Me(t,s);if(a)for(let c of s.files??[]){let m=be.resolve(a,typeof c=="string"?c:c.path);if(!xe(m))continue;let f=await Ar.readFile(m,"utf8");if(typeof c=="string"||!c.content)continue;let x=await q({filename:c.path,raw:c.content,config:t,baseColor:i}),d=Lr(x,f);d.length>1&&n.push({filePath:m,patch:d})}}return n}async function Dr(e){e.forEach(t=>{if(t)return t.added?process.stdout.write(l.success(t.value)):t.removed?process.stdout.write(l.error(t.value)):process.stdout.write(t.value)})}import{Command as Kr}from"commander";var mt={name:"shadcn",version:"0.0.0-beta.58be5c4",description:"Add components to your apps.",publishConfig:{access:"public"},license:"MIT",author:{name:"shadcn",url:"https://twitter.com/shadcn"},repository:{type:"git",url:"https://github.com/shadcn/ui.git",directory:"packages/cli"},files:["dist"],keywords:["components","ui","tailwind","radix-ui","shadcn"],type:"module",exports:"./dist/index.js",bin:"./dist/index.js",scripts:{dev:"tsup --watch",build:"tsup",typecheck:"tsc --noEmit",clean:"rimraf dist && rimraf components","start:dev":"cross-env REGISTRY_URL=http://localhost:3333/r node dist/index.js",start:"node dist/index.js","format:write":'prettier --write "**/*.{ts,tsx,mdx}" --cache',"format:check":'prettier --check "**/*.{ts,tsx,mdx}" --cache',release:"changeset version","pub:beta":"pnpm build && pnpm publish --no-git-checks --access public --tag beta","pub:next":"pnpm build && pnpm publish --no-git-checks --access public --tag next","pub:release":"pnpm build && pnpm publish --access public",test:"vitest run","test:dev":"REGISTRY_URL=http://localhost:3333/r vitest run"},dependencies:{"@antfu/ni":"^0.21.4","@babel/core":"^7.22.1","@babel/parser":"^7.22.6","@babel/plugin-transform-typescript":"^7.22.5",commander:"^10.0.0",cosmiconfig:"^8.1.3",deepmerge:"^4.3.1",diff:"^5.1.0",execa:"^7.0.0","fast-glob":"^3.3.2","fs-extra":"^11.1.0","https-proxy-agent":"^6.2.0",kleur:"^4.1.5","lodash.template":"^4.5.0","node-fetch":"^3.3.0",ora:"^6.1.2",postcss:"^8.4.24",prompts:"^2.4.2",recast:"^0.23.2","stringify-object":"^5.0.0","ts-morph":"^18.0.0","tsconfig-paths":"^4.2.0",zod:"^3.20.2"},devDependencies:{"@types/babel__core":"^7.20.1","@types/diff":"^5.0.3","@types/fs-extra":"^11.0.1","@types/lodash.template":"^4.5.1","@types/prompts":"^2.4.2","@types/stringify-object":"^4.0.5",rimraf:"^6.0.1",tsup:"^6.6.3","type-fest":"^3.8.0",typescript:"^4.9.3"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Wr(){let e=new Kr().name("shadcn").description("add components and dependencies to your project").version(mt.version||"1.0.0","-v, --version","display the version number");e.addCommand(it).addCommand(lt).addCommand(pt),e.parse()}Wr();
27
+ }`;await dt.writeFile(r,n,"utf8")}import{Command as Jr}from"commander";import Se from"prompts";import{z as b}from"zod";var Yr=b.object({components:b.array(b.string()).optional(),yes:b.boolean(),overwrite:b.boolean(),cwd:b.string(),all:b.boolean(),path:b.string().optional(),silent:b.boolean(),srcDir:b.boolean().optional()}),gt=new Jr().name("add").description("add a component to your project").argument("[components...]","the components to add or a url to the component.").option("-y, --yes","skip confirmation prompt.",!1).option("-o, --overwrite","overwrite existing files.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-a, --all","add all available components",!1).option("-p, --path <path>","the path to add the component to.").option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project.",!1).action(async(e,t)=>{try{let r=Yr.parse({components:e,cwd:Br.resolve(t.cwd),...t}),i=r.components?.some(l=>l.includes("theme-"));if(!r.yes&&i){a.break();let{confirm:l}=await Se({type:"confirm",name:"confirm",message:c.warn(`You are about to install a new theme.
28
+ Existing CSS variables will be overwritten. Continue?`)});l||(a.break(),a.log("Theme installation cancelled."),a.break(),process.exit(1))}r.components?.length||(r.components=await Hr(r));let{errors:n,config:s}=await ft(r);if(n[V]){let{proceed:l}=await Se({type:"confirm",name:"proceed",message:`You need to create a ${c.info("components.json")} file to add components. Proceed?`,initial:!0});l||(a.break(),process.exit(1)),s=await ne({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!1,silent:!0,isNewProject:!1,srcDir:r.srcDir})}let o=!1;if(n[k]){let{projectPath:l}=await re({cwd:r.cwd,force:r.overwrite,srcDir:r.srcDir});l||(a.break(),process.exit(1)),r.cwd=l,s=await ne({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!0,silent:!0,isNewProject:!0,srcDir:r.srcDir}),o=r.components?.length===1&&!!r.components[0].match(/\/chat\/b\//)}if(!s)throw new Error(`Failed to read config at ${c.info(r.cwd)}.`);await te(r.components,s,r),o&&await ut(r.components[0],s)}catch(r){a.break(),x(r)}});async function Hr(e){let t=await z();if(!t)return a.break(),x(new Error("Failed to fetch registry index.")),[];if(e.all)return t.map(n=>n.name);if(e.components?.length)return e.components;let{components:r}=await Se({type:"multiselect",name:"components",message:"Which components would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:!1,choices:t.filter(n=>n.type==="registry:ui").map(n=>({title:n.name,value:n.name,selected:e.all?!0:e.components?.includes(n.name)}))});r?.length||(a.warn("No components selected. Exiting."),a.info(""),process.exit(1));let i=b.array(b.string()).safeParse(r);return i.success?i.data:(a.error(""),x(new Error("Something went wrong. Please try again.")),[])}import{existsSync as Ce,promises as Qr}from"fs";import Pe from"path";import{Command as Xr}from"commander";import{diffLines as qr}from"diff";import{z as W}from"zod";var Zr=W.object({component:W.string().optional(),yes:W.boolean(),cwd:W.string(),path:W.string().optional()}),yt=new Xr().name("diff").description("check for updates against the registry").argument("[component]","the component name").option("-y, --yes","skip confirmation prompt.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t)=>{try{let r=Zr.parse({component:e,...t}),i=Pe.resolve(r.cwd);Ce(i)||(a.error(`The path ${i} does not exist. Please try again.`),process.exit(1));let n=await I(i);n||(a.warn(`Configuration is missing. Please run ${c.success("init")} to create a components.json file.`),process.exit(1));let s=await z();if(s||(x(new Error("Failed to fetch registry index.")),process.exit(1)),!r.component){let f=n.resolvedPaths.components,d=s.filter(w=>{for(let S of w.files??[]){let C=Pe.resolve(f,typeof S=="string"?S:S.path);if(Ce(C))return!0}return!1}),m=[];for(let w of d){let S=await ht(w,n);S.length&&m.push({name:w.name,changes:S})}m.length||(a.info("No updates found."),process.exit(0)),a.info("The following components have updates available:");for(let w of m){a.info(`- ${w.name}`);for(let S of w.changes)a.info(` - ${S.filePath}`)}a.break(),a.info(`Run ${c.success("diff <component>")} to see the changes.`),process.exit(0)}let o=s.find(f=>f.name===r.component);o||(a.error(`The component ${c.success(r.component)} does not exist.`),process.exit(1));let l=await ht(o,n);l.length||(a.info(`No updates found for ${r.component}.`),process.exit(0));for(let f of l)a.info(`- ${f.filePath}`),await ei(f.patch),a.info("")}catch(r){x(r)}});async function ht(e,t){let r=await Be(t.style,[e]),i=await K(t.tailwind.baseColor);if(!r)return[];let n=[];for(let s of r){let o=await Je(t,s);if(o)for(let l of s.files??[]){let f=Pe.resolve(o,typeof l=="string"?l:l.path);if(!Ce(f))continue;let d=await Qr.readFile(f,"utf8");if(typeof l=="string"||!l.content)continue;let m=await ee({filename:l.path,raw:l.content,config:t,baseColor:i}),w=qr(m,d);w.length>1&&n.push({filePath:f,patch:w})}}return n}async function ei(e){e.forEach(t=>{if(t)return t.added?process.stdout.write(c.success(t.value)):t.removed?process.stdout.write(c.error(t.value)):process.stdout.write(t.value)})}import{Command as ri}from"commander";var wt={name:"shadcn",version:"0.0.0-beta.8ea4ab5",description:"Add components to your apps.",publishConfig:{access:"public"},license:"MIT",author:{name:"shadcn",url:"https://twitter.com/shadcn"},repository:{type:"git",url:"https://github.com/shadcn/ui.git",directory:"packages/shadcn"},files:["dist"],keywords:["components","ui","tailwind","radix-ui","shadcn"],type:"module",exports:"./dist/index.js",bin:"./dist/index.js",scripts:{dev:"tsup --watch",build:"tsup",typecheck:"tsc --noEmit",clean:"rimraf dist && rimraf components","start:dev":"cross-env REGISTRY_URL=http://localhost:3333/r node dist/index.js",start:"node dist/index.js","format:write":'prettier --write "**/*.{ts,tsx,mdx}" --cache',"format:check":'prettier --check "**/*.{ts,tsx,mdx}" --cache',release:"changeset version","pub:beta":"pnpm build && pnpm publish --no-git-checks --access public --tag beta","pub:next":"pnpm build && pnpm publish --no-git-checks --access public --tag next","pub:release":"pnpm build && pnpm publish --access public",test:"vitest run","test:dev":"REGISTRY_URL=http://localhost:3333/r vitest run"},dependencies:{"@antfu/ni":"^0.21.4","@babel/core":"^7.22.1","@babel/parser":"^7.22.6","@babel/plugin-transform-typescript":"^7.22.5",commander:"^10.0.0",cosmiconfig:"^8.1.3",deepmerge:"^4.3.1",diff:"^5.1.0",execa:"^7.0.0","fast-glob":"^3.3.2","fs-extra":"^11.1.0","https-proxy-agent":"^6.2.0",kleur:"^4.1.5","lodash.template":"^4.5.0","node-fetch":"^3.3.0",ora:"^6.1.2",postcss:"^8.4.24",prompts:"^2.4.2",recast:"^0.23.2","stringify-object":"^5.0.0","ts-morph":"^18.0.0","tsconfig-paths":"^4.2.0",zod:"^3.20.2"},devDependencies:{"@types/babel__core":"^7.20.1","@types/diff":"^5.0.3","@types/fs-extra":"^11.0.1","@types/lodash.template":"^4.5.1","@types/prompts":"^2.4.2","@types/stringify-object":"^4.0.5",rimraf:"^6.0.1",tsup:"^6.6.3","type-fest":"^3.8.0",typescript:"^4.9.3"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function ii(){let e=new ri().name("shadcn").description("add components and dependencies to your project").version(wt.version||"1.0.0","-v, --version","display the version number");e.addCommand(pt).addCommand(gt).addCommand(yt),e.parse()}ii();
22
29
  //# sourceMappingURL=index.js.map