hghcn 3.6.17 → 3.6.18
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 +2 -2
- 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
|
@@ -46,7 +46,7 @@ Some packages may fail to install due to peer dependency issues in npm (see http
|
|
|
46
46
|
`,"utf-8"),p.succeed();}return {config:c$1,newRegistries:Object.keys(a)}}async function cr(e,t$1,r){if(!e)return;r={silent:false,...r};let i=j__default.relative(t$1.resolvedPaths.cwd,t$1.resolvedPaths.tailwindConfig),n=t(`Updating ${d.info(i)}`,{silent:r.silent}).start(),o=await promises.readFile(t$1.resolvedPaths.tailwindConfig,"utf8"),a=await Hi(o,e,t$1);await promises.writeFile(t$1.resolvedPaths.tailwindConfig,a,"utf8"),n?.succeed();}async function Hi(e,t,r){let i=await U(e,r),n=i.getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression).find(o=>o.getProperties().some(a=>a.isKind(SyntaxKind.PropertyAssignment)&&a.getName()==="content"));return n?(Xi(n,t),i.getFullText()):e}async function Xi(e,t){let r=V(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(SyntaxKind.PropertyAssignment)){let n=i.getInitializer();if(n?.isKind(SyntaxKind.ArrayLiteralExpression))for(let o of t){let a=`${r}${o}${r}`;n.getElements().map(s=>s.getText()).includes(a)||n.addElement(a);}return e}return e}process.on("exit",e=>{let t=j__default.resolve(process.cwd(),"components.json");return e===0?tt(t):or(t)});var it=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?D[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()}),mr=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=it.parse({cwd:j__default.resolve(t.cwd),isNewProject:!1,components:e,...t});if(await z(r.cwd),e.length>0){let i=O(n({resolvedPaths:{cwd:r.cwd}})),n$1=j__default.resolve(r.cwd,"components.json");if(S.existsSync(n$1)){let s=await S.readJson(n$1),c$1=c.partial().parse(s),m=n({resolvedPaths:{cwd:r.cwd}});i=O({...c$1,resolvedPaths:{...m.resolvedPaths,cwd:r.cwd}}),nr(n$1);}let{config:o}=await _(e,i,{silent:!0,writeFile:!1});i=o,R(e[0],i);let[a]=await _$1([e[0]],{config:i});a?.type==="registry:base"&&(a.config&&(i=O(lr(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
47
|
You may now add components.`),tt(j__default.resolve(r.cwd,"components.json")),s.break();}catch(r){s.break(),Y(r);}finally{P();}});async function le(e){let t$1,r;if(e.skipPreflight)t$1=await p(e.cwd);else {let h=await Jt(e);if(h.errors["1"]){let{projectPath:g,template:w}=await Ee(e);g||process.exit(1),e.cwd=g,e.isNewProject=true,r=w,t$1=await p(e.cwd);}else t$1=h.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 en(i$1,e):await Zi(await i(e.cwd));if(!e.yes){let{proceed:h}=await Te({type:"confirm",name:"proceed",message:`Write configuration to ${d.info("components.json")}. Proceed?`,initial:true});h||process.exit(0);}let o=[...e.baseStyle?["index"]:[],...e.components??[]],a=await j$1(e.cwd,n),{config:s}=await _(o,a,{silent:true});s.registries&&(n.registries=s.registries);let c=t("Writing components.json.").start(),l=`${j__default.resolve(e.cwd,"components.json")}${he}`,p$1=(h,g)=>{let{registries:w,...C}=lr(h,g);return {...C,registries:w}};if(!e.force&&S.existsSync(l)){let h=await S.readJson(l);n=p$1(h,n);}e.registryBaseConfig&&(n=p$1(n,e.registryBaseConfig)),n.registries=Object.fromEntries(Object.entries(n.registries||{}).filter(([h])=>!Object.keys(b).includes(h))),c.succeed();let u=await j$1(e.cwd,n);return await se(o,u,{overwrite:true,silent:e.silent,baseStyle:e.baseStyle,isNewProject:e.isNewProject||t$1?.framework.name==="next-app"}),e.isNewProject&&e.srcDir&&await cr(["./src/**/*.{js,ts,jsx,tsx,mdx}"],u,{silent:e.silent}),u}async function Zi(e$1=null){let[t,r]=await Promise.all([ca(),ea()]);s.info("");let i=await Te([{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:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${d.info("base color")}?`,choices:r.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 en(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([ca(),ea(),r(e)]),m=await Te([{type:c==="v4"||r$1?null:"select",name:"style",message:`Which ${d.info("style")} would you like to use?`,choices:a.map(l=>({title:l.name==="new-york"?"New York (Recommended)":l.label,value:l.name})),initial:0},{type:t.baseColor?null:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${d.info("base color")}?`,choices:s.map(l=>({title:l.label,value:l.name}))}]);r$1=m.style??r$1??"new-york",i=m.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 pr(e){let t={};if(!S.existsSync(e.cwd)||!S.existsSync(j__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,config:null};if(!S.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);}}var rn=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()}),ur=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=rn.parse({components:e,cwd:j__default.resolve(t.cwd),...t});await z(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(w=>i$1?.style.startsWith(w))){let w=e.filter(C=>n$1.some(v=>C.startsWith(v)));w.length&&(s.warn(`The ${d.info(w.map(C=>C).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:g,newRegistries:w}=await _(e,i$1,{silent:r.silent,writeFile:!1});i$1=g,a=w.length>0;}let s$1,c=!0;if(e.length>0){let[g]=await _$1([e[0]],{config:i$1});if(s$1=g?.type,c=s$1!=="registry:theme"&&s$1!=="registry:style",N(g)){await se(e,i$1,{...r,baseStyle:c});return}if(!r.yes&&(s$1==="registry:style"||s$1==="registry:theme")){s.break();let{confirm:w}=await Te({type:"confirm",name:"confirm",message:d.warn(`You are about to install a new ${s$1.replace("registry:","")}.
|
|
49
|
-
Existing CSS variables and components will be overwritten. Continue?`)});w||(s.break(),s.log("Installation cancelled."),s.break(),process.exit(1));}}if(r.components?.length||(r.components=await nn(r)),(await p(r.cwd))?.tailwindVersion==="v4"){let g=c$1.filter(w=>r.components?.includes(w.name));g?.length&&(s.break(),g.forEach(w=>{s.warn(d.warn(w.message));}),s.break(),process.exit(1));}let{errors:l,config:p$1}=await pr(r),u=!1;if(l["3"]){let{proceed:g}=await Te({type:"confirm",name:"proceed",message:`You need to create a ${d.info("components.json")} file to add components. Proceed?`,initial:!0});g||(s.break(),process.exit(1)),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 h=!1;if(l["1"]){let{projectPath:g,template:w}=await Ee({cwd:r.cwd,force:r.overwrite,srcDir:r.srcDir,components:r.components});g||(s.break(),process.exit(1)),r.cwd=g,w==="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,h=r.components?.length===1&&!!r.components[0].match(/\/chat\/b\//));}}catch(r){console.log("add error"),s.break(),Y(r);}finally{P();}});async function nn(e){let t=await ba();if(!t)return s.break(),Y(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 Te({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(""),Y(new Error("Something went wrong. Please try again.")),[])}async function wr(e){let t={},r={cwd:e.cwd,registryFile:j__default.resolve(e.cwd,e.registryFile),outputDir:j__default.resolve(e.cwd,e.outputDir)};return S.existsSync(r.registryFile)||(t["13"]=true),await S.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 sn=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string()}),yr=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=sn.parse({cwd:j.resolve(t$1.cwd),registryFile:e,outputDir:t$1.output}),{resolvePaths:i}=await wr(r),n=await J.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 m of s$1.files??[])m.content=await J.readFile(j.resolve(i.cwd,m.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 J.writeFile(j.resolve(i.outputDir,`${c.data.name}.json`),JSON.stringify(c.data,null,2));}await J.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),a.succeed("Building registry.");}catch(r){s.break(),Y(r);}});var xr="https://ui.shadcn.com",ln={next:"Next.js",vite:"Vite",start:"TanStack Start"},vr=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 g=Sr();s.log("Build your own shadcn/ui."),s.log(`You will be taken to ${d.info(g)} to build your custom design system.`),s.break();let{proceed:w}=await Te({type:"confirm",name:"proceed",message:"Open in browser?",initial:!0});w&&await br(g),process.exit(0);}let i=e;if(!i){let{enteredName:g}=await Te({type:"text",name:"enteredName",message:"What is your project named?",initial:t.template?`${t.template}-app`:"my-app",format:w=>w.trim(),validate:w=>w.length>128?"Name should be less than 128 characters.":!0});g||process.exit(0),i=g;}let n=t.template;if(!n){let{selectedTemplate:g}=await Te({type:"select",name:"selectedTemplate",message:`Which ${d.info("template")} would you like to use?`,choices:Object.entries(ln).map(([w,C])=>({title:C,value:w}))});g||process.exit(0),n=g;}let o=await fn(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=mn(o),s$1=o.baseColor);let c=O({}),{config:m}=await _([a],c,{silent:!0});c=m;let[l]=await _$1([a],{config:c}),p;l?.type==="registry:base"&&l.config&&(p=l.config);let u=it.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}),h=await le(u);if(h){await se(["component-example"],h,{baseStyle:!1,silent:!0,overwrite:!0});let g=pn(n);g.length>0&&await K(g,h,{overwrite:!0,silent:!0});}s.log(`${d.success("Success!")} Project initialization completed.
|
|
49
|
+
Existing CSS variables and components will be overwritten. Continue?`)});w||(s.break(),s.log("Installation cancelled."),s.break(),process.exit(1));}}if(r.components?.length||(r.components=await nn(r)),(await p(r.cwd))?.tailwindVersion==="v4"){let g=c$1.filter(w=>r.components?.includes(w.name));g?.length&&(s.break(),g.forEach(w=>{s.warn(d.warn(w.message));}),s.break(),process.exit(1));}let{errors:l,config:p$1}=await pr(r);console.log({errors:l,config:p$1});let u=!1;if(l["3"]){let{proceed:g}=await Te({type:"confirm",name:"proceed",message:`You need to create a ${d.info("components.json")} file to add components. Proceed?`,initial:!0});g||(s.break(),process.exit(1)),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 h=!1;if(l["1"]){let{projectPath:g,template:w}=await Ee({cwd:r.cwd,force:r.overwrite,srcDir:r.srcDir,components:r.components});g||(s.break(),process.exit(1)),r.cwd=g,w==="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,h=r.components?.length===1&&!!r.components[0].match(/\/chat\/b\//));}}catch(r){console.log("add error"),s.break(),Y(r);}finally{P();}});async function nn(e){let t=await ba();if(!t)return s.break(),Y(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 Te({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(""),Y(new Error("Something went wrong. Please try again.")),[])}async function wr(e){let t={},r={cwd:e.cwd,registryFile:j__default.resolve(e.cwd,e.registryFile),outputDir:j__default.resolve(e.cwd,e.outputDir)};return S.existsSync(r.registryFile)||(t["13"]=true),await S.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 sn=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string()}),yr=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=sn.parse({cwd:j.resolve(t$1.cwd),registryFile:e,outputDir:t$1.output}),{resolvePaths:i}=await wr(r),n=await J.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 m of s$1.files??[])m.content=await J.readFile(j.resolve(i.cwd,m.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 J.writeFile(j.resolve(i.outputDir,`${c.data.name}.json`),JSON.stringify(c.data,null,2));}await J.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),a.succeed("Building registry.");}catch(r){s.break(),Y(r);}});var xr="https://ui.shadcn.com",ln={next:"Next.js",vite:"Vite",start:"TanStack Start"},vr=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 g=Sr();s.log("Build your own shadcn/ui."),s.log(`You will be taken to ${d.info(g)} to build your custom design system.`),s.break();let{proceed:w}=await Te({type:"confirm",name:"proceed",message:"Open in browser?",initial:!0});w&&await br(g),process.exit(0);}let i=e;if(!i){let{enteredName:g}=await Te({type:"text",name:"enteredName",message:"What is your project named?",initial:t.template?`${t.template}-app`:"my-app",format:w=>w.trim(),validate:w=>w.length>128?"Name should be less than 128 characters.":!0});g||process.exit(0),i=g;}let n=t.template;if(!n){let{selectedTemplate:g}=await Te({type:"select",name:"selectedTemplate",message:`Which ${d.info("template")} would you like to use?`,choices:Object.entries(ln).map(([w,C])=>({title:C,value:w}))});g||process.exit(0),n=g;}let o=await fn(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=mn(o),s$1=o.baseColor);let c=O({}),{config:m}=await _([a],c,{silent:!0});c=m;let[l]=await _$1([a],{config:c}),p;l?.type==="registry:base"&&l.config&&(p=l.config);let u=it.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}),h=await le(u);if(h){await se(["component-example"],h,{baseStyle:!1,silent:!0,overwrite:!0});let g=pn(n);g.length>0&&await K(g,h,{overwrite:!0,silent:!0});}s.log(`${d.success("Success!")} Project initialization completed.
|
|
50
50
|
You may now add components.`),s.break();}catch(r){s.break(),Y(r);}finally{P();}});function mn(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 `${dn()}?${t.toString()}`}async function fn(e){if(e===true){let t=await ka(),{selectedPreset:r}=await Te({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=Sr();return s.info(`
|
|
51
51
|
Opening ${d.info(i)} in your browser...
|
|
52
52
|
`),await br(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 la(e);if(!t){let i=(await ka()).map(n=>n.name).join(", ");s.error(`Preset "${e}" not found. Available presets: ${i}`),process.exit(1);}return t}return null}function pn(e){switch(e){case "vite":return [{type:"registry:file",path:"src/App.tsx",target:"src/App.tsx",content:st`import { ComponentExample } from "@/components/component-example";
|
|
@@ -84,5 +84,5 @@ args = ["shadcn@${fe}", "mcp"]`),s.break(),s.info("3. Restart Codex to load the
|
|
|
84
84
|
`).map(C=>{if(C.trim().startsWith("import "))return C;let v=C;return v=v.replace(/\b(asChild\s*\?\s*)Slot(\s*:)/g,"$1__SLOT_PLACEHOLDER__$2"),v=v.replace(/\bReact\.ComponentProps<typeof\s+Slot>/g,"React.ComponentProps<typeof __SLOT_PLACEHOLDER__>"),v=v.replace(/\bComponentProps<typeof\s+Slot>/g,"ComponentProps<typeof __SLOT_PLACEHOLDER__>"),v=v.replace(/(<\/?)Slot(\s*\/?>)/g,"$1__SLOT_PLACEHOLDER__$2"),v=v.replace(/\bSlot\b/g,(Y,O,X)=>{let T=X.substring(0,O),_e=(T.match(/"/g)||[]).length,Yr=(T.match(/'/g)||[]).length;return _e%2!==0||Yr%2!==0?Y:"__SLOT_PLACEHOLDER__"}),v=v.replace(/__SLOT_PLACEHOLDER__/g,"SlotPrimitive.Slot"),v}).join(`
|
|
85
85
|
`));let h=Array.from(new Set(n));return {content:s,replacedPackages:h}}async function Tr(e){let t={};if(!S.existsSync(e.cwd)||!S.existsSync(j__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,config:null};if(!S.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)}.
|
|
86
86
|
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 Fr=[{name:"icons",description:"migrate your ui components to a different icon library."},{name:"radix",description:"migrate to radix-ui."}],zn=z$1.object({cwd:z$1.string(),list:z$1.boolean(),yes:z$1.boolean(),migration:z$1.string().refine(e=>e&&Fr.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional()}),Ar=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=zn.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 Fr)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 Tr(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 $r(n),r.migration==="radix"&&await Nr(n,{yes:r.yes});}catch(r){s.break(),Y(r);}});async function Dr(e){let t={},r={cwd:e.cwd,registryFile:j__default.resolve(e.cwd,e.registryFile),outputDir:j__default.resolve(e.cwd,e.outputDir)};if(!S.existsSync(r.registryFile))return t["13"]=true,{errors:t,resolvePaths:null,config:null};if(!S.existsSync(j__default.resolve(e.cwd,"components.json")))return t["3"]=true,{errors:t,resolvePaths:null,config:null};await S.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)}.
|
|
87
|
-
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 Un=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),_r=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 Gn({cwd:j.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function Gn(e){try{let t$1=Un.parse(e),[{errors:r,resolvePaths:i,config:n},o$1]=await Promise.all([Dr(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 J.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..."),m=await Jn(s$1.data,n,o$1);for(let l of m.items)l.files=l.files?.filter((p,u,h)=>u===h.findIndex(g=>g.path===p.path)),l.dependencies&&(l.dependencies=l.dependencies.filter((p,u,h)=>u===h.findIndex(g=>g===p)));for(let l of m.items){if(!l.files)continue;c.start(`Building ${l.name}...`),l.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let u of l.files){let h=j.resolve(i.cwd,u.path);try{if(!(await J.stat(h)).isFile())continue;u.content=await J.readFile(h,"utf-8");}catch(g){console.error("Error reading file in registry build:",h,g);continue}}let p=n$1.safeParse(l);if(!p.success){s.error(`Invalid registry item found for ${d.info(l.name)}.`);continue}await J.writeFile(j.resolve(i.outputDir,`${p.data.name}.json`),JSON.stringify(p.data,null,2));}if(await J.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t$1.verbose){t(`The registry has ${d.info(m.items.length.toString())} items:`).succeed();for(let l of m.items){s.log(` - ${l.name} (${d.info(l.type)})`);for(let p of l.files??[])s.log(` - ${p.path}`);}}}catch(t){s.break(),Y(t);}}async function Jn(e,t,r){for(let i of e.items)if(i.files?.length)for(let n of i.files){let o=await L(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 Lr=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 qn=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),Wr=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=qn.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 z(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(S.existsSync(o)){let l=await S.readJson(o),p=c.partial().parse(l);n$1=O({...i$1,...p});}let a=n$1;try{let l=await i(r.cwd);l&&(a=O(l));}catch{}let{config:s,newRegistries:c$1}=await _(e.map(l=>`${l}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),Q(e,a);let m=await ma(e,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(m,null,2)),process.exit(0);}catch(r){Y(r);}finally{P();}});var Xn=z$1.object({cwd:z$1.string()}),Gr=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=Xn.parse({cwd:j__default.resolve(t.cwd)});await z(r.cwd);let i$1=O({}),n=j__default.resolve(r.cwd,"components.json");if(S.existsSync(n)){let m=await S.readJson(n),l=c.partial().parse(m);i$1=O(l);}let o=i$1;try{let m=await i(r.cwd);m&&(o=O(m));}catch{}let{config:a,newRegistries:s}=await _(e,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),Q(e,o);let c$1=await _$1(e,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){Y(r);}finally{P();}});var Jr={version:"3.6.
|
|
87
|
+
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 Un=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),_r=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 Gn({cwd:j.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function Gn(e){try{let t$1=Un.parse(e),[{errors:r,resolvePaths:i,config:n},o$1]=await Promise.all([Dr(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 J.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..."),m=await Jn(s$1.data,n,o$1);for(let l of m.items)l.files=l.files?.filter((p,u,h)=>u===h.findIndex(g=>g.path===p.path)),l.dependencies&&(l.dependencies=l.dependencies.filter((p,u,h)=>u===h.findIndex(g=>g===p)));for(let l of m.items){if(!l.files)continue;c.start(`Building ${l.name}...`),l.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let u of l.files){let h=j.resolve(i.cwd,u.path);try{if(!(await J.stat(h)).isFile())continue;u.content=await J.readFile(h,"utf-8");}catch(g){console.error("Error reading file in registry build:",h,g);continue}}let p=n$1.safeParse(l);if(!p.success){s.error(`Invalid registry item found for ${d.info(l.name)}.`);continue}await J.writeFile(j.resolve(i.outputDir,`${p.data.name}.json`),JSON.stringify(p.data,null,2));}if(await J.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t$1.verbose){t(`The registry has ${d.info(m.items.length.toString())} items:`).succeed();for(let l of m.items){s.log(` - ${l.name} (${d.info(l.type)})`);for(let p of l.files??[])s.log(` - ${p.path}`);}}}catch(t){s.break(),Y(t);}}async function Jn(e,t,r){for(let i of e.items)if(i.files?.length)for(let n of i.files){let o=await L(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 Lr=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 qn=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),Wr=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=qn.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 z(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(S.existsSync(o)){let l=await S.readJson(o),p=c.partial().parse(l);n$1=O({...i$1,...p});}let a=n$1;try{let l=await i(r.cwd);l&&(a=O(l));}catch{}let{config:s,newRegistries:c$1}=await _(e.map(l=>`${l}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),Q(e,a);let m=await ma(e,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(m,null,2)),process.exit(0);}catch(r){Y(r);}finally{P();}});var Xn=z$1.object({cwd:z$1.string()}),Gr=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=Xn.parse({cwd:j__default.resolve(t.cwd)});await z(r.cwd);let i$1=O({}),n=j__default.resolve(r.cwd,"components.json");if(S.existsSync(n)){let m=await S.readJson(n),l=c.partial().parse(m);i$1=O(l);}let o=i$1;try{let m=await i(r.cwd);m&&(o=O(m));}catch{}let{config:a,newRegistries:s}=await _(e,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),Q(e,o);let c$1=await _$1(e,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){Y(r);}finally{P();}});var Jr={version:"3.6.17"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function eo(){let e=new Command().name("shadcn").description("add items from registries to your project").version(Jr.version,"-v, --version","display the version number");e.addCommand(mr).addCommand(vr).addCommand(ur).addCommand(Cr).addCommand(Gr).addCommand(Wr).addCommand(Ar).addCommand(Ir).addCommand(yr).addCommand(mt),e.addCommand(_r).addCommand(Lr),e.parse();}eo();//# sourceMappingURL=index.js.map
|
|
88
88
|
//# sourceMappingURL=index.js.map
|