hghcn 3.6.10 → 3.6.11
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.d.ts +323 -323
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/registry/index.d.ts +2 -2
- package/dist/schema/index.d.ts +681 -681
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -44,13 +44,13 @@ Some packages may fail to install due to peer dependency issues in npm (see http
|
|
|
44
44
|
`);}a.push(l);}return a.length>0&&$i(n,a),n.getFullText()}function ki(e){let t={};return e.font.subsets?.length&&(t.subsets=e.font.subsets),e.font.weight?.length&&(t.weight=e.font.weight),t.variable=e.font.variable,JSON.stringify(t).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'")}function Pi(e){return e.split("_").map((t,r)=>r===0?t.toLowerCase():t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function ji(e,t){let r=e.getVariableStatements();for(let i of r)for(let n of i.getDeclarations()){let o=n.getInitializer();if(!o||o.getKind()!==SyntaxKind.CallExpression)continue;let s=o.getArguments();if(s.length===0)continue;let c=s[0].getText();if(c.includes("variable:")&&c.includes(t))return n}return null}function Ei(e){let t=e.getImportDeclarations();return t.length>0?t[t.length-1].getChildIndex()+1:0}function $i(e,t){let r=e.getDescendantsOfKind(SyntaxKind.JsxOpeningElement);for(let i of r){if(i.getTagNameNode().getText()!=="html")continue;let o=i.getAttribute("className");if(!o){let l=t.map(m=>`${m}.variable`).join(", ");t.length===1?i.addAttribute({name:"className",initializer:`{${l}}`}):(ge(e),i.addAttribute({name:"className",initializer:`{cn(${l})}`}));return}if(o.getKind()!==SyntaxKind.JsxAttribute)return;let a=o.asKindOrThrow(SyntaxKind.JsxAttribute),s=a.getInitializer();if(!s)return;let c=t.map(l=>`${l}.variable`);if(s.getKind()===SyntaxKind.StringLiteral){let l=s.getText().slice(1,-1);ge(e),a.setInitializer(`{cn("${l}", ${c.join(", ")})}`);}else if(s.getKind()===SyntaxKind.JsxExpression){let l=s.asKindOrThrow(SyntaxKind.JsxExpression),m=l.getExpression();if(!m)return;let p=m.getText();if(p.startsWith("cn(")){if(c.every(h=>p.includes(h)))continue;let g=Oi(p),w=Ti(g,c);l.replaceWithText(`{${w}}`);}else if(/^\w+\.variable$/.test(p)){if(c.includes(p))continue;c.length===1?l.replaceWithText(`{${c[0]}}`):(ge(e),l.replaceWithText(`{cn(${c.join(", ")})}`));}else if(p.startsWith("`")&&p.endsWith("`")){let u=Ni(p);ge(e),l.replaceWithText(`{cn(${[...u,...c].join(", ")})}`);}else ge(e),l.replaceWithText(`{cn(${p}, ${c.join(", ")})}`);}}}function ge(e){if(!e.getImportDeclaration(r=>r.getNamedImports().some(n=>n.getName()==="cn"))){let r=e.getImportDeclaration(i=>i.getModuleSpecifierValue().includes("/lib/utils"));r?r.getNamedImports().some(n=>n.getName()==="cn")||r.addNamedImport("cn"):e.addImportDeclaration({moduleSpecifier:"@/lib/utils",namedImports:["cn"]});}}function Ni(e){let t=[],r=[],n=e.slice(1,-1).split(/(\$\{[^}]+\})/);for(let o of n)if(o)if(o.startsWith("${")&&o.endsWith("}")){let a=o.slice(2,-1).trim();a&&r.push(a);}else {let a=o.trim().split(/\s+/).filter(Boolean);for(let s of a)t.push(`"${s}"`);}return [...t,...r]}function Oi(e){return e.replace(/,?\s*\w+\.variable/g,"").replace(/cn\(\s*,/,"cn(")}function Ti(e,t){let r=t.join(", ");return e.replace(/\)$/,`, ${r})`)}async function ie(e,t,r){r={overwrite:false,silent:false,isNewProject:false,baseStyle:true,...r};let i=await k(t);return i&&i.ui&&i.ui.resolvedPaths.cwd!==t.resolvedPaths.cwd?await Di(e,t,i,{...r,isRemote:e?.length===1&&!!e[0].match(/\/chat\/b\//)}):await Ai(e,t,r)}async function Ai(e,t$1,r$1){if(!r$1.baseStyle&&!e.length)return;let i=t("Checking registry.",{silent:r$1.silent})?.start(),n=await V(e,O(t$1));if(!n)return i?.fail(),W(new Error("Failed to fetch components from registry."));try{Qt(n.files??[],t$1.resolvedPaths.cwd);}catch(s){return i?.fail(),W(s)}i?.succeed();let o=await r(t$1);n=await Xt(n,t$1),await T$1(n.tailwind?.config,t$1,{silent:r$1.silent,tailwindVersion:o});let a=await Zt(e,t$1);await Ye(n.cssVars,t$1,{cleanupDefaultNextStyles:r$1.isNewProject,silent:r$1.silent,tailwindVersion:o,tailwindConfig:n.tailwind?.config,overwriteCssVars:a,initIndex:r$1.baseStyle}),await Je(n.css,t$1,{silent:r$1.silent}),await qe(n.envVars,t$1,{silent:r$1.silent}),await z(n.dependencies,n.devDependencies,t$1,{silent:r$1.silent}),await He(n.fonts,t$1,{silent:r$1.silent}),await K(n.files,t$1,{overwrite:r$1.overwrite,silent:r$1.silent,path:r$1.path}),n.docs&&s.info(n.docs);}async function Di(e,t$1,r$1,i){if(!i.baseStyle&&!e.length)return;let n=t("Checking registry.",{silent:i.silent})?.start(),o=await V(e,O(t$1));if(!o)return n?.fail(),W(new Error("Failed to fetch components from registry."));try{Qt(o.files??[],t$1.resolvedPaths.cwd);}catch(h){return n?.fail(),W(h)}n?.succeed();let a=[],s$1=[],c=[],l$1=t("Installing components.")?.start(),m$1=r$1.ui,p=await r(m$1),u=m(t$1.resolvedPaths.cwd,m$1.resolvedPaths.ui);if(o.tailwind?.config&&(await T$1(o.tailwind?.config,m$1,{silent:true,tailwindVersion:p}),s$1.push(j__default.relative(u,m$1.resolvedPaths.tailwindConfig))),o.cssVars){let h=await Zt(e,t$1);await Ye(o.cssVars,m$1,{silent:true,tailwindVersion:p,tailwindConfig:o.tailwind?.config,overwriteCssVars:h}),s$1.push(j__default.relative(u,m$1.resolvedPaths.tailwindCss));}o.css&&(await Je(o.css,m$1,{silent:true}),s$1.push(j__default.relative(u,m$1.resolvedPaths.tailwindCss))),o.envVars&&await qe(o.envVars,m$1,{silent:true}),await z(o.dependencies,o.devDependencies,m$1,{silent:true}),await He(o.fonts,m$1,{silent:true});let g=new Map;for(let h of o.files??[]){let x=h.type||"registry:ui";g.has(x)||g.set(x,[]),g.get(x).push(h);}for(let h of Array.from(g.keys())){let x=g.get(h),v=h==="registry:ui"?r$1.ui:t$1,M=m(t$1.resolvedPaths.cwd,v.resolvedPaths.ui||v.resolvedPaths.cwd),F=await l(M,v.resolvedPaths.cwd)??v.resolvedPaths.cwd,X=await K(x,v,{overwrite:i.overwrite,silent:true,rootSpinner:l$1,isRemote:i.isRemote,isWorkspace:true,path:i.path});a.push(...X.filesCreated.map(A=>j__default.relative(M,j__default.join(F,A)))),s$1.push(...X.filesUpdated.map(A=>j__default.relative(M,j__default.join(F,A)))),c.push(...X.filesSkipped.map(A=>j__default.relative(M,j__default.join(F,A))));}if(l$1?.succeed(),a.sort(),s$1.sort(),c.sort(),!(a.length||s$1.length)&&!c.length&&t("No files updated.",{silent:i.silent})?.info(),a.length){t(`Created ${a.length} ${a.length===1?"file":"files"}:`,{silent:i.silent})?.succeed();for(let h of a)s.log(` - ${h}`);}if(s$1.length){t(`Updated ${s$1.length} ${s$1.length===1?"file":"files"}:`,{silent:i.silent})?.info();for(let h of s$1)s.log(` - ${h}`);}if(c.length){t(`Skipped ${c.length} ${s$1.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:i.silent})?.info();for(let h of c)s.log(` - ${h}`);}o.docs&&s.info(o.docs);}async function Zt(e,t){let r=await Y$1(e,{config:t});return z$1.array(n$1).parse(r).some(n=>n.type==="registry:theme"||n.type==="registry:style"||n.type==="registry:font"||n.type==="registry:base")}function Qt(e,t){for(let r of e)if(r?.target&&!Bt(r.target,t))throw new Error(`We found an unsafe file path "${r.target} in the registry item. Installation aborted.`)}var Qe="https://codeload.github.com/shadcn-ui/ui/tar.gz/main",L={next:"next","next-monorepo":"next-monorepo",vite:"vite",start:"start"};async function Ee(e){e={srcDir:false,...e};let t=e.template&&L[e.template]?e.template:"next",r=e.name??(t===L.next||t===L.vite||t===L.start?"my-app":"my-monorepo"),i="latest",n=e.components?.length===1&&!!e.components[0].match(/\/chat\/b\//);if(e.components&&n)try{let[s]=await S(e.components),{meta:c}=z$1.object({meta:z$1.object({nextVersion:z$1.string()})}).parse(s);i=c.nextVersion,t=L.next;}catch(s$1){s.break(),W(s$1);}if(!e.force){let{type:s,name:c}=await Oe([{type:e.template||n?null:"select",name:"type",message:`The path ${d.info(e.cwd)} does not contain a package.json file.
|
|
45
45
|
Would you like to start a new project?`,choices:[{title:"Next.js",value:"next"},{title:"Next.js (Monorepo)",value:"next-monorepo"},{title:"Vite",value:"vite"},{title:"TanStack Start",value:"start"}],initial:0},{type:e.name?null:"text",name:"name",message:"What is your project named?",initial:r,format:l=>l.trim(),validate:l=>l.length>128?"Name should be less than 128 characters.":true}]);t=s??t,r=c??r;}let o=await a$1(e.cwd,{withFallback:true}),a=`${e.cwd}/${r}`;try{await R.access(e.cwd,R.constants.W_OK);}catch{s.break(),s.error(`The path ${d.info(e.cwd)} is not writable.`),s.error(`It is likely you do not have write permissions for this folder or the path ${d.info(e.cwd)} does not exist.`),s.break(),process.exit(1);}return R.existsSync(j__default.resolve(e.cwd,r,"package.json"))&&(s.break(),s.error(`A project with the name ${d.info(r)} already exists.`),s.error("Please choose a different name and try again."),s.break(),process.exit(1)),t===L.next&&await Li(a,{version:i,cwd:e.cwd,packageManager:o,srcDir:!!e.srcDir}),t===L["next-monorepo"]&&await Vi(a,{packageManager:o}),t===L.vite&&await Mi(a,{packageManager:o}),t===L.start&&await Wi(a,{packageManager:o}),{projectPath:a,projectName:r,template:t}}async function Li(e,t$1){let r=t("Creating a new Next.js project. This may take a few minutes.").start(),i=["--tailwind","--eslint","--typescript","--app",t$1.srcDir?"--src-dir":"--no-src-dir","--no-import-alias",`--use-${t$1.packageManager}`];(t$1.version.startsWith("15")||t$1.version.startsWith("latest")||t$1.version.startsWith("canary"))&&i.push("--turbopack"),(t$1.version.startsWith("latest")||t$1.version.startsWith("canary"))&&i.push("--no-react-compiler");try{await execa("npx",[`create-next-app@${t$1.version}`,e,"--silent",...i],{cwd:t$1.cwd});}catch{s.break(),s.error("Something went wrong creating a new Next.js project. Please try again."),process.exit(1);}r?.succeed("Creating a new Next.js project.");}async function Vi(e,t$1){let r=t("Creating a new Next.js monorepo. This may take a few minutes.").start();try{let i=j__default.join(Ze.tmpdir(),`shadcn-template-${Date.now()}`);await R.ensureDir(i);let n=await fetch(Qe);if(!n.ok)throw new Error(`Failed to download template: ${n.statusText}`);let o=j__default.resolve(i,"template.tar.gz");await R.writeFile(o,Buffer.from(await n.arrayBuffer())),await execa("tar",["-xzf",o,"-C",i,"--strip-components=2","ui-main/templates/monorepo-next"]);let a=j__default.resolve(i,"monorepo-next");await R.move(a,e),await R.remove(i),await execa(t$1.packageManager,["install"],{cwd:e});let s=j__default.join(e,"package.json");if(R.existsSync(s)){let l=await R.readFile(s,"utf8"),m=JSON.parse(l);m.name=e.split("/").pop(),await R.writeFile(s,JSON.stringify(m,null,2));}let c=process.cwd();await execa("git",["--version"],{cwd:e}),await execa("git",["init"],{cwd:e}),await execa("git",["add","-A"],{cwd:e}),await execa("git",["commit","-m","Initial commit"],{cwd:e}),r?.succeed("Creating a new Next.js monorepo.");}catch(i){r?.fail("Something went wrong creating a new Next.js monorepo."),W(i);}}async function Mi(e,t$1){let r=t("Creating a new Vite project. This may take a few minutes.").start();try{let i=j__default.join(Ze.tmpdir(),`shadcn-template-${Date.now()}`);await R.ensureDir(i);let n=await fetch(Qe);if(!n.ok)throw new Error(`Failed to download template: ${n.statusText}`);let o=j__default.resolve(i,"template.tar.gz");await R.writeFile(o,Buffer.from(await n.arrayBuffer())),await execa("tar",["-xzf",o,"-C",i,"--strip-components=2","ui-main/templates/vite-app"]);let a=j__default.resolve(i,"vite-app");if(await R.move(a,e),await R.remove(i),t$1.packageManager!=="pnpm"){let c=j__default.join(e,"pnpm-lock.yaml");R.existsSync(c)&&await R.remove(c);}await execa(t$1.packageManager,["install"],{cwd:e});let s=j__default.join(e,"package.json");if(R.existsSync(s)){let c=await R.readFile(s,"utf8"),l=JSON.parse(c);l.name=e.split("/").pop(),await R.writeFile(s,JSON.stringify(l,null,2));}await execa("git",["--version"],{cwd:e}),await execa("git",["init"],{cwd:e}),await execa("git",["add","-A"],{cwd:e}),await execa("git",["commit","-m","Initial commit"],{cwd:e}),r?.succeed("Creating a new Vite project.");}catch(i){r?.fail("Something went wrong creating a new Vite project."),W(i);}}async function Wi(e,t$1){let r=t("Creating a new TanStack Start project. This may take a few minutes.").start();try{let i=j__default.join(Ze.tmpdir(),`shadcn-template-${Date.now()}`);await R.ensureDir(i);let n=await fetch(Qe);if(!n.ok)throw new Error(`Failed to download template: ${n.statusText}`);let o=j__default.resolve(i,"template.tar.gz");await R.writeFile(o,Buffer.from(await n.arrayBuffer())),await execa("tar",["-xzf",o,"-C",i,"--strip-components=2","ui-main/templates/start-app"]);let a=j__default.resolve(i,"start-app");if(await R.move(a,e),await R.remove(i),t$1.packageManager!=="pnpm"){let c=j__default.join(e,"pnpm-lock.yaml");R.existsSync(c)&&await R.remove(c);}await execa(t$1.packageManager,["install"],{cwd:e});let s=j__default.join(e,"package.json");if(R.existsSync(s)){let c=await R.readFile(s,"utf8"),l=JSON.parse(c);l.name=e.split("/").pop(),await R.writeFile(s,JSON.stringify(l,null,2));}await execa("git",["--version"],{cwd:e}),await execa("git",["init"],{cwd:e}),await execa("git",["add","-A"],{cwd:e}),await execa("git",["commit","-m","Initial commit"],{cwd:e}),r?.succeed("Creating a new TanStack Start project.");}catch(i){r?.fail("Something went wrong creating a new TanStack Start project."),W(i);}}async function B(e=process.cwd()){try{let{config:t}=await import('@dotenvx/dotenvx'),r=[".env.local",".env.development.local",".env.development",".env"];for(let i of r){let n=join(e,i);existsSync(n)&&t({path:n,overload:!1,quiet:!0});}}catch(t){s.warn("Failed to load env files:",t);}}var he=".bak";function er(e){if(!R.existsSync(e))return null;let t=`${e}${he}`;try{return R.renameSync(e,t),t}catch(r){return console.error(`Failed to create backup of ${e}: ${r}`),null}}function tr(e){let t=`${e}${he}`;if(!R.existsSync(t))return false;try{return R.renameSync(t,e),!0}catch(r){return console.error(`Warning: Could not restore backup file ${t}: ${r}`),false}}function et(e){let t=`${e}${he}`;if(!R.existsSync(t))return false;try{return R.unlinkSync(t),!0}catch{return false}}async function rr(e,t){let r=new Set,i=new Set,n=[...e];for(;n.length>0;){let o=n.shift();if(i.has(o))continue;i.add(o);let{registry:a}=F(o);a&&!b[a]&&r.add(a);try{let[s]=await U([o],t,{useCache:!0});if(s?.registryDependencies)for(let c of s.registryDependencies){let{registry:l}=F(c);l&&!b[l]&&r.add(l),i.has(c)||n.push(c);}}catch(s){if(s instanceof z$2){let{registry:c}=F(o);c&&!b[c]&&r.add(c);continue}continue}}return Array.from(r)}async function T(e,t$1,r={}){r={silent:false,writeFile:true,...r};let n=(await rr(e,t$1)).filter(l=>!t$1.registries?.[l]&&!Object.keys(b).includes(l));if(n.length===0)return {config:t$1,newRegistries:[]};let o=await ha({useCache:process.env.NODE_ENV!=="development"});if(!o)return {config:t$1,newRegistries:[]};let a={};for(let l of n)o[l]&&(a[l]=o[l]);if(Object.keys(a).length===0)return {config:t$1,newRegistries:[]};let s=Object.fromEntries(Object.entries(t$1.registries||{}).filter(([l])=>!Object.keys(b).includes(l))),c$1={...t$1,registries:{...s,...a}};if(r.writeFile){let{resolvedPaths:l,...m}=c$1,p=t("Updating components.json.",{silent:r.silent}).start(),u=c.parse(m);await R.writeFile(j__default.resolve(t$1.resolvedPaths.cwd,"components.json"),JSON.stringify(u,null,2)+`
|
|
46
46
|
`,"utf-8"),p.succeed();}return {config:c$1,newRegistries:Object.keys(a)}}process.on("exit",e=>{let t=j__default.resolve(process.cwd(),"components.json");return e===0?et(t):tr(t)});var rt=z$1.object({cwd:z$1.string(),name:z$1.string().optional(),components:z$1.array(z$1.string()).optional(),yes:z$1.boolean(),defaults:z$1.boolean(),force:z$1.boolean(),silent:z$1.boolean(),isNewProject:z$1.boolean(),srcDir:z$1.boolean().optional(),cssVariables:z$1.boolean(),template:z$1.string().optional().refine(e=>e?L[e]:true,{message:"Invalid template. Please use 'next', 'vite', 'start' or 'next-monorepo'."}),baseColor:z$1.string().optional().refine(e=>e?a.find(t=>t.name===e):true,{message:`Invalid base color. Please use '${a.map(e=>e.name).join("', '")}'`}),baseStyle:z$1.boolean(),registryBaseConfig:c.deepPartial().optional()}),nr=new Command().name("init").description("initialize your project and install dependencies").argument("[components...]","names, url or local path to component").option("-t, --template <template>","the template to use. (next, start, vite, next-monorepo)").option("-b, --base-color <base-color>","the base color to use. (neutral, gray, zinc, stone, slate)",void 0).option("-y, --yes","skip confirmation prompt.",true).option("-d, --defaults,","use default configuration.",false).option("-f, --force","force overwrite of existing configuration.",false).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",false).option("--src-dir","use the src directory when creating a new project.",false).option("--no-src-dir","do not use the src directory when creating a new project.").option("--css-variables","use css variables for theming.",true).option("--no-css-variables","do not use css variables for theming.").option("--no-base-style","do not install the base shadcn style.").action(async(e,t)=>{try{t.defaults&&(t.template=t.template||"next",t.baseColor=t.baseColor||"neutral");let r=rt.parse({cwd:j__default.resolve(t.cwd),isNewProject:!1,components:e,...t});if(await B(r.cwd),e.length>0){let i=O(n({resolvedPaths:{cwd:r.cwd}})),n$1=j__default.resolve(r.cwd,"components.json");if(R.existsSync(n$1)){let s=await R.readJson(n$1),c$1=c.partial().parse(s),l=n({resolvedPaths:{cwd:r.cwd}});i=O({...c$1,resolvedPaths:{...l.resolvedPaths,cwd:r.cwd}}),er(n$1);}let{config:o}=await T(e,i,{silent:!0,writeFile:!1});i=o,R$1(e[0],i);let[a]=await Y$1([e[0]],{config:i});a?.type==="registry:base"&&(a.config&&(i=O(ir(i,a.config)),r.registryBaseConfig=a.config),r.baseStyle=a.extends==="none"?!1:r.baseStyle),a?.type==="registry:style"&&(r.baseColor="neutral",r.baseStyle=a.extends==="none"?!1:r.baseStyle);}r.baseStyle||(r.baseColor="neutral"),await le(r),s.log(`${d.success("Success!")} Project initialization completed.
|
|
47
|
-
You may now add components.`),et(j__default.resolve(r.cwd,"components.json")),s.break();}catch(r){s.break(),W(r);}finally{P();}});async function le(e){let t$1,r;if(e.skipPreflight)t$1=await p(e.cwd);else {let g=await zt(e);if(g.errors["1"]){let{projectPath:w,template:h}=await Ee(e);w||process.exit(1),e.cwd=w,e.isNewProject=true,r=h,t$1=await p(e.cwd);}else t$1=g.projectInfo;}if(r==="next-monorepo")return e.cwd=j__default.resolve(e.cwd,"apps/web"),await i(e.cwd);let i$1=await q(e.cwd,t$1),n=i$1?await Ki(i$1,e):await Yi(await i(e.cwd));if(!e.yes){let{proceed:g}=await Oe({type:"confirm",name:"proceed",message:`Write configuration to ${d.info("components.json")}. Proceed?`,initial:true});g||process.exit(0);}let o=[...e.baseStyle?["index"]:[],...e.components??[]],a=await j$1(e.cwd,n),{config:s}=await T(o,a,{silent:true});s.registries&&(n.registries=s.registries);let c=t("Writing components.json.").start(),m=`${j__default.resolve(e.cwd,"components.json")}${he}`,p$1=(g,w)=>{let{registries:h,...x}=ir(g,w);return {...x,registries:h}};if(!e.force&&R.existsSync(m)){let g=await R.readJson(m);n=p$1(g,n);}e.registryBaseConfig&&(n=p$1(n,e.registryBaseConfig)),n.registries=Object.fromEntries(Object.entries(n.registries||{}).filter(([g])=>!Object.keys(b).includes(g))),c.succeed();let u=await j$1(e.cwd,n);return await ie(o,u,{overwrite:true,silent:e.silent,baseStyle:e.baseStyle,isNewProject:e.isNewProject||t$1?.framework.name==="next-app"}),u}async function Yi(e$1=null){let[t,r]=await Promise.all([aa(),ca()]);s.info("");let i=await Oe([{type:"toggle",name:"typescript",message:`Would you like to use ${d.info("TypeScript")} (recommended)?`,initial:e$1?.tsx??true,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${d.info("style")} would you like to use?`,choices:t.map(n=>({title:n.label,value:n.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${d.info("global CSS")} file?`,initial:e$1?.tailwind.css??g},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${d.info("CSS variables")} for theming?`,initial:e$1?.tailwind.cssVariables??true,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${d.info("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${d.info("tailwind.config.js")} located?`,initial:e$1?.tailwind.config??h},{type:"text",name:"components",message:`Configure the import alias for ${d.info("components")}:`,initial:e$1?.aliases.components??e},{type:"text",name:"utils",message:`Configure the import alias for ${d.info("utils")}:`,initial:e$1?.aliases.utils??f},{type:"toggle",name:"rsc",message:`Are you using ${d.info("React Server Components")}?`,initial:e$1?.rsc??true,active:"yes",inactive:"no"}]);return c.parse({$schema:"https://ui.shadcn.com/schema.json",style: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 Ki(e,t){let r$1=e.style,i=t.baseColor,n=e.tailwind.cssVariables,o=e.iconLibrary??"lucide";if(!t.defaults){let[a,s,c]=await Promise.all([aa(),ca(),r(e)]),l=await Oe([]);r$1=l.style??r$1??"new-york",i=l.tailwindBaseColor??i,n=t.cssVariables;}return c.parse({$schema:e?.$schema,style:r$1,tailwind:{...e?.tailwind,baseColor:i,cssVariables:n},rsc:e?.rsc,tsx:e?.tsx,iconLibrary:o,aliases:e?.aliases})}async function sr(e){let t={};if(!R.existsSync(e.cwd)||!R.existsSync(j__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,config:null};if(!R.existsSync(j__default.resolve(e.cwd,"components.json")))return t["3"]=true,{errors:t,config:null};try{let r=await i(e.cwd);return {errors:t,config:r}}catch{s.break(),s.error(`An invalid ${d.info("components.json")} file was found at ${d.info(e.cwd)}.
|
|
47
|
+
You may now add components.`),et(j__default.resolve(r.cwd,"components.json")),s.break();}catch(r){console.log("init error"),s.break(),W(r);}finally{P();}});async function le(e){let t$1,r;if(e.skipPreflight)t$1=await p(e.cwd);else {let g=await zt(e);if(g.errors["1"]){let{projectPath:w,template:h}=await Ee(e);w||process.exit(1),e.cwd=w,e.isNewProject=true,r=h,t$1=await p(e.cwd);}else t$1=g.projectInfo;}if(r==="next-monorepo")return e.cwd=j__default.resolve(e.cwd,"apps/web"),await i(e.cwd);let i$1=await q(e.cwd,t$1),n=i$1?await Ki(i$1,e):await Yi(await i(e.cwd));if(!e.yes){let{proceed:g}=await Oe({type:"confirm",name:"proceed",message:`Write configuration to ${d.info("components.json")}. Proceed?`,initial:true});g||process.exit(0);}let o=[...e.baseStyle?["index"]:[],...e.components??[]],a=await j$1(e.cwd,n),{config:s}=await T(o,a,{silent:true});s.registries&&(n.registries=s.registries);let c=t("Writing components.json.").start(),m=`${j__default.resolve(e.cwd,"components.json")}${he}`,p$1=(g,w)=>{let{registries:h,...x}=ir(g,w);return {...x,registries:h}};if(!e.force&&R.existsSync(m)){let g=await R.readJson(m);n=p$1(g,n);}e.registryBaseConfig&&(n=p$1(n,e.registryBaseConfig)),n.registries=Object.fromEntries(Object.entries(n.registries||{}).filter(([g])=>!Object.keys(b).includes(g))),c.succeed();let u=await j$1(e.cwd,n);return await ie(o,u,{overwrite:true,silent:e.silent,baseStyle:e.baseStyle,isNewProject:e.isNewProject||t$1?.framework.name==="next-app"}),u}async function Yi(e$1=null){let[t,r]=await Promise.all([aa(),ca()]);s.info("");let i=await Oe([{type:"toggle",name:"typescript",message:`Would you like to use ${d.info("TypeScript")} (recommended)?`,initial:e$1?.tsx??true,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${d.info("style")} would you like to use?`,choices:t.map(n=>({title:n.label,value:n.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${d.info("global CSS")} file?`,initial:e$1?.tailwind.css??g},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${d.info("CSS variables")} for theming?`,initial:e$1?.tailwind.cssVariables??true,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${d.info("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${d.info("tailwind.config.js")} located?`,initial:e$1?.tailwind.config??h},{type:"text",name:"components",message:`Configure the import alias for ${d.info("components")}:`,initial:e$1?.aliases.components??e},{type:"text",name:"utils",message:`Configure the import alias for ${d.info("utils")}:`,initial:e$1?.aliases.utils??f},{type:"toggle",name:"rsc",message:`Are you using ${d.info("React Server Components")}?`,initial:e$1?.rsc??true,active:"yes",inactive:"no"}]);return c.parse({$schema:"https://ui.shadcn.com/schema.json",style: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 Ki(e,t){let r$1=e.style,i=t.baseColor,n=e.tailwind.cssVariables,o=e.iconLibrary??"lucide";if(!t.defaults){let[a,s,c]=await Promise.all([aa(),ca(),r(e)]),l=await Oe([]);r$1=l.style??r$1??"new-york",i=l.tailwindBaseColor??i,n=t.cssVariables;}return c.parse({$schema:e?.$schema,style:r$1,tailwind:{...e?.tailwind,baseColor:i,cssVariables:n},rsc:e?.rsc,tsx:e?.tsx,iconLibrary:o,aliases:e?.aliases})}async function sr(e){let t={};if(!R.existsSync(e.cwd)||!R.existsSync(j__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,config:null};if(!R.existsSync(j__default.resolve(e.cwd,"components.json")))return t["3"]=true,{errors:t,config:null};try{let r=await i(e.cwd);return {errors:t,config:r}}catch{s.break(),s.error(`An invalid ${d.info("components.json")} file was found at ${d.info(e.cwd)}.
|
|
48
48
|
Before you can add components, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),s.error(`Learn more at ${d.info("https://ui.shadcn.com/docs/components-json")}.`),s.break(),process.exit(1);}}async function cr(e,t){let r=j__default.join(t.resolvedPaths.cwd,"app/page.tsx");if(!(await Y__default.stat(r)).isFile())return;let[i]=await Y$1([e],{config:t});if(!i?.meta?.importSpecifier||!i?.meta?.moduleSpecifier)return;let n=`import { ${i?.meta?.importSpecifier} } from "${i.meta.moduleSpecifier}"
|
|
49
49
|
|
|
50
50
|
export default function Page() {
|
|
51
51
|
return <${i?.meta?.importSpecifier} />
|
|
52
52
|
}`;await Y__default.writeFile(r,n,"utf8");}var Xi=z$1.object({components:z$1.array(z$1.string()).optional(),yes:z$1.boolean(),overwrite:z$1.boolean(),cwd:z$1.string(),all:z$1.boolean(),path:z$1.string().optional(),silent:z$1.boolean(),srcDir:z$1.boolean().optional(),cssVariables:z$1.boolean()}),fr=new Command().name("add").description("add a component to your project").argument("[components...]","names, url or local path to component").option("-y, --yes","skip confirmation prompt.",false).option("-o, --overwrite","overwrite existing files.",false).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-a, --all","add all available components",false).option("-p, --path <path>","the path to add the component to.").option("-s, --silent","mute output.",false).option("--src-dir","use the src directory when creating a new project.",false).option("--no-src-dir","do not use the src directory when creating a new project.").option("--css-variables","use css variables for theming.",true).option("--no-css-variables","do not use css variables for theming.").action(async(e,t)=>{try{let r=Xi.parse({components:e,cwd:j__default.resolve(t.cwd),...t});await B(r.cwd);let i$1=await i(r.cwd);i$1||(i$1=n({style:"new-york",resolvedPaths:{cwd:r.cwd}}));let n$1=["sidebar-","login-","signup-","otp-","calendar-"],o=["base-","radix-"];if(e.length>0&&i$1?.style&&o.some(x=>i$1?.style.startsWith(x))){let x=e.filter(v=>n$1.some(M=>v.startsWith(M)));x.length&&(s.warn(`The ${d.info(x.map(v=>v).join(", "))} component(s) are not available for the ${d.info(i$1.style)} style yet. They are coming soon.`),s.warn("In the meantime, you can visit the blocks page on https://ui.shadcn.com/blocks and copy the code."),s.break(),process.exit(1));}let a=!1;if(e.length>0){let{config:h,newRegistries:x}=await T(e,i$1,{silent:r.silent,writeFile:!1});i$1=h,a=x.length>0;}let s$1,c=!0;if(e.length>0){let[h]=await Y$1([e[0]],{config:i$1});if(s$1=h?.type,c=s$1!=="registry:theme"&&s$1!=="registry:style",N(h)){await ie(e,i$1,{...r,baseStyle:c});return}if(!r.yes&&(s$1==="registry:style"||s$1==="registry:theme")){s.break();let{confirm:x}=await Oe({type:"confirm",name:"confirm",message:d.warn(`You are about to install a new ${s$1.replace("registry:","")}.
|
|
53
|
-
Existing CSS variables and components will be overwritten. Continue?`)});x||(s.break(),s.log("Installation cancelled."),s.break(),process.exit(1));}}if(r.components?.length||(r.components=await Zi(r)),(await p(r.cwd))?.tailwindVersion==="v4"){let h=c$1.filter(x=>r.components?.includes(x.name));h?.length&&(s.break(),h.forEach(x=>{s.warn(d.warn(x.message));}),s.break(),process.exit(1));}let{errors:m,config:p$1}=await sr(r),u=!1;m["3"]&&(p$1=await le({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!1,silent:r.silent&&!a,isNewProject:!1,srcDir:r.srcDir,cssVariables:r.cssVariables,baseStyle:c,baseColor:c?void 0:"neutral",components:r.components}),u=!0);let g=!1;if(m["1"]){let{projectPath:h,template:x}=await Ee({cwd:r.cwd,force:r.overwrite,srcDir:r.srcDir,components:r.components});h||(s.break(),process.exit(1)),r.cwd=h,x==="next-monorepo"?(r.cwd=j__default.resolve(r.cwd,"apps/web"),p$1=await i(r.cwd)):(p$1=await le({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!0,silent:!a&&r.silent,isNewProject:!0,srcDir:r.srcDir,cssVariables:r.cssVariables,baseStyle:c,baseColor:c?void 0:"neutral",components:r.components}),u=!0,g=r.components?.length===1&&!!r.components[0].match(/\/chat\/b\//));}if(!p$1)throw new Error(`Failed to read config at ${d.info(r.cwd)}.`);let{config:w}=await T(r.components,p$1,{silent:r.silent||a});p$1=w,u||await ie(r.components,p$1,{...r,baseStyle:c}),g&&await cr(r.components[0],p$1);}catch(r){s.break(),W(r);}finally{P();}});async function Zi(e){let t=await $();if(!t)return s.break(),W(new Error("Failed to fetch registry index.")),[];if(e.all)return t.map(n=>n.name).filter(n=>!c$1.some(o=>o.name===n));if(e.components?.length)return e.components;let{components:r}=await Oe({type:"multiselect",name:"components",message:"Which components would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:false,choices:t.filter(n=>n.type==="registry:ui"&&!c$1.some(o=>o.name===n.name)).map(n=>({title:n.name,value:n.name,selected:e.all?true:e.components?.includes(n.name)}))});r?.length||(s.warn("No components selected. Exiting."),s.info(""),process.exit(1));let i=z$1.array(z$1.string()).safeParse(r);return i.success?i.data:(s.error(""),W(new Error("Something went wrong. Please try again.")),[])}async function ur(e){let t={},r={cwd:e.cwd,registryFile:j__default.resolve(e.cwd,e.registryFile),outputDir:j__default.resolve(e.cwd,e.outputDir)};return R.existsSync(r.registryFile)||(t["13"]=true),await R.mkdir(r.outputDir,{recursive:true}),Object.keys(t).length>0&&(t["13"]&&(s.break(),s.error(`The path ${d.info(r.registryFile)} does not exist.`)),s.break(),process.exit(1)),{errors:t,resolvePaths:r}}var en=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string()}),gr=new Command().name("build").description("build components for a shadcn registry").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t$1)=>{try{let r=en.parse({cwd:j.resolve(t$1.cwd),registryFile:e,outputDir:t$1.output}),{resolvePaths:i}=await ur(r),n=await Y.readFile(i.registryFile,"utf-8"),o$1=o.safeParse(JSON.parse(n));o$1.success||(s.error(`Invalid registry file found at ${d.info(i.registryFile)}.`),process.exit(1));let a=t("Building registry...");for(let s$1 of o$1.data.items){a.start(`Building ${s$1.name}...`),s$1.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let l of s$1.files??[])l.content=await Y.readFile(j.resolve(i.cwd,l.path),"utf-8");let c=n$1.safeParse(s$1);if(!c.success){s.error(`Invalid registry item found for ${d.info(s$1.name)}.`);continue}await Y.writeFile(j.resolve(i.outputDir,`${c.data.name}.json`),JSON.stringify(c.data,null,2));}await Y.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),a.succeed("Building registry.");}catch(r){s.break(),W(r);}});var wr="https://ui.shadcn.com",nn={next:"Next.js",vite:"Vite",start:"TanStack Start"},yr=new Command().name("create").description("create a new project with shadcn/ui").argument("[name]","the name of your project").option("-t, --template <template>","the template to use. e.g. next, start or vite").option("-p, --preset [name]","use a preset configuration").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("--src-dir","use the src directory when creating a new project.",false).option("--no-src-dir","do not use the src directory when creating a new project.").option("-y, --yes","skip confirmation prompt.",true).action(async(e,t)=>{try{if(!e&&!t.template&&!t.preset){let w=br();s.log("Build your own shadcn/ui."),s.log(`You will be taken to ${d.info(w)} to build your custom design system.`),s.break();let{proceed:h}=await Oe({type:"confirm",name:"proceed",message:"Open in browser?",initial:!0});h&&await hr(w),process.exit(0);}let i=e;if(!i){let{enteredName:w}=await Oe({type:"text",name:"enteredName",message:"What is your project named?",initial:t.template?`${t.template}-app`:"my-app",format:h=>h.trim(),validate:h=>h.length>128?"Name should be less than 128 characters.":!0});w||process.exit(0),i=w;}let n=t.template;if(!n){let{selectedTemplate:w}=await Oe({type:"select",name:"selectedTemplate",message:`Which ${d.info("template")} would you like to use?`,choices:Object.entries(nn).map(([h,x])=>({title:x,value:h}))});w||process.exit(0),n=w;}let o=await sn(t.preset??!0);o||process.exit(0);let a,s$1;"_isUrl"in o?(a=o.url,s$1=new URL(o.url).searchParams.get("baseColor")??"neutral"):(a=on(o),s$1=o.baseColor);let c=O({}),{config:l}=await T([a],c,{silent:!0});c=l;let[m]=await Y$1([a],{config:c}),p;m?.type==="registry:base"&&m.config&&(p=m.config);let u=rt.parse({cwd:j__default.resolve(t.cwd),name:i,components:[a],yes:t.yes,defaults:!1,force:!1,silent:!1,isNewProject:!0,srcDir:t.srcDir,cssVariables:!0,template:n,baseColor:s$1,baseStyle:!1,registryBaseConfig:p,skipPreflight:!1}),g=await le(u);if(g){await ie(["component-example"],g,{baseStyle:!1,silent:!0,overwrite:!0});let w=an(n);w.length>0&&await K(w,g,{overwrite:!0,silent:!0});}s.log(`${d.success("Success!")} Project initialization completed.
|
|
53
|
+
Existing CSS variables and components will be overwritten. Continue?`)});x||(s.break(),s.log("Installation cancelled."),s.break(),process.exit(1));}}if(r.components?.length||(r.components=await Zi(r)),(await p(r.cwd))?.tailwindVersion==="v4"){let h=c$1.filter(x=>r.components?.includes(x.name));h?.length&&(s.break(),h.forEach(x=>{s.warn(d.warn(x.message));}),s.break(),process.exit(1));}let{errors:m,config:p$1}=await sr(r),u=!1;m["3"]&&(p$1=await le({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!1,silent:r.silent&&!a,isNewProject:!1,srcDir:r.srcDir,cssVariables:r.cssVariables,baseStyle:c,baseColor:c?void 0:"neutral",components:r.components}),u=!0);let g=!1;if(m["1"]){let{projectPath:h,template:x}=await Ee({cwd:r.cwd,force:r.overwrite,srcDir:r.srcDir,components:r.components});h||(s.break(),process.exit(1)),r.cwd=h,x==="next-monorepo"?(r.cwd=j__default.resolve(r.cwd,"apps/web"),p$1=await i(r.cwd)):(p$1=await le({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!0,silent:!a&&r.silent,isNewProject:!0,srcDir:r.srcDir,cssVariables:r.cssVariables,baseStyle:c,baseColor:c?void 0:"neutral",components:r.components}),u=!0,g=r.components?.length===1&&!!r.components[0].match(/\/chat\/b\//));}if(!p$1)throw new Error(`Failed to read config at ${d.info(r.cwd)}.`);let{config:w}=await T(r.components,p$1,{silent:r.silent||a});p$1=w,u||await ie(r.components,p$1,{...r,baseStyle:c}),g&&await cr(r.components[0],p$1);}catch(r){console.log("add error"),s.break(),W(r);}finally{P();}});async function Zi(e){let t=await $();if(!t)return s.break(),W(new Error("Failed to fetch registry index.")),[];if(e.all)return t.map(n=>n.name).filter(n=>!c$1.some(o=>o.name===n));if(e.components?.length)return e.components;let{components:r}=await Oe({type:"multiselect",name:"components",message:"Which components would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:false,choices:t.filter(n=>n.type==="registry:ui"&&!c$1.some(o=>o.name===n.name)).map(n=>({title:n.name,value:n.name,selected:e.all?true:e.components?.includes(n.name)}))});r?.length||(s.warn("No components selected. Exiting."),s.info(""),process.exit(1));let i=z$1.array(z$1.string()).safeParse(r);return i.success?i.data:(s.error(""),W(new Error("Something went wrong. Please try again.")),[])}async function ur(e){let t={},r={cwd:e.cwd,registryFile:j__default.resolve(e.cwd,e.registryFile),outputDir:j__default.resolve(e.cwd,e.outputDir)};return R.existsSync(r.registryFile)||(t["13"]=true),await R.mkdir(r.outputDir,{recursive:true}),Object.keys(t).length>0&&(t["13"]&&(s.break(),s.error(`The path ${d.info(r.registryFile)} does not exist.`)),s.break(),process.exit(1)),{errors:t,resolvePaths:r}}var en=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string()}),gr=new Command().name("build").description("build components for a shadcn registry").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t$1)=>{try{let r=en.parse({cwd:j.resolve(t$1.cwd),registryFile:e,outputDir:t$1.output}),{resolvePaths:i}=await ur(r),n=await Y.readFile(i.registryFile,"utf-8"),o$1=o.safeParse(JSON.parse(n));o$1.success||(s.error(`Invalid registry file found at ${d.info(i.registryFile)}.`),process.exit(1));let a=t("Building registry...");for(let s$1 of o$1.data.items){a.start(`Building ${s$1.name}...`),s$1.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let l of s$1.files??[])l.content=await Y.readFile(j.resolve(i.cwd,l.path),"utf-8");let c=n$1.safeParse(s$1);if(!c.success){s.error(`Invalid registry item found for ${d.info(s$1.name)}.`);continue}await Y.writeFile(j.resolve(i.outputDir,`${c.data.name}.json`),JSON.stringify(c.data,null,2));}await Y.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),a.succeed("Building registry.");}catch(r){s.break(),W(r);}});var wr="https://ui.shadcn.com",nn={next:"Next.js",vite:"Vite",start:"TanStack Start"},yr=new Command().name("create").description("create a new project with shadcn/ui").argument("[name]","the name of your project").option("-t, --template <template>","the template to use. e.g. next, start or vite").option("-p, --preset [name]","use a preset configuration").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("--src-dir","use the src directory when creating a new project.",false).option("--no-src-dir","do not use the src directory when creating a new project.").option("-y, --yes","skip confirmation prompt.",true).action(async(e,t)=>{try{if(!e&&!t.template&&!t.preset){let w=br();s.log("Build your own shadcn/ui."),s.log(`You will be taken to ${d.info(w)} to build your custom design system.`),s.break();let{proceed:h}=await Oe({type:"confirm",name:"proceed",message:"Open in browser?",initial:!0});h&&await hr(w),process.exit(0);}let i=e;if(!i){let{enteredName:w}=await Oe({type:"text",name:"enteredName",message:"What is your project named?",initial:t.template?`${t.template}-app`:"my-app",format:h=>h.trim(),validate:h=>h.length>128?"Name should be less than 128 characters.":!0});w||process.exit(0),i=w;}let n=t.template;if(!n){let{selectedTemplate:w}=await Oe({type:"select",name:"selectedTemplate",message:`Which ${d.info("template")} would you like to use?`,choices:Object.entries(nn).map(([h,x])=>({title:x,value:h}))});w||process.exit(0),n=w;}let o=await sn(t.preset??!0);o||process.exit(0);let a,s$1;"_isUrl"in o?(a=o.url,s$1=new URL(o.url).searchParams.get("baseColor")??"neutral"):(a=on(o),s$1=o.baseColor);let c=O({}),{config:l}=await T([a],c,{silent:!0});c=l;let[m]=await Y$1([a],{config:c}),p;m?.type==="registry:base"&&m.config&&(p=m.config);let u=rt.parse({cwd:j__default.resolve(t.cwd),name:i,components:[a],yes:t.yes,defaults:!1,force:!1,silent:!1,isNewProject:!0,srcDir:t.srcDir,cssVariables:!0,template:n,baseColor:s$1,baseStyle:!1,registryBaseConfig:p,skipPreflight:!1}),g=await le(u);if(g){await ie(["component-example"],g,{baseStyle:!1,silent:!0,overwrite:!0});let w=an(n);w.length>0&&await K(w,g,{overwrite:!0,silent:!0});}s.log(`${d.success("Success!")} Project initialization completed.
|
|
54
54
|
You may now add components.`),s.break();}catch(r){s.break(),W(r);}finally{P();}});function on(e){let t=new URLSearchParams({base:e.base,style:e.style,baseColor:e.baseColor,theme:e.theme,iconLibrary:e.iconLibrary,font:e.font,menuAccent:e.menuAccent,menuColor:e.menuColor,radius:e.radius});return `${cn()}?${t.toString()}`}async function sn(e){if(e===true){let t=await ia(),{selectedPreset:r}=await Oe({type:"select",name:"selectedPreset",message:`Which ${d.info("preset")} would you like to use?`,choices:[...t.map(i=>({title:i.title,description:i.description,value:i.name})),{title:"Custom",description:"Build your own on https://ui.shadcn.com",value:"custom"}]});if(!r)return null;if(r==="custom"){let i=br();return s.info(`
|
|
55
55
|
Opening ${d.info(i)} in your browser...
|
|
56
56
|
`),await hr(i),null}return t.find(i=>i.name===r)??null}if(typeof e=="string"){if(M(e))return {_isUrl:true,url:e};let t=await ja(e);if(!t){let i=(await ia()).map(n=>n.name).join(", ");s.error(`Preset "${e}" not found. Available presets: ${i}`),process.exit(1);}return t}return null}function an(e){switch(e){case "vite":return [{type:"registry:file",path:"src/App.tsx",target:"src/App.tsx",content:nt`import { ComponentExample } from "@/components/component-example";
|
|
@@ -88,5 +88,5 @@ args = ["shadcn@${fe}", "mcp"]`),s.break(),s.info("3. Restart Codex to load the
|
|
|
88
88
|
`).map(x=>{if(x.trim().startsWith("import "))return x;let v=x;return v=v.replace(/\b(asChild\s*\?\s*)Slot(\s*:)/g,"$1__SLOT_PLACEHOLDER__$2"),v=v.replace(/\bReact\.ComponentProps<typeof\s+Slot>/g,"React.ComponentProps<typeof __SLOT_PLACEHOLDER__>"),v=v.replace(/\bComponentProps<typeof\s+Slot>/g,"ComponentProps<typeof __SLOT_PLACEHOLDER__>"),v=v.replace(/(<\/?)Slot(\s*\/?>)/g,"$1__SLOT_PLACEHOLDER__$2"),v=v.replace(/\bSlot\b/g,(M,F,X)=>{let A=X.substring(0,F),De=(A.match(/"/g)||[]).length,Ur=(A.match(/'/g)||[]).length;return De%2!==0||Ur%2!==0?M:"__SLOT_PLACEHOLDER__"}),v=v.replace(/__SLOT_PLACEHOLDER__/g,"SlotPrimitive.Slot"),v}).join(`
|
|
89
89
|
`));let g=Array.from(new Set(n));return {content:s,replacedPackages:g}}async function $r(e){let t={};if(!R.existsSync(e.cwd)||!R.existsSync(j__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,config:null};if(!R.existsSync(j__default.resolve(e.cwd,"components.json")))return t["3"]=true,{errors:t,config:null};try{let r=await i(e.cwd);return {errors:t,config:r}}catch{s.break(),s.error(`An invalid ${d.info("components.json")} file was found at ${d.info(e.cwd)}.
|
|
90
90
|
Before you can run a migration, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),s.error(`Learn more at ${d.info("https://ui.shadcn.com/docs/components-json")}.`),s.break(),process.exit(1);}}var Nr=[{name:"icons",description:"migrate your ui components to a different icon library."},{name:"radix",description:"migrate to radix-ui."}],_n=z$1.object({cwd:z$1.string(),list:z$1.boolean(),yes:z$1.boolean(),migration:z$1.string().refine(e=>e&&Nr.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional()}),Or=new Command().name("migrate").description("run a migration.").argument("[migration]","the migration to run.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-l, --list","list all migrations.",false).option("-y, --yes","skip confirmation prompt.",false).action(async(e,t)=>{try{let r=_n.parse({cwd:j__default.resolve(t.cwd),migration:e,list:t.list,yes:t.yes});if(r.list||!r.migration){s.info("Available migrations:");for(let o of Nr)s.info(`- ${o.name}: ${o.description}`);return}if(!r.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:i,config:n}=await $r(r);if(i["1"]||i["3"])throw new Error("No `components.json` file found. Ensure you are at the root of your project.");if(!n)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");r.migration==="icons"&&await Pr(n),r.migration==="radix"&&await jr(n,{yes:r.yes});}catch(r){s.break(),W(r);}});async function Tr(e){let t={},r={cwd:e.cwd,registryFile:j__default.resolve(e.cwd,e.registryFile),outputDir:j__default.resolve(e.cwd,e.outputDir)};if(!R.existsSync(r.registryFile))return t["13"]=true,{errors:t,resolvePaths:null,config:null};if(!R.existsSync(j__default.resolve(e.cwd,"components.json")))return t["3"]=true,{errors:t,resolvePaths:null,config:null};await R.mkdir(r.outputDir,{recursive:true});try{let i$1=await i(e.cwd);return {errors:t,config:i$1,resolvePaths:r}}catch{s.break(),s.error(`An invalid ${d.info("components.json")} file was found at ${d.info(e.cwd)}.
|
|
91
|
-
Before you can build the registry, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),s.break(),process.exit(1);}}var Vn=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),Fr=new Command().name("registry:build").description("builds the registry [EXPERIMENTAL]").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-v, --verbose","verbose output").action(async(e,t)=>{await Mn({cwd:j.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function Mn(e){try{let t$1=Vn.parse(e),[{errors:r,resolvePaths:i,config:n},o$1]=await Promise.all([Tr(t$1),p(t$1.cwd)]);(r["3"]||!n||!o$1)&&(s.error(`A ${d.info("components.json")} file is required to build the registry. Run ${d.info("shadcn init")} to create one.`),s.break(),process.exit(1)),(r["13"]||!i)&&(s.error(`We could not find a registry file at ${d.info(j.resolve(t$1.cwd,t$1.registryFile))}.`),s.break(),process.exit(1));let a=await Y.readFile(i.registryFile,"utf-8"),s$1=o.safeParse(JSON.parse(a));s$1.success||(s.error(`Invalid registry file found at ${d.info(i.registryFile)}.`),s.break(),process.exit(1));let c=t("Building registry..."),l=await Wn(s$1.data,n,o$1);for(let m of l.items)m.files=m.files?.filter((p,u,g)=>u===g.findIndex(w=>w.path===p.path)),m.dependencies&&(m.dependencies=m.dependencies.filter((p,u,g)=>u===g.findIndex(w=>w===p)));for(let m of l.items){if(!m.files)continue;c.start(`Building ${m.name}...`),m.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let u of m.files){let g=j.resolve(i.cwd,u.path);try{if(!(await Y.stat(g)).isFile())continue;u.content=await Y.readFile(g,"utf-8");}catch(w){console.error("Error reading file in registry build:",g,w);continue}}let p=n$1.safeParse(m);if(!p.success){s.error(`Invalid registry item found for ${d.info(m.name)}.`);continue}await Y.writeFile(j.resolve(i.outputDir,`${p.data.name}.json`),JSON.stringify(p.data,null,2));}if(await Y.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t$1.verbose){t(`The registry has ${d.info(l.items.length.toString())} items:`).succeed();for(let m of l.items){s.log(` - ${m.name} (${d.info(m.type)})`);for(let p of m.files??[])s.log(` - ${p.path}`);}}}catch(t){s.break(),W(t);}}async function Wn(e,t,r){for(let i of e.items)if(i.files?.length)for(let n of i.files){let o=await L$1(n.path,t,r);o.files=o.files?.filter(a=>a.path!==n.path),o.files&&i.files.push(...o.files),o.dependencies&&(i.dependencies=i.dependencies?i.dependencies.concat(o.dependencies):o.dependencies);}return e}var Ar=new Command().name("registry:mcp").description("starts the registry MCP server [DEPRECATED]").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async()=>{s.warn(`The ${d.info("shadcn registry:mcp")} command is deprecated. Use the ${d.info("shadcn mcp")} command instead.`),s.break();});var Un=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),Lr=new Command().name("search").alias("list").description("search items from registries").argument("<registries...>","the registry names or urls to search items from. Names must be prefixed with @.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-q, --query <query>","query string").option("-l, --limit <number>","maximum number of items to display per registry","100").option("-o, --offset <number>","number of items to skip","0").action(async(e,t)=>{try{let r=Un.parse({cwd:j__default.resolve(t.cwd),query:t.query,limit:t.limit?parseInt(t.limit,10):void 0,offset:t.offset?parseInt(t.offset,10):void 0});await B(r.cwd);let i$1=n({style:"new-york",resolvedPaths:{cwd:r.cwd}}),n$1=O(i$1),o=j__default.resolve(r.cwd,"components.json");if(R.existsSync(o)){let m=await R.readJson(o),p=c.partial().parse(m);n$1=O({...i$1,...p});}let a=n$1;try{let m=await i(r.cwd);m&&(a=O(m));}catch{}let{config:s,newRegistries:c$1}=await T(e.map(m=>`${m}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),Q(e,a);let l=await ka(e,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(l,null,2)),process.exit(0);}catch(r){W(r);}finally{P();}});var Jn=z$1.object({cwd:z$1.string()}),zr=new Command().name("view").description("view items from the registry").argument("<items...>","the item names or URLs to view").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t)=>{try{let r=Jn.parse({cwd:j__default.resolve(t.cwd)});await B(r.cwd);let i$1=O({}),n=j__default.resolve(r.cwd,"components.json");if(R.existsSync(n)){let l=await R.readJson(n),m=c.partial().parse(l);i$1=O(m);}let o=i$1;try{let l=await i(r.cwd);l&&(o=O(l));}catch{}let{config:a,newRegistries:s}=await T(e,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),Q(e,o);let c$1=await Y$1(e,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){W(r);}finally{P();}});var Br={version:"3.6.
|
|
91
|
+
Before you can build the registry, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),s.break(),process.exit(1);}}var Vn=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),Fr=new Command().name("registry:build").description("builds the registry [EXPERIMENTAL]").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-v, --verbose","verbose output").action(async(e,t)=>{await Mn({cwd:j.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function Mn(e){try{let t$1=Vn.parse(e),[{errors:r,resolvePaths:i,config:n},o$1]=await Promise.all([Tr(t$1),p(t$1.cwd)]);(r["3"]||!n||!o$1)&&(s.error(`A ${d.info("components.json")} file is required to build the registry. Run ${d.info("shadcn init")} to create one.`),s.break(),process.exit(1)),(r["13"]||!i)&&(s.error(`We could not find a registry file at ${d.info(j.resolve(t$1.cwd,t$1.registryFile))}.`),s.break(),process.exit(1));let a=await Y.readFile(i.registryFile,"utf-8"),s$1=o.safeParse(JSON.parse(a));s$1.success||(s.error(`Invalid registry file found at ${d.info(i.registryFile)}.`),s.break(),process.exit(1));let c=t("Building registry..."),l=await Wn(s$1.data,n,o$1);for(let m of l.items)m.files=m.files?.filter((p,u,g)=>u===g.findIndex(w=>w.path===p.path)),m.dependencies&&(m.dependencies=m.dependencies.filter((p,u,g)=>u===g.findIndex(w=>w===p)));for(let m of l.items){if(!m.files)continue;c.start(`Building ${m.name}...`),m.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let u of m.files){let g=j.resolve(i.cwd,u.path);try{if(!(await Y.stat(g)).isFile())continue;u.content=await Y.readFile(g,"utf-8");}catch(w){console.error("Error reading file in registry build:",g,w);continue}}let p=n$1.safeParse(m);if(!p.success){s.error(`Invalid registry item found for ${d.info(m.name)}.`);continue}await Y.writeFile(j.resolve(i.outputDir,`${p.data.name}.json`),JSON.stringify(p.data,null,2));}if(await Y.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t$1.verbose){t(`The registry has ${d.info(l.items.length.toString())} items:`).succeed();for(let m of l.items){s.log(` - ${m.name} (${d.info(m.type)})`);for(let p of m.files??[])s.log(` - ${p.path}`);}}}catch(t){s.break(),W(t);}}async function Wn(e,t,r){for(let i of e.items)if(i.files?.length)for(let n of i.files){let o=await L$1(n.path,t,r);o.files=o.files?.filter(a=>a.path!==n.path),o.files&&i.files.push(...o.files),o.dependencies&&(i.dependencies=i.dependencies?i.dependencies.concat(o.dependencies):o.dependencies);}return e}var Ar=new Command().name("registry:mcp").description("starts the registry MCP server [DEPRECATED]").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async()=>{s.warn(`The ${d.info("shadcn registry:mcp")} command is deprecated. Use the ${d.info("shadcn mcp")} command instead.`),s.break();});var Un=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),Lr=new Command().name("search").alias("list").description("search items from registries").argument("<registries...>","the registry names or urls to search items from. Names must be prefixed with @.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-q, --query <query>","query string").option("-l, --limit <number>","maximum number of items to display per registry","100").option("-o, --offset <number>","number of items to skip","0").action(async(e,t)=>{try{let r=Un.parse({cwd:j__default.resolve(t.cwd),query:t.query,limit:t.limit?parseInt(t.limit,10):void 0,offset:t.offset?parseInt(t.offset,10):void 0});await B(r.cwd);let i$1=n({style:"new-york",resolvedPaths:{cwd:r.cwd}}),n$1=O(i$1),o=j__default.resolve(r.cwd,"components.json");if(R.existsSync(o)){let m=await R.readJson(o),p=c.partial().parse(m);n$1=O({...i$1,...p});}let a=n$1;try{let m=await i(r.cwd);m&&(a=O(m));}catch{}let{config:s,newRegistries:c$1}=await T(e.map(m=>`${m}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),Q(e,a);let l=await ka(e,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(l,null,2)),process.exit(0);}catch(r){W(r);}finally{P();}});var Jn=z$1.object({cwd:z$1.string()}),zr=new Command().name("view").description("view items from the registry").argument("<items...>","the item names or URLs to view").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t)=>{try{let r=Jn.parse({cwd:j__default.resolve(t.cwd)});await B(r.cwd);let i$1=O({}),n=j__default.resolve(r.cwd,"components.json");if(R.existsSync(n)){let l=await R.readJson(n),m=c.partial().parse(l);i$1=O(m);}let o=i$1;try{let l=await i(r.cwd);l&&(o=O(l));}catch{}let{config:a,newRegistries:s}=await T(e,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),Q(e,o);let c$1=await Y$1(e,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){W(r);}finally{P();}});var Br={version:"3.6.11"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function qn(){let e=new Command().name("shadcn").description("add items from registries to your project").version(Br.version,"-v, --version","display the version number");e.addCommand(nr).addCommand(yr).addCommand(fr).addCommand(vr).addCommand(zr).addCommand(Lr).addCommand(Or).addCommand(Sr).addCommand(gr).addCommand(ct),e.addCommand(Fr).addCommand(Ar),e.parse();}qn();//# sourceMappingURL=index.js.map
|
|
92
92
|
//# sourceMappingURL=index.js.map
|