shadcn 2.0.6 → 2.0.8
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 +14 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
To start over, remove the ${l.info("components.json")} file and run ${l.info("init")} again.`),a.break(),process.exit(1)),r?.succeed();let i=y("Verifying framework.",{silent:e.silent}).start(),n=await
|
|
2
|
+
import zr from"path";import{promises as Nr}from"fs";import lt from"path";import $e from"path";var T="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 N from"path";import{cyan as xt,green as bt,red as St,yellow as Ct}from"kleur/colors";var l={error:St,warn:Ct,info:xt,success:bt};import{createMatchPath as Pt}from"tsconfig-paths";async function R(e,t){return Pt(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}import{cosmiconfig as vt}from"cosmiconfig";import{loadConfig as Rt}from"tsconfig-paths";import{z as h}from"zod";var Te="@/components",Ie="@/lib/utils",ke="app/globals.css",Ee="tailwind.config.js";var Tt=vt("components",{searchPlaces:["components.json"]}),A=h.object({$schema:h.string().optional(),style:h.string(),rsc:h.coerce.boolean().default(!1),tsx:h.coerce.boolean().default(!0),tailwind:h.object({config:h.string(),css:h.string(),baseColor:h.string(),cssVariables:h.boolean().default(!0),prefix:h.string().default("").optional()}),aliases:h.object({components:h.string(),utils:h.string(),ui:h.string().optional(),lib:h.string().optional(),hooks:h.string().optional()})}).strict(),It=A.extend({resolvedPaths:h.object({cwd:h.string(),tailwindConfig:h.string(),tailwindCss:h.string(),utils:h.string(),components:h.string(),lib:h.string(),hooks:h.string(),ui:h.string()})});async function I(e){let t=await kt(e);return t?await F(e,t):null}async function F(e,t){let r=await Rt(e);if(r.resultType==="failed")throw new Error(`Failed to load ${t.tsx?"tsconfig":"jsconfig"}.json. ${r.message??""}`.trim());return It.parse({...t,resolvedPaths:{cwd:e,tailwindConfig:N.resolve(e,t.tailwind.config),tailwindCss:N.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):N.resolve(await R(t.aliases.components,r)??e,"ui"),lib:t.aliases.lib?await R(t.aliases.lib,r):N.resolve(await R(t.aliases.utils,r)??e,".."),hooks:t.aliases.hooks?await R(t.aliases.hooks,r):N.resolve(await R(t.aliases.components,r)??e,"..","hooks")}})}async function kt(e){try{let t=await Tt.search(e);return t?A.parse(t.config):null}catch{let r=`${e}/component.json`;throw new Error(`Invalid configuration found in ${l.info(r)}.`)}}import M from"fast-glob";import ce from"fs-extra";import{loadConfig as Et}from"tsconfig-paths";var G=["**/node_modules/**",".next","public","dist","build"];async function j(e){let[t,r,i,n,s,o]=await Promise.all([M.glob("**/{next,vite,astro}.config.*|gatsby-config.*|composer.json",{cwd:e,deep:3,ignore:G}),ce.pathExists(le.resolve(e,"src")),Nt(e),$t(e),jt(e),Ot(e)]),c=await ce.pathExists(le.resolve(e,`${r?"src/":""}app`)),p={framework:v.manual,isSrcDir:r,isRSC:!1,isTsx:i,tailwindConfigFile:n,tailwindCssFile:s,aliasPrefix:o};return t.length?t.find(d=>d.startsWith("next.config."))?.length?(p.framework=c?v["next-app"]:v["next-pages"],p.isRSC=c,p):t.find(d=>d.startsWith("astro.config."))?.length?(p.framework=v.astro,p):t.find(d=>d.startsWith("gatsby-config."))?.length?(p.framework=v.gatsby,p):t.find(d=>d.startsWith("composer.json"))?.length?(p.framework=v.laravel,p):(t.find(d=>d.startsWith("vite.config."))?.length&&(p.framework=c?v.remix:v.vite),p):p}async function jt(e){let t=await M.glob(["**/*.css","**/*.scss"],{cwd:e,deep:5,ignore:G});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 $t(e){let t=await M.glob("tailwind.config.*",{cwd:e,deep:3,ignore:G});return t.length?t[0]:null}async function Ot(e){let t=await Et(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 Nt(e){return(await M.glob("tsconfig.*",{cwd:e,deep:1,ignore:G})).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 F(e,n)}var a={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 At from"ora";function y(e,t){return At({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[T]=!0,{errors:t,projectInfo:null};let r=y("Preflight checks.",{silent:e.silent}).start();pe.existsSync($e.resolve(e.cwd,"components.json"))&&!e.force&&(r?.fail(),a.break(),a.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.`),a.break(),process.exit(1)),r?.succeed();let i=y("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 ${l.info(e.cwd)}.
|
|
4
4
|
Visit ${l.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 ${l.info(n.framework.label)}.`);let s=y("Validating Tailwind CSS.",{silent:e.silent}).start();!n?.tailwindConfigFile||!n?.tailwindCssFile?(t[oe]=!0,s?.fail()):s?.succeed();let o=y("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 ${l.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 ${l.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 ${l.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
|
|
5
|
+
Once configured, you can use the cli to add components.`),a.break(),process.exit(1)),i?.succeed(`Verifying framework. Found ${l.info(n.framework.label)}.`);let s=y("Validating Tailwind CSS.",{silent:e.silent}).start();!n?.tailwindConfigFile||!n?.tailwindCssFile?(t[oe]=!0,s?.fail()):s?.succeed();let o=y("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 ${l.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 ${l.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 ${l.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 Ft}from"zod";function b(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 Ft.ZodError){a.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))a.error(`- ${l.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 Yt from"path";import{z as m}from"zod";var Ne=m.enum(["registry:style","registry:lib","registry:example","registry:block","registry:component","registry:ui","registry:hook","registry:theme","registry:page"]),Ae=m.object({path:m.string(),content:m.string().optional(),type:Ne,target:m.string().optional()}),Dt=m.object({config:m.object({content:m.array(m.string()).optional(),theme:m.record(m.string(),m.any()).optional(),plugins:m.array(m.string()).optional()}).optional()}),Lt=m.object({light:m.record(m.string(),m.string()).optional(),dark:m.record(m.string(),m.string()).optional()}),D=m.object({name:m.string(),type:Ne,description:m.string().optional(),dependencies:m.array(m.string()).optional(),devDependencies:m.array(m.string()).optional(),registryDependencies:m.array(m.string()).optional(),files:m.array(Ae).optional(),tailwind:Dt.optional(),cssVars:Lt.optional(),meta:m.record(m.string(),m.any()).optional(),docs:m.string().optional()}),me=m.array(D.extend({files:m.array(m.union([m.string(),Ae])).optional()})),Fe=m.array(m.object({name:m.string(),label:m.string()})),De=m.object({inlineColors:m.object({light:m.record(m.string(),m.string()),dark:m.record(m.string(),m.string())}),cssVars:m.object({light:m.record(m.string(),m.string()),dark:m.record(m.string(),m.string())}),inlineColorsTemplate:m.string(),cssVarsTemplate:m.string()}),Le=D.pick({dependencies:!0,devDependencies:!0,files:!0,tailwind:!0,cssVars:!0,docs:!0});import{promises as fe}from"fs";import{tmpdir as _t}from"os";import L from"path";import zt from"deepmerge";import Kt from"stringify-object";import{Project as Wt,QuoteKind as Vt,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=y(`Updating ${l.info(i)}`,{silent:r.silent}).start(),s=await fe.readFile(t.resolvedPaths.tailwindConfig,"utf8"),o=await Ut(s,e,t);await fe.writeFile(t.resolvedPaths.tailwindConfig,o,"utf8"),n?.succeed()}async function Ut(e,t,r){let i=await B(e,r),n=i.getDescendantsOfKind(u.ObjectLiteralExpression).find(o=>o.getProperties().some(c=>c.isKind(u.PropertyAssignment)&&c.getName()==="content"));if(!n)return e;let s=de(n);return Mt(n,{name:"darkMode",value:"class"},{quoteChar:s}),t.plugins?.forEach(o=>{Bt(n,o)}),t.theme&&await Gt(n,t.theme),i.getFullText()}function Mt(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 Gt(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 Jt(n),o=zt(s,t),c=Kt(o).replace(/\'\"/g,"'").replace(/\"\'/g,"'").replace(/\'\[/g,"[").replace(/\]\'/g,"]").replace(/\'\\\'/g,"'").replace(/\\\'/g,"'").replace(/\\\'\'/g,"'").replace(/\'\'/g,"'");i.replaceWithText(c)}We(e)}function Bt(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 B(e,t){let r=await fe.mkdtemp(L.join(_t(),"shadcn-")),i=t?.resolvedPaths?.tailwindConfig||"tailwind.config.ts",n=L.join(r,`shadcn-${L.basename(i)}`);return new Wt({compilerOptions:{}}).createSourceFile(n,e,{scriptKind:L.extname(i)===".ts"?_e.TS:_e.JS})}function de(e){return e.getFirstDescendantByKind(u.StringLiteral)?.getQuoteKind()===Vt.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 Jt(e){let r=(await B(`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 Ht from"node-fetch";import{z as Xt}from"zod";var qt=process.env.REGISTRY_URL??"https://ui.shadcn.com/r",Zt=process.env.https_proxy?new Qt(process.env.https_proxy):void 0;async function z(){try{let[e]=await O(["index.json"]);return me.parse(e)}catch(e){a.error(`
|
|
6
6
|
`),b(e)}}async function ue(){try{let[e]=await O(["styles/index.json"]);return Fe.parse(e)}catch(e){return a.error(`
|
|
7
|
-
`),b(e),[]}}async function J(e,t){try{let[r]=await O([he(e)?e:`styles/${t}/${e}.json`]);return D.parse(r)}catch(r){return a.break(),b(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 O([`colors/${e}.json`]);return De.parse(t)}catch(t){b(t)}}async function Ge(e,t){try{let r=t.map(n=>`styles/${e}/${n.name}.json`),i=await O(r);return me.parse(i)}catch(r){b(r)}}async function Be(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?
|
|
7
|
+
`),b(e),[]}}async function J(e,t){try{let[r]=await O([he(e)?e:`styles/${t}/${e}.json`]);return D.parse(r)}catch(r){return a.break(),b(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 O([`colors/${e}.json`]);return De.parse(t)}catch(t){b(t)}}async function Ge(e,t){try{let r=t.map(n=>`styles/${e}/${n.name}.json`),i=await O(r);return me.parse(i)}catch(r){b(r)}}async function Be(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?Yt.join(e.resolvedPaths[i],n):null}async function O(e){try{return await Promise.all(e.map(async r=>{let i=Qe(r),n=await Ht(i,{agent:Zt});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 ${l.info(i)}.
|
|
8
8
|
If this is a remote registry, you may need to authenticate.`);if(n.status===404)throw new Error(`The component at ${l.info(i)} was not found.
|
|
9
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 ${l.info(i)}.
|
|
10
10
|
If this is a remote registry, you may need to authenticate or a token.`);let o=await n.json(),c=o&&typeof o=="object"&&"error"in o?o.error:n.statusText||s[n.status];throw new Error(`Failed to fetch from ${l.info(i)}.
|
|
11
11
|
${c}`)}return n.json()}))}catch(t){return a.error(`
|
|
12
|
-
`),b(t),[]}}function Je(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 Ye(e,t){try{if(!await z())return null;let i=(await Promise.all(e.map(async f=>await J(f,t.style)))).filter(f=>f!==null);if(!i.length)return null;let n=i.map(f=>f.registryDependencies??[]).flat(),s=Array.from(new Set(n)),o=Array.from([...e,...s]).map(f=>Qe(he(f)?f:`styles/${t.style}/${f}.json`)),c=await O(o),p=
|
|
13
|
-
`)}),Le.parse({dependencies:_.all(p.map(f=>f.dependencies??[])),devDependencies:_.all(p.map(f=>f.devDependencies??[])),files:_.all(p.map(f=>f.files??[])),tailwind:d,cssVars:
|
|
14
|
-
`}}),e.append(r)),t.forEach(({selector:i,apply:n})=>{r?.nodes?.find(o=>o.type==="rule"&&o.selector===i)||r?.append(
|
|
12
|
+
`),b(t),[]}}function Je(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 Ye(e,t){try{if(!await z())return null;let i=(await Promise.all(e.map(async f=>await J(f,t.style)))).filter(f=>f!==null);if(!i.length)return null;let n=i.map(f=>f.registryDependencies??[]).flat(),s=Array.from(new Set(n)),o=Array.from([...e,...s]).map(f=>Qe(he(f)?f:`styles/${t.style}/${f}.json`)),c=await O(o),p=Xt.array(D).parse(c);if(!p)return null;if(e.includes("index")){let f=await J("index",t.style);if(f&&p.unshift(f),t.tailwind.baseColor){let S=await er(t.tailwind.baseColor,t);S&&p.unshift(S)}}let d={};p.forEach(f=>{d=_(d,f.tailwind??{})});let g={};p.forEach(f=>{g=_(g,f.cssVars??{})});let x="";return p.forEach(f=>{f.docs&&(x+=`${f.docs}
|
|
13
|
+
`)}),Le.parse({dependencies:_.all(p.map(f=>f.dependencies??[])),devDependencies:_.all(p.map(f=>f.devDependencies??[])),files:_.all(p.map(f=>f.files??[])),tailwind:d,cssVars:g,docs:x})}catch(r){return b(r),null}}async function er(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`${qt}/${e}`}function he(e){try{return new URL(e),!0}catch{return!1}}import{promises as He}from"fs";import tr from"path";import $ from"postcss";import rr from"postcss/lib/at-rule";async function qe(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=tr.relative(t.resolvedPaths.cwd,i),s=y(`Updating ${l.info(n)}`,{silent:r.silent}).start(),o=await He.readFile(i,"utf8"),c=await ir(o,e,t,{cleanupDefaultNextStyles:r.cleanupDefaultNextStyles});await He.writeFile(i,c,"utf8"),s.succeed()}async function ir(e,t,r,i){i={cleanupDefaultNextStyles:!1,...i};let n=[sr(t)];return i.cleanupDefaultNextStyles&&n.push(or()),r.tailwind.cssVariables&&n.push(nr()),(await $(n).process(e,{from:void 0})).css}function nr(){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(c=>c.type==="atrule"&&c.name==="apply"&&c.params===s))));r||(r=$.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($.rule({selector:i,nodes:[$.atRule({name:"apply",params:n,raws:{semicolon:!0,before:`
|
|
15
15
|
`}})],raws:{semicolon:!0,between:" ",before:`
|
|
16
|
-
`}}))})}}}function
|
|
17
|
-
`,between:" "}}),t.append(r)),r!==void 0&&Object.entries(e).forEach(([i,n])=>{let s=i==="light"?":root":`.${i}`;
|
|
18
|
-
`}}),e.append(i)),Object.entries(r).forEach(([n,s])=>{let o=`--${n.replace(/^--/,"")}`,c=j.decl({prop:o,value:s,raws:{semicolon:!0}}),p=i?.nodes.find(d=>d.type==="decl"&&d.prop===o);p?p.replaceWith(c):i?.append(c)})}import{detect as ar}from"@antfu/ni";async function Y(e,{withFallback:t}={withFallback:!1}){let r=await ar({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 lr}from"execa";async function qe(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let i=y("Installing dependencies.",{silent:r.silent})?.start(),n=await Y(t.resolvedPaths.cwd);await lr(n,[n==="npm"?"install":"add",...e],{cwd:t.resolvedPaths.cwd}),i?.succeed()}import{existsSync as tt,promises as rt}from"fs";import $,{basename as vr}from"path";import{promises as wr}from"fs";import{tmpdir as xr}from"os";import et from"path";import{SyntaxKind as cr}from"ts-morph";var Q=async({sourceFile:e,config:t,baseColor:r})=>(t.tailwind?.cssVariables||!r?.inlineColors||e.getDescendantsOfKind(cr.StringLiteral).forEach(i=>{let n=i.getText();if(n){let s=mr(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 pr=["bg-","text-","border-","ring-offset-","ring-"];function mr(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,c,p]=ye(s),d=pr.find(x=>c?.startsWith(x));if(!d){i.has(s)||i.add(s);continue}let u=c?.replace(d,"");if(u&&u in t.light){i.add([o,`${d}${t.light[u]}`].filter(Boolean).join(":")+(p?`/${p}`:"")),n.add(["dark",o,`${d}${t.dark[u]}`].filter(Boolean).join(":")+(p?`/${p}`:""));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=fr(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 fr(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 dr}from"@babel/core";import{parse as ur}from"@babel/parser";import gr from"@babel/plugin-transform-typescript";import*as X from"recast";var hr={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"]},Ze=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let i=X.parse(r,{parser:{parse:s=>ur(s,hr)}}),n=dr(i,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[gr],configFile:!1});if(!n||!n.ast)throw new Error("Failed to transform JSX");return X.print(n.ast).code};import{SyntaxKind as yr}from"ts-morph";var q=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(yr.ExpressionStatement);return r?.getText()==='"use client"'&&r.remove(),e};import{Project as br,ScriptKind as Sr}from"ts-morph";import{SyntaxKind as w}from"ts-morph";var Z=async({sourceFile:e,config:t})=>(t.tailwind?.prefix&&(e.getDescendantsOfKind(w.CallExpression).filter(r=>r.getExpression().getText()==="cva").forEach(r=>{if(r.getArguments()[0]?.isKind(w.StringLiteral)){let i=r.getArguments()[0];i&&i.replaceWithText(`"${k(i.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}r.getArguments()[1]?.isKind(w.ObjectLiteralExpression)&&r.getArguments()[1]?.getDescendantsOfKind(w.PropertyAssignment).find(i=>i.getName()==="variants")?.getDescendantsOfKind(w.PropertyAssignment).forEach(i=>{i.getDescendantsOfKind(w.PropertyAssignment).forEach(n=>{let s=n.getInitializerIfKind(w.StringLiteral);s&&s?.replaceWithText(`"${k(s.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)})})}),e.getDescendantsOfKind(w.JsxAttribute).forEach(r=>{if(r.getName()==="className"){if(r.getInitializer()?.isKind(w.StringLiteral)){let i=r.getInitializer();i&&i.replaceWithText(`"${k(i.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}if(r.getInitializer()?.isKind(w.JsxExpression)){let i=r.getInitializer()?.getDescendantsOfKind(w.CallExpression).find(n=>n.getExpression().getText()==="cn");i&&i.getArguments().forEach(n=>{(n.isKind(w.ConditionalExpression)||n.isKind(w.BinaryExpression))&&n.getChildrenOfKind(w.StringLiteral).forEach(s=>{s.replaceWithText(`"${k(s.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}),n.isKind(w.StringLiteral)&&n.replaceWithText(`"${k(n.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)})}}r.getName()==="classNames"&&r.getInitializer()?.isKind(w.JsxExpression)&&r.getDescendantsOfKind(w.PropertyAssignment).forEach(i=>{if(i.getInitializer()?.isKind(w.CallExpression)){let n=i.getInitializerIfKind(w.CallExpression);n&&n.getArguments().forEach(s=>{s.isKind(w.ConditionalExpression)&&s.getChildrenOfKind(w.StringLiteral).forEach(o=>{o.replaceWithText(`"${k(o.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}),s.isKind(w.StringLiteral)&&s.replaceWithText(`"${k(s.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)})}if(i.getInitializer()?.isKind(w.StringLiteral)&&i.getName()!=="variant"){let n=i.getInitializer();n&&n.replaceWithText(`"${k(n.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}})})),e);function k(e,t=""){let r=e.split(" "),i=[];for(let n of r){let[s,o,c]=ye(n);s?c?i.push(`${s}:${t}${o}/${c}`):i.push(`${s}:${t}${o}`):c?i.push(`${t}${o}/${c}`):i.push(`${t}${o}`)}return i.join(" ")}var Cr=new br({compilerOptions:{}});async function Pr(e){let t=await wr.mkdtemp(et.join(xr(),"shadcn-"));return et.join(t,e)}async function ee(e,t=[H,q,Q,Z]){let r=await Pr(e.filename),i=Cr.createSourceFile(r,e.raw,{scriptKind:Sr.TSX});for(let n of t)n({sourceFile:i,...e});return e.transformJsx?await Ze({sourceFile:i,...e}):i.getText()}import Tr from"prompts";async function it(e,t,r){if(!e?.length)return;r={overwrite:!1,force:!1,silent:!1,...r};let i=y("Updating files.",{silent:r.silent})?.start(),[n,s]=await Promise.all([E(t.resolvedPaths.cwd),K(t.tailwind.baseColor)]),o=[],c=[],p=[];for(let u of e){if(!u.content)continue;let x=Je(u,t),f=vr(u.path),S=$.join(x,f);u.target&&(S=n?.isSrcDir?$.join(t.resolvedPaths.cwd,"src",u.target):$.join(t.resolvedPaths.cwd,u.target),x=$.dirname(S)),t.tsx||(S=S.replace(/\.tsx?$/,se=>se===".tsx"?".jsx":".js"));let ve=tt(S);if(ve&&!r.overwrite){i.stop();let{overwrite:se}=await Tr({type:"confirm",name:"overwrite",message:`The file ${l.info(f)} already exists. Would you like to overwrite?`,initial:!1});if(!se){p.push($.relative(t.resolvedPaths.cwd,S));continue}i?.start()}tt(x)||await rt.mkdir(x,{recursive:!0});let yt=await ee({filename:u.path,raw:u.content,config:t,baseColor:s,transformJsx:!t.tsx},[H,q,Q,Z]);await rt.writeFile(S,yt,"utf-8"),ve?c.push($.relative(t.resolvedPaths.cwd,S)):o.push($.relative(t.resolvedPaths.cwd,S))}if(!(o.length||c.length)&&!p.length&&i?.info("No files updated."),o.length){if(i?.succeed(`Created ${o.length} ${o.length===1?"file":"files"}:`),!r.silent)for(let u of o)a.log(` - ${u}`)}else i?.stop();if(c.length&&(y(`Updated ${c.length} ${c.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let u of c)a.log(` - ${u}`);if(p.length&&(y(`Skipped ${p.length} ${c.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let u of p)a.log(` - ${u}`);r.silent||a.break()}async function te(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,...r};let i=y("Checking registry.",{silent:r.silent})?.start(),n=await Ye(e,t);if(!n)return i?.fail(),b(new Error("Failed to fetch components from registry."));i?.succeed(),await ze(n.tailwind?.config,t,{silent:r.silent}),await Xe(n.cssVars,t,{cleanupDefaultNextStyles:r.isNewProject,silent:r.silent}),await qe(n.dependencies,t,{silent:r.silent}),await it(n.files,t,{overwrite:r.overwrite,silent:r.silent}),n.docs&&a.info(n.docs)}import Ir from"path";import{execa as Rr}from"execa";import we from"fs-extra";import nt from"prompts";async function re(e){if(e={srcDir:!1,...e},!e.force){let{proceed:o}=await nt({type:"confirm",name:"proceed",message:`The path ${l.info(e.cwd)} is does not contain a package.json file. Would you like to start a new ${l.info("Next.js")} project?`,initial:!0});if(!o)return{projectPath:null,projectName:null}}let t=await Y(e.cwd),{name:r}=await nt({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 ${l.info(e.cwd)} is not writable.`),a.error(`It is likely you do not have write permissions for this folder or the path ${l.info(e.cwd)} does not exist.`),a.break(),process.exit(1)}we.existsSync(Ir.resolve(e.cwd,r,"package.json"))&&(a.break(),a.error(`A project with the name ${l.info(r)} already exists.`),a.error("Please choose a different name and try again."),a.break(),process.exit(1));let n=y("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 Rr("npx",["create-next-app@latest",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 st}from"fs";import kr from"path";import{SyntaxKind as ie}from"ts-morph";async function ot(e,t,r){if(!e)return;r={silent:!1,...r};let i=kr.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=y(`Updating ${l.info(i)}`,{silent:r.silent}).start(),s=await st.readFile(t.resolvedPaths.tailwindConfig,"utf8"),o=await Er(s,e,t);await st.writeFile(t.resolvedPaths.tailwindConfig,o,"utf8"),n?.succeed()}async function Er(e,t,r){let i=await B(e,r),n=i.getDescendantsOfKind(ie.ObjectLiteralExpression).find(s=>s.getProperties().some(o=>o.isKind(ie.PropertyAssignment)&&o.getName()==="content"));return n?(jr(n,t),i.getFullText()):e}async function jr(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(c=>c.getText()).includes(o)||n.addElement(o)}return e}return e}import{Command as Or}from"commander";import xe from"prompts";import{z as P}from"zod";var Nr=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()}),lt=new Or().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=Nr.parse({cwd:at.resolve(t.cwd),isNewProject:!1,components:e,...t});await ne(r),a.log(`${l.success("Success!")} Project initialization completed.
|
|
19
|
-
You may now add components.`),a.break()}catch(r){a.break(),b(r)}});async function ne(e){let t;if(e.skipPreflight)t=await
|
|
20
|
-
Before you can add components, you must create a valid ${l.info("components.json")} file by running the ${l.info("init")} command.`),a.error(`Learn more at ${l.info("https://ui.shadcn.com/docs/components-json")}.`),a.break(),process.exit(1)}}import
|
|
16
|
+
`}}))})}}}function sr(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 rr||(r=$.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}`;ar(r,s,n)})}}}function Xe(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 or(){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()),Xe(e);let r=e.nodes.find(i=>i.type==="atrule"&&i.params==="(prefers-color-scheme: dark)");r&&(Xe(r),r.nodes.length===0&&r.remove())}}}function ar(e,t,r){let i=e.nodes?.find(n=>n.type==="rule"&&n.selector===t);i||Object.keys(r).length>0&&(i=$.rule({selector:t,raws:{between:" ",before:`
|
|
18
|
+
`}}),e.append(i)),Object.entries(r).forEach(([n,s])=>{let o=`--${n.replace(/^--/,"")}`,c=$.decl({prop:o,value:s,raws:{semicolon:!0}}),p=i?.nodes.find(d=>d.type==="decl"&&d.prop===o);p?p.replaceWith(c):i?.append(c)})}import{detect as lr}from"@antfu/ni";async function Y(e,{withFallback:t}={withFallback:!1}){let r=await lr({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 cr}from"execa";async function Ze(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let i=y("Installing dependencies.",{silent:r.silent})?.start(),n=await Y(t.resolvedPaths.cwd);await cr(n,[n==="npm"?"install":"add",...e],{cwd:t.resolvedPaths.cwd}),i?.succeed()}import{existsSync as rt,promises as it}from"fs";import E,{basename as Rr}from"path";import{promises as xr}from"fs";import{tmpdir as br}from"os";import tt from"path";import{SyntaxKind as pr}from"ts-morph";var Q=async({sourceFile:e,config:t,baseColor:r})=>(t.tailwind?.cssVariables||!r?.inlineColors||e.getDescendantsOfKind(pr.StringLiteral).forEach(i=>{let n=i.getText();if(n){let s=fr(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 mr=["bg-","text-","border-","ring-offset-","ring-"];function fr(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,c,p]=ye(s),d=mr.find(x=>c?.startsWith(x));if(!d){i.has(s)||i.add(s);continue}let g=c?.replace(d,"");if(g&&g in t.light){i.add([o,`${d}${t.light[g]}`].filter(Boolean).join(":")+(p?`/${p}`:"")),n.add(["dark",o,`${d}${t.dark[g]}`].filter(Boolean).join(":")+(p?`/${p}`:""));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=dr(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 dr(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 ur}from"@babel/core";import{parse as gr}from"@babel/parser";import hr from"@babel/plugin-transform-typescript";import*as X from"recast";var yr={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"]},et=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let i=X.parse(r,{parser:{parse:s=>gr(s,yr)}}),n=ur(i,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[hr],configFile:!1});if(!n||!n.ast)throw new Error("Failed to transform JSX");return X.print(n.ast).code};import{SyntaxKind as wr}from"ts-morph";var q=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(wr.ExpressionStatement);return r?.getText()==='"use client"'&&r.remove(),e};import{Project as Sr,ScriptKind as Cr}from"ts-morph";import{SyntaxKind as w}from"ts-morph";var Z=async({sourceFile:e,config:t})=>(t.tailwind?.prefix&&(e.getDescendantsOfKind(w.CallExpression).filter(r=>r.getExpression().getText()==="cva").forEach(r=>{if(r.getArguments()[0]?.isKind(w.StringLiteral)){let i=r.getArguments()[0];i&&i.replaceWithText(`"${k(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}r.getArguments()[1]?.isKind(w.ObjectLiteralExpression)&&r.getArguments()[1]?.getDescendantsOfKind(w.PropertyAssignment).find(i=>i.getName()==="variants")?.getDescendantsOfKind(w.PropertyAssignment).forEach(i=>{i.getDescendantsOfKind(w.PropertyAssignment).forEach(n=>{let s=n.getInitializerIfKind(w.StringLiteral);s&&s?.replaceWithText(`"${k(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)})})}),e.getDescendantsOfKind(w.JsxAttribute).forEach(r=>{if(r.getName()==="className"){if(r.getInitializer()?.isKind(w.StringLiteral)){let i=r.getInitializer();i&&i.replaceWithText(`"${k(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}if(r.getInitializer()?.isKind(w.JsxExpression)){let i=r.getInitializer()?.getDescendantsOfKind(w.CallExpression).find(n=>n.getExpression().getText()==="cn");i&&i.getArguments().forEach(n=>{(n.isKind(w.ConditionalExpression)||n.isKind(w.BinaryExpression))&&n.getChildrenOfKind(w.StringLiteral).forEach(s=>{s.replaceWithText(`"${k(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}),n.isKind(w.StringLiteral)&&n.replaceWithText(`"${k(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)})}}r.getName()==="classNames"&&r.getInitializer()?.isKind(w.JsxExpression)&&r.getDescendantsOfKind(w.PropertyAssignment).forEach(i=>{if(i.getInitializer()?.isKind(w.CallExpression)){let n=i.getInitializerIfKind(w.CallExpression);n&&n.getArguments().forEach(s=>{s.isKind(w.ConditionalExpression)&&s.getChildrenOfKind(w.StringLiteral).forEach(o=>{o.replaceWithText(`"${k(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}),s.isKind(w.StringLiteral)&&s.replaceWithText(`"${k(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)})}if(i.getInitializer()?.isKind(w.StringLiteral)&&i.getName()!=="variant"){let n=i.getInitializer();n&&n.replaceWithText(`"${k(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`)}})})),e);function k(e,t=""){let r=e.split(" "),i=[];for(let n of r){let[s,o,c]=ye(n);s?c?i.push(`${s}:${t}${o}/${c}`):i.push(`${s}:${t}${o}`):c?i.push(`${t}${o}/${c}`):i.push(`${t}${o}`)}return i.join(" ")}var Pr=new Sr({compilerOptions:{}});async function vr(e){let t=await xr.mkdtemp(tt.join(br(),"shadcn-"));return tt.join(t,e)}async function ee(e,t=[H,q,Q,Z]){let r=await vr(e.filename),i=Pr.createSourceFile(r,e.raw,{scriptKind:Cr.TSX});for(let n of t)n({sourceFile:i,...e});return e.transformJsx?await et({sourceFile:i,...e}):i.getText()}import Tr from"prompts";function Ir(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 nt(e,t,r){if(!e?.length)return;r={overwrite:!1,force:!1,silent:!1,...r};let i=y("Updating files.",{silent:r.silent})?.start(),[n,s]=await Promise.all([j(t.resolvedPaths.cwd),K(t.tailwind.baseColor)]),o=[],c=[],p=[];for(let g of e){if(!g.content)continue;let x=Je(g,t),f=Rr(g.path),S=E.join(x,f);g.target&&(S=Ir(n,t,g.target),x=E.dirname(S)),t.tsx||(S=S.replace(/\.tsx?$/,se=>se===".tsx"?".jsx":".js"));let ve=rt(S);if(ve&&!r.overwrite){i.stop();let{overwrite:se}=await Tr({type:"confirm",name:"overwrite",message:`The file ${l.info(f)} already exists. Would you like to overwrite?`,initial:!1});if(!se){p.push(E.relative(t.resolvedPaths.cwd,S));continue}i?.start()}rt(x)||await it.mkdir(x,{recursive:!0});let wt=await ee({filename:g.path,raw:g.content,config:t,baseColor:s,transformJsx:!t.tsx},[H,q,Q,Z]);await it.writeFile(S,wt,"utf-8"),ve?c.push(E.relative(t.resolvedPaths.cwd,S)):o.push(E.relative(t.resolvedPaths.cwd,S))}if(!(o.length||c.length)&&!p.length&&i?.info("No files updated."),o.length){if(i?.succeed(`Created ${o.length} ${o.length===1?"file":"files"}:`),!r.silent)for(let g of o)a.log(` - ${g}`)}else i?.stop();if(c.length&&(y(`Updated ${c.length} ${c.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let g of c)a.log(` - ${g}`);if(p.length&&(y(`Skipped ${p.length} ${c.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let g of p)a.log(` - ${g}`);r.silent||a.break()}async function te(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,...r};let i=y("Checking registry.",{silent:r.silent})?.start(),n=await Ye(e,t);if(!n)return i?.fail(),b(new Error("Failed to fetch components from registry."));i?.succeed(),await ze(n.tailwind?.config,t,{silent:r.silent}),await qe(n.cssVars,t,{cleanupDefaultNextStyles:r.isNewProject,silent:r.silent}),await Ze(n.dependencies,t,{silent:r.silent}),await nt(n.files,t,{overwrite:r.overwrite,silent:r.silent}),n.docs&&a.info(n.docs)}import kr from"path";import{execa as Er}from"execa";import we from"fs-extra";import st from"prompts";async function re(e){if(e={srcDir:!1,...e},!e.force){let{proceed:o}=await st({type:"confirm",name:"proceed",message:`The path ${l.info(e.cwd)} does not contain a package.json file. Would you like to start a new ${l.info("Next.js")} project?`,initial:!0});if(!o)return{projectPath:null,projectName:null}}let t=await Y(e.cwd),{name:r}=await st({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 ${l.info(e.cwd)} is not writable.`),a.error(`It is likely you do not have write permissions for this folder or the path ${l.info(e.cwd)} does not exist.`),a.break(),process.exit(1)}we.existsSync(kr.resolve(e.cwd,r,"package.json"))&&(a.break(),a.error(`A project with the name ${l.info(r)} already exists.`),a.error("Please choose a different name and try again."),a.break(),process.exit(1));let n=y("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 Er("npx",["create-next-app@latest",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 ot}from"fs";import jr from"path";import{SyntaxKind as ie}from"ts-morph";async function at(e,t,r){if(!e)return;r={silent:!1,...r};let i=jr.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=y(`Updating ${l.info(i)}`,{silent:r.silent}).start(),s=await ot.readFile(t.resolvedPaths.tailwindConfig,"utf8"),o=await $r(s,e,t);await ot.writeFile(t.resolvedPaths.tailwindConfig,o,"utf8"),n?.succeed()}async function $r(e,t,r){let i=await B(e,r),n=i.getDescendantsOfKind(ie.ObjectLiteralExpression).find(s=>s.getProperties().some(o=>o.isKind(ie.PropertyAssignment)&&o.getName()==="content"));return n?(Or(n,t),i.getFullText()):e}async function Or(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(c=>c.getText()).includes(o)||n.addElement(o)}return e}return e}import{Command as Ar}from"commander";import xe from"prompts";import{z as P}from"zod";var Fr=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()}),ct=new Ar().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=Fr.parse({cwd:lt.resolve(t.cwd),isNewProject:!1,components:e,...t});await ne(r),a.log(`${l.success("Success!")} Project initialization completed.
|
|
19
|
+
You may now add components.`),a.break()}catch(r){a.break(),b(r)}});async function ne(e){let t;if(e.skipPreflight)t=await j(e.cwd);else{let p=await Oe(e);if(p.errors[T]){let{projectPath:d}=await re(e);d||process.exit(1),e.cwd=d,e.isNewProject=!0}t=p.projectInfo}let r=await je(e.cwd,t),i=r?await Lr(r,e):await Dr(await I(e.cwd));if(!e.yes){let{proceed:p}=await xe({type:"confirm",name:"proceed",message:`Write configuration to ${l.info("components.json")}. Proceed?`,initial:!0});p||process.exit(0)}let n=y("Writing components.json.").start(),s=lt.resolve(e.cwd,"components.json");await Nr.writeFile(s,JSON.stringify(i,null,2),"utf8"),n.succeed();let o=await F(e.cwd,i),c=["index",...e.components||[]];return await te(c,o,{overwrite:!0,silent:e.silent,isNewProject:e.isNewProject||t?.framework.name==="next-app"}),e.isNewProject&&e.srcDir&&await at(["./src/**/*.{js,ts,jsx,tsx,mdx}"],o,{silent:e.silent}),o}async function Dr(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 ${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??ke},{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??Ee},{type:"text",name:"components",message:`Configure the import alias for ${l.info("components")}:`,initial:e?.aliases.components??Te},{type:"text",name:"utils",message:`Configure the import alias for ${l.info("utils")}:`,initial:e?.aliases.utils??Ie},{type:"toggle",name:"rsc",message:`Are you using ${l.info("React Server Components")}?`,initial:e?.rsc??!0,active:"yes",inactive:"no"}]);return A.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 Lr(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()]),c=await xe([{type:"select",name:"style",message:`Which ${l.info("style")} would you like to use?`,choices:s.map(p=>({title:p.label,value:p.name})),initial:s.findIndex(p=>p.name===r)},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${l.info("base color")}?`,choices:o.map(p=>({title:p.label,value:p.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 A.parse({$schema:e?.$schema,style:r,tailwind:{...e?.tailwind,baseColor:i,cssVariables:n},rsc:e?.rsc,tsx:e?.tsx,aliases:e?.aliases})}import pt from"path";import be from"fs-extra";async function mt(e){let t={};if(!be.existsSync(e.cwd)||!be.existsSync(pt.resolve(e.cwd,"package.json")))return t[T]=!0,{errors:t,config:null};if(!be.existsSync(pt.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 ${l.info("components.json")} file was found at ${l.info(e.cwd)}.
|
|
20
|
+
Before you can add components, you must create a valid ${l.info("components.json")} file by running the ${l.info("init")} command.`),a.error(`Learn more at ${l.info("https://ui.shadcn.com/docs/components-json")}.`),a.break(),process.exit(1)}}import ft from"fs/promises";import _r from"path";async function dt(e,t){let r=_r.join(t.resolvedPaths.cwd,"app/page.tsx");if(!(await ft.stat(r)).isFile())return;let i=await J(e,t.style);if(!i?.meta?.importSpecifier||!i?.meta?.moduleSpecifier)return;let n=`import { ${i?.meta?.importSpecifier} } from "${i.meta.moduleSpecifier}"
|
|
21
21
|
|
|
22
22
|
export default function Page() {
|
|
23
23
|
return <${i?.meta?.importSpecifier} />
|
|
24
|
-
}`;await
|
|
25
|
-
Existing CSS variables will be overwritten. Continue?`)});c||(a.break(),a.log("Theme installation cancelled."),a.break(),process.exit(1))}r.components?.length||(r.components=await
|
|
24
|
+
}`;await ft.writeFile(r,n,"utf8")}import{Command as Kr}from"commander";import Se from"prompts";import{z as C}from"zod";var Wr=C.object({components:C.array(C.string()).optional(),yes:C.boolean(),overwrite:C.boolean(),cwd:C.string(),all:C.boolean(),path:C.string().optional(),silent:C.boolean(),srcDir:C.boolean().optional()}),ut=new Kr().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=Wr.parse({components:e,cwd:zr.resolve(t.cwd),...t}),i=r.components?.some(c=>c.includes("theme-"));if(!r.yes&&i){a.break();let{confirm:c}=await Se({type:"confirm",name:"confirm",message:l.warn(`You are about to install a new theme.
|
|
25
|
+
Existing CSS variables will be overwritten. Continue?`)});c||(a.break(),a.log("Theme installation cancelled."),a.break(),process.exit(1))}r.components?.length||(r.components=await Vr(r));let{errors:n,config:s}=await mt(r);if(n[V]){let{proceed:c}=await Se({type:"confirm",name:"proceed",message:`You need to create a ${l.info("component.json")} file to add components. Proceed?`,initial:!0});c||(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[T]){let{projectPath:c}=await re({cwd:r.cwd,force:r.overwrite,srcDir:r.srcDir});c||(a.break(),process.exit(1)),r.cwd=c,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 ${l.info(r.cwd)}.`);await te(r.components,s,r),o&&await dt(r.components[0],s)}catch(r){a.break(),b(r)}});async function Vr(e){let t=await z();if(!t)return a.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 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=C.array(C.string()).safeParse(r);return i.success?i.data:(a.error(""),b(new Error("Something went wrong. Please try again.")),[])}import{existsSync as Ce,promises as Ur}from"fs";import Pe from"path";import{Command as Mr}from"commander";import{diffLines as Gr}from"diff";import{z as W}from"zod";var Br=W.object({component:W.string().optional(),yes:W.boolean(),cwd:W.string(),path:W.string().optional()}),ht=new Mr().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=Br.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 ${l.success("init")} to create a components.json file.`),process.exit(1));let s=await z();if(s||(b(new Error("Failed to fetch registry index.")),process.exit(1)),!r.component){let p=n.resolvedPaths.components,d=s.filter(x=>{for(let f of x.files??[]){let S=Pe.resolve(p,typeof f=="string"?f:f.path);if(Ce(S))return!0}return!1}),g=[];for(let x of d){let f=await gt(x,n);f.length&&g.push({name:x.name,changes:f})}g.length||(a.info("No updates found."),process.exit(0)),a.info("The following components have updates available:");for(let x of g){a.info(`- ${x.name}`);for(let f of x.changes)a.info(` - ${f.filePath}`)}a.break(),a.info(`Run ${l.success("diff <component>")} to see the changes.`),process.exit(0)}let o=s.find(p=>p.name===r.component);o||(a.error(`The component ${l.success(r.component)} does not exist.`),process.exit(1));let c=await gt(o,n);c.length||(a.info(`No updates found for ${r.component}.`),process.exit(0));for(let p of c)a.info(`- ${p.filePath}`),await Jr(p.patch),a.info("")}catch(r){b(r)}});async function gt(e,t){let r=await Ge(t.style,[e]),i=await K(t.tailwind.baseColor);if(!r)return[];let n=[];for(let s of r){let o=await Be(t,s);if(o)for(let c of s.files??[]){let p=Pe.resolve(o,typeof c=="string"?c:c.path);if(!Ce(p))continue;let d=await Ur.readFile(p,"utf8");if(typeof c=="string"||!c.content)continue;let g=await ee({filename:c.path,raw:c.content,config:t,baseColor:i}),x=Gr(g,d);x.length>1&&n.push({filePath:p,patch:x})}}return n}async function Jr(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 Qr}from"commander";var yt={name:"shadcn",version:"2.0.8",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 Hr(){let e=new Qr().name("shadcn").description("add components and dependencies to your project").version(yt.version||"1.0.0","-v, --version","display the version number");e.addCommand(ct).addCommand(ut).addCommand(ht),e.parse()}Hr();
|
|
26
26
|
//# sourceMappingURL=index.js.map
|