shadcn 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {b as b$1,a as a$1}from'./chunk-E7NDCDPP.js';import {b,a,H as H$1,ra,ua,d,$,V,sa,N,O as O$1,x,e,fa,ha,L,M as M$1,J as J$1,K,ta,T,ba,I,f,ea as ea$1,ka,ia,la,C,S,ma,U,W as W$1,va,_ as _$1,X,na,P,ga,qa,c as c$1,r,Z,l,R,Y as Y$1,Q as Q$1,E,F,G,t,y,z as z$2,B,D,A,s,u,w,v}from'./chunk-IFVYASFF.js';export{ka as fetchTree,la as getItemTargetPath,pa as getPreset,oa as getPresets,ma as getRegistries,da as getRegistriesConfig,na as getRegistriesIndex,aa as getRegistry,ia as getRegistryBaseColor,ha as getRegistryBaseColors,ga as getRegistryIcons,ba as getRegistryItems,fa as getRegistryStyles,ea as getShadcnRegistryIndex,ca as resolveRegistryItems,ja as resolveTree}from'./chunk-IFVYASFF.js';import {c,o as o$1,n as n$1}from'./chunk-FFSLICO3.js';import {
|
|
2
|
+
import {b as b$1,a as a$1}from'./chunk-E7NDCDPP.js';import {o,n}from'./chunk-K3VKXMEA.js';import {b,a,H as H$1,ra,ua,d,$,V,sa,N,O as O$1,x,e,fa,ha,L,M as M$1,J as J$1,K,ta,T,ba,I,f,ea as ea$1,ka,ia,la,C,S,ma,U,W as W$1,va,_ as _$1,X,na,P,ga,qa,c as c$1,r,Z,l,R,Y as Y$1,Q as Q$1,E,F,G,t,y,z as z$2,B,D,A,s,u,w,v}from'./chunk-IFVYASFF.js';export{ka as fetchTree,la as getItemTargetPath,pa as getPreset,oa as getPresets,ma as getRegistries,da as getRegistriesConfig,na as getRegistriesIndex,aa as getRegistry,ia as getRegistryBaseColor,ha as getRegistryBaseColors,ga as getRegistryIcons,ba as getRegistryItems,fa as getRegistryStyles,ea as getShadcnRegistryIndex,ca as resolveRegistryItems,ja as resolveTree}from'./chunk-IFVYASFF.js';import {c,o as o$1,n as n$1}from'./chunk-FFSLICO3.js';import {e as e$1,a as a$3,c as c$2,f as f$1,d as d$1}from'./chunk-IMJ4D25X.js';import {a as a$2}from'./chunk-CHWMSXYA.js';import*as Q from'path';import Q__default,{join}from'path';import {promises,existsSync}from'fs';import Zt from'fast-glob';import z$1 from'fs-extra';import So from'open';import ae from'prompts';import cn from'dedent';import $o,{tmpdir}from'os';import {execa}from'execa';import $$1 from'postcss';import jo from'postcss/lib/at-rule';import Kt,{z}from'zod';import {twMerge}from'tailwind-merge';import {Project,ScriptKind,SyntaxKind,VariableDeclarationKind}from'ts-morph';import an from'deepmerge';import {Command}from'commander';import {diffLines,structuredPatch,diffWords}from'diff';import {dim,yellow,bold,green,cyan,red}from'kleur/colors';import*as xe from'fs/promises';import xe__default from'fs/promises';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import {randomBytes}from'crypto';var bo=["next.config.*","vite.config.*","astro.config.*","remix.config.*","nuxt.config.*","svelte.config.*","gatsby-config.*","angular.json"];async function J(e){if(z$1.existsSync(Q__default.resolve(e,"pnpm-workspace.yaml")))return true;let t=Q__default.resolve(e,"package.json");if(z$1.existsSync(t))try{if((await z$1.readJson(t)).workspaces)return !0}catch{}return !!(z$1.existsSync(Q__default.resolve(e,"lerna.json"))||z$1.existsSync(Q__default.resolve(e,"nx.json")))}async function H(e){let t=await xo(e);if(!t.length)return [];let r=await Zt(t,{cwd:e,onlyDirectories:true,ignore:["**/node_modules/**"]}),n=[];for(let i of r){let o=Q__default.resolve(e,i);if(!z$1.existsSync(Q__default.resolve(o,"package.json")))continue;let s=z$1.existsSync(Q__default.resolve(o,"components.json")),c=bo.some(a=>Zt.sync(a,{cwd:o,dot:true}).length>0);(s||c)&&n.push({name:i,hasConfig:s});}return n}function Y(e,t){b.break(),b.log(`It looks like you are running ${a.info(e)} from a monorepo root.`),b.log(`To use shadcn in a specific workspace, use the ${a.info("-c")} flag:`),b.break();for(let r of t)b.log(` shadcn ${e} -c ${r.name}`);b.break();}async function xo(e){let t=[],r=Q__default.resolve(e,"pnpm-workspace.yaml");if(z$1.existsSync(r)){let i=await z$1.readFile(r,"utf8"),o=Array.from(i.matchAll(/^\s*-\s*["']?([^"'\n#]+)["']?\s*$/gm));for(let s of o)t.push(s[1].trim());}let n=Q__default.resolve(e,"package.json");if(z$1.existsSync(n))try{let i=await z$1.readJson(n),o=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;Array.isArray(o)&&t.push(...o.filter(s=>!s.startsWith("!")));}catch{}return Array.from(new Set(t))}async function Gr(e){let t={};if(!z$1.existsSync(e.cwd)||!z$1.existsSync(Q__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,projectInfo:null};let r=x("Preflight checks.",{silent:e.silent}).start();z$1.existsSync(Q__default.resolve(e.cwd,"components.json"))&&!e.force&&(r?.fail(),b.break(),b.error(`A ${a.info("components.json")} file already exists at ${a.info(e.cwd)}.
|
|
3
3
|
To start over, remove the ${a.info("components.json")} file and run ${a.info("init")} again.`),b.break(),process.exit(1)),r?.succeed();let n=x("Verifying framework.",{silent:e.silent}).start(),i=e.existingConfig?.tailwind,o=await ra(e.cwd,{configCssFile:typeof i?.css=="string"?i.css:void 0});if(!o||o?.framework.name==="manual"){if(t["7"]=true,n?.fail(),!e.monorepo&&await J(e.cwd)){let f=await H(e.cwd);f.length>0&&(Y("init",f),process.exit(1));}b.break(),o?.framework.links.installation&&b.error(`We could not detect a supported framework at ${a.info(e.cwd)}.
|
|
4
4
|
Visit ${a.info(o?.framework.links.installation)} to manually configure your project.
|
|
5
5
|
Once configured, you can use the cli to add components.`),b.break(),process.exit(1);}n?.succeed(`Verifying framework. Found ${a.info(o.framework.label)}.`);let s="Validating Tailwind CSS.";o.tailwindVersion==="v4"&&(s=`Validating Tailwind CSS. Found ${a.info("v4")}.`);let c=x(s,{silent:e.silent}).start();o.tailwindVersion==="v3"&&(!o?.tailwindConfigFile||!o?.tailwindCssFile)?(t["5"]=true,c?.fail()):o.tailwindVersion==="v4"&&!o?.tailwindCssFile?(t["5"]=true,c?.fail()):o.tailwindVersion?c?.succeed():(t["5"]=true,c?.fail());let a$1=x("Validating import alias.",{silent:e.silent}).start();return o?.aliasPrefix?a$1?.succeed():(t["6"]=true,a$1?.fail()),Object.keys(t).length>0&&(t["5"]&&(b.break(),b.error(`No Tailwind CSS configuration found at ${a.info(e.cwd)}.`),b.error("It is likely you do not have Tailwind CSS installed or have an invalid configuration."),b.error("Install Tailwind CSS then try again."),o?.framework.links.tailwind&&b.error(`Visit ${a.info(o?.framework.links.tailwind)} to get started.`)),t["6"]&&(b.break(),b.error("No import alias found in your tsconfig.json file."),o?.framework.links.installation&&b.error(`Visit ${a.info(o?.framework.links.installation)} to learn how to set an import alias.`)),b.break(),process.exit(1)),{errors:t,projectInfo:o}}async function Jr(e$1,t){let r$1=new Set,n=new Set,i=[...e$1];for(;i.length>0;){let o=i.shift();if(n.has(o))continue;n.add(o);let{registry:s}=r(o);s&&!e[s]&&r$1.add(s);try{let[c]=await Z([o],t,{useCache:!0});if(c?.registryDependencies)for(let a of c.registryDependencies){let{registry:f}=r(a);f&&!e[f]&&r$1.add(f),n.has(a)||i.push(a);}}catch(c){if(c instanceof l){let{registry:a}=r(o);a&&!e[a]&&r$1.add(a);continue}continue}}return Array.from(r$1)}async function _(e$1,t,r={}){r={silent:false,writeFile:true,...r};let i=(await Jr(e$1,t)).filter(f=>!t.registries?.[f]&&!Object.keys(e).includes(f));if(i.length===0)return {config:t,newRegistries:[]};let o=await na({useCache:process.env.NODE_ENV!=="development"});if(!o)return {config:t,newRegistries:[]};let s={};for(let f of i)o[f]&&(s[f]=o[f]);if(Object.keys(s).length===0)return {config:t,newRegistries:[]};let c$1=Object.fromEntries(Object.entries(t.registries||{}).filter(([f])=>!Object.keys(e).includes(f))),a={...t,registries:{...c$1,...s}};if(r.writeFile){let{resolvedPaths:f,...l}=a,m=x("Updating components.json.",{silent:r.silent}).start(),d=c.parse(l);await z$1.writeFile(Q__default.resolve(t.resolvedPaths.cwd,"components.json"),JSON.stringify(d,null,2)+`
|
|
@@ -155,4 +155,4 @@ args = ["shadcn@${ve}", "mcp"]`),b.break(),b.info("3. Restart Codex to load the
|
|
|
155
155
|
`).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,(C,k,S)=>{let j=S.substring(0,k),fe=(j.match(/"/g)||[]).length,pe=(j.match(/'/g)||[]).length;return fe%2!==0||pe%2!==0?C:"__SLOT_PLACEHOLDER__"}),v=v.replace(/__SLOT_PLACEHOLDER__/g,"SlotPrimitive.Slot"),v}).join(`
|
|
156
156
|
`));let h=Array.from(new Set(i));return {content:c,replacedPackages:h}}var Ds=["sidebar.tsx","pagination.tsx","calendar.tsx"],_s=`${d}/docs/rtl#manual-migration-optional`;async function ro(e,t={}){let r,n;if(t.path){if(n=e.resolvedPaths.cwd,t.path.includes("*"))r=await Zt(t.path,{cwd:n,onlyFiles:true,ignore:["**/node_modules/**"]});else {let f=Q__default.resolve(n,t.path),l=await promises.stat(f).catch(()=>null);if(!l)throw new Error(`File not found: ${t.path}`);if(l.isDirectory())n=f,r=await Zt("**/*.{js,ts,jsx,tsx}",{cwd:n,onlyFiles:true,ignore:["**/node_modules/**"]});else if(l.isFile())r=[t.path];else throw new Error(`Unsupported path type: ${t.path}`)}if(r.length===0)throw new Error(`No files found matching: ${t.path}`)}else {if(!e.resolvedPaths.ui)throw new Error("Could not find a valid `ui` path in your `components.json`. Please provide a path or glob pattern.");n=e.resolvedPaths.ui,r=await Zt("**/*.{js,ts,jsx,tsx}",{cwd:n,onlyFiles:true});}if(!t.yes){let a$1=t.path?t.path:`./${Q__default.relative(e.resolvedPaths.cwd,n)}`,{confirm:f}=await ae({type:"confirm",name:"confirm",initial:true,message:`We will migrate ${a.info(r.length)} file(s) in ${a.info(a$1)} to RTL. Continue?`});f||(b.info("Migration cancelled."),process.exit(0));}let i=x("Updating components.json...").start();try{let a=Q__default.resolve(e.resolvedPaths.cwd,"components.json"),f=JSON.parse(await promises.readFile(a,"utf-8"));f.rtl=!0,await promises.writeFile(a,JSON.stringify(f,null,2)+`
|
|
157
157
|
`),i.succeed("Updated components.json.");}catch{throw i.fail("Failed to update components.json."),new Error("Could not update components.json. Please manually set `rtl: true`.")}let o=x("Migrating files to RTL...").start(),s=0,c=[];if(await Promise.all(r.map(async a=>{o.text=`Migrating ${a}...`;let f=Q__default.join(n,a),l=await promises.readFile(f,"utf-8"),m=await e$1(l,true);m!==l&&(await promises.writeFile(f,m),s++);let d=Q__default.basename(a);Ds.includes(d)&&c.push(a);})),o.succeed(`Migration complete. ${s} file(s) transformed.`),c.length>0){b.break(),b.warn("The following components may need manual RTL adjustments:");for(let a of c)b.info(` - ${a}`);b.break(),b.info(`See ${a.info(_s)} for more information.`);}}async function oo(e){let t={};if(!z$1.existsSync(e.cwd)||!z$1.existsSync(Q__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,config:null};if(!z$1.existsSync(Q__default.resolve(e.cwd,"components.json")))return t["3"]=true,{errors:t,config:null};try{let r=await N(e.cwd);return {errors:t,config:r}}catch{b.break(),b.error(`An invalid ${a.info("components.json")} file was found at ${a.info(e.cwd)}.
|
|
158
|
-
Before you can run a migration, you must create a valid ${a.info("components.json")} file by running the ${a.info("init")} command.`),b.error(`Learn more at ${a.info(`${d}/docs/components-json`)}.`),b.break(),process.exit(1);}}var io=[{name:"icons",description:"migrate your ui components to a different icon library."},{name:"radix",description:"migrate to radix-ui."},{name:"rtl",description:"migrate your components to support RTL (right-to-left)."}],Ms=z.object({cwd:z.string(),list:z.boolean(),yes:z.boolean(),migration:z.string().refine(e=>e&&io.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional(),path:z.string().optional()}),so=new Command().name("migrate").description("run a migration.").argument("[migration]","the migration to run.").argument("[path]","optional path or glob pattern to migrate.").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,r)=>{try{let n=Ms.parse({cwd:Q__default.resolve(r.cwd),migration:e,path:t,list:r.list,yes:r.yes});if(n.list||!n.migration){b.info("Available migrations:");for(let s of io)b.info(`- ${s.name}: ${s.description}`);return}if(!n.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:i,config:o}=await oo(n);if(i["1"]||i["3"])throw new Error("No `components.json` file found. Ensure you are at the root of your project.");if(!o)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");n.migration==="icons"&&await eo(o),n.migration==="radix"&&await to(o,{yes:n.yes,path:n.path}),n.migration==="rtl"&&await ro(o,{yes:n.yes,path:n.path});}catch(n){b.break(),$(n);}});var zs=z.object({cwd:z.string(),silent:z.boolean()}),co=new Command().name("add").description("add registries to your project").argument("[registries...]","registries (@namespace) or registry URLs (@namespace=url)").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",false).action(async(e,t)=>{try{let r=zs.parse({cwd:Q__default.resolve(t.cwd),silent:t.silent}),n=e.length>0?e:await Js({silent:r.silent});await Gs(n,r.cwd,{silent:r.silent});}catch(r){b.break(),$(r);}});function Bs(e){let[t,...r]=e.split("="),n=r.length>0?r.join("="):void 0;if(!t.startsWith("@"))throw new Error(`Invalid registry namespace: ${a.info(t)}. Registry names must start with @ (e.g., @acme).`);return {namespace:t,url:n}}function nr(e,t,r){return `${e} ${e===1?t:r}`}async function Gs(e$1,t,r){let n=Q__default.resolve(t,"components.json");if(!z$1.existsSync(n))throw new Error(`No ${a.info("components.json")} found. Run ${a.info("shadcn init")} first.`);let i=e$1.map(Bs),o=i.filter(g=>!g.url),s=[];if(o.length>0){let g=x("Fetching registries.",{silent:r.silent}).start(),w=await ma();if(!w)throw g.fail(),new Error("Failed to fetch registries.");g.succeed(),s=w;}let c={};for(let{namespace:g,url:w}of i){if(g in e){b.warn(`${a.info(g)} is a built-in registry and cannot be added.`);continue}if(w){if(!w.includes("{name}"))throw new Error(`Invalid registry URL for ${a.info(g)}. URL must include {name} placeholder. Example: ${a.info(`${g}=https://example.com/r/{name}.json`)}`);c[g]=w;}else {let x=s.find(v=>v.name===g);if(!x)throw new Error(`Registry ${a.info(g)} not found. Provide a URL: ${a.info(`${g}=https://.../{name}.json`)}`);c[g]=x.url;}}if(Object.keys(c).length===0)return {addedRegistries:[]};let a$1=await z$1.readJson(n),f=a$1.registries||{},l={},m=[];for(let[g,w]of Object.entries(c))f[g]?m.push(g):l[g]=w;if(Object.keys(l).length===0){if(m.length>0&&!r.silent){x(`Skipped ${nr(m.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let g of m)b.log(` - ${g}`);}else r.silent||b.info("No new registries to add.");return}let d={...a$1,registries:{...f,...l}},h=x("Updating components.json.",{silent:r.silent}).start();if(await z$1.writeJson(n,d,{spaces:2}),h.succeed(),!r.silent){let g=Object.keys(l);x(`Added ${nr(g.length,"registry","registries")}:`,{silent:r.silent})?.succeed();for(let w of g)b.log(` - ${w}`);if(m.length>0){x(`Skipped ${nr(m.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let w of m)b.log(` - ${w}`);}}}async function Js(e){let t=x("Fetching registries.",{silent:e.silent}).start(),r=await ma();if(!r)throw t.fail(),new Error("Failed to fetch registries.");t.succeed();let n=[...r].sort((o,s)=>o.name.localeCompare(s.name)),{selected:i}=await ae({type:"autocompleteMultiselect",name:"selected",message:"Which registries would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:false,choices:n.map(o=>({title:o.name,description:o.description,value:o.name}))});return i?.length||(b.warn("No registries selected. Exiting."),b.info(""),process.exit(1)),i}var lo=new Command().name("registry").description("manage registries").addCommand(co);var Ks=z.object({cwd:z.string(),query:z.string().optional(),limit:z.number().optional(),offset:z.number().optional()}),mo=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=Ks.parse({cwd:Q__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 q(r.cwd);let n=T({style:"new-york",resolvedPaths:{cwd:r.cwd}}),i=U(n),o=Q__default.resolve(r.cwd,"components.json");if(z$1.existsSync(o)){let l=await z$1.readJson(o),m=c.partial().parse(l);i=U({...n,...m});}let s=i;try{let l=await N(r.cwd);l&&(s=U(l));}catch{}let{config:c$1,newRegistries:a}=await _(e.map(l=>`${l}/registry`),s,{silent:!0,writeFile:!1});a.length>0&&(s.registries=c$1.registries),W$1(e,s);let f=await va(e,{query:r.query,limit:r.limit,offset:r.offset,config:s});console.log(JSON.stringify(f,null,2)),process.exit(0);}catch(r){$(r);}finally{V();}});var Xs=z.object({cwd:z.string()}),yo=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=Xs.parse({cwd:Q__default.resolve(t.cwd)});await q(r.cwd);let n=U({}),i=Q__default.resolve(r.cwd,"components.json");if(z$1.existsSync(i)){let f=await z$1.readJson(i),l=c.partial().parse(f);n=U(l);}let o=n;try{let f=await N(r.cwd);f&&(o=U(f));}catch{}let{config:s,newRegistries:c$1}=await _(e,o,{silent:!0,writeFile:!1});c$1.length>0&&(o.registries=s.registries),W$1(e,o);let a=await ba(e,{config:o});console.log(JSON.stringify(a,null,2)),process.exit(0);}catch(r){$(r);}finally{V();}});var wo={version:"4.0.
|
|
158
|
+
Before you can run a migration, you must create a valid ${a.info("components.json")} file by running the ${a.info("init")} command.`),b.error(`Learn more at ${a.info(`${d}/docs/components-json`)}.`),b.break(),process.exit(1);}}var io=[{name:"icons",description:"migrate your ui components to a different icon library."},{name:"radix",description:"migrate to radix-ui."},{name:"rtl",description:"migrate your components to support RTL (right-to-left)."}],Ms=z.object({cwd:z.string(),list:z.boolean(),yes:z.boolean(),migration:z.string().refine(e=>e&&io.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional(),path:z.string().optional()}),so=new Command().name("migrate").description("run a migration.").argument("[migration]","the migration to run.").argument("[path]","optional path or glob pattern to migrate.").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,r)=>{try{let n=Ms.parse({cwd:Q__default.resolve(r.cwd),migration:e,path:t,list:r.list,yes:r.yes});if(n.list||!n.migration){b.info("Available migrations:");for(let s of io)b.info(`- ${s.name}: ${s.description}`);return}if(!n.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:i,config:o}=await oo(n);if(i["1"]||i["3"])throw new Error("No `components.json` file found. Ensure you are at the root of your project.");if(!o)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");n.migration==="icons"&&await eo(o),n.migration==="radix"&&await to(o,{yes:n.yes,path:n.path}),n.migration==="rtl"&&await ro(o,{yes:n.yes,path:n.path});}catch(n){b.break(),$(n);}});var zs=z.object({cwd:z.string(),silent:z.boolean()}),co=new Command().name("add").description("add registries to your project").argument("[registries...]","registries (@namespace) or registry URLs (@namespace=url)").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",false).action(async(e,t)=>{try{let r=zs.parse({cwd:Q__default.resolve(t.cwd),silent:t.silent}),n=e.length>0?e:await Js({silent:r.silent});await Gs(n,r.cwd,{silent:r.silent});}catch(r){b.break(),$(r);}});function Bs(e){let[t,...r]=e.split("="),n=r.length>0?r.join("="):void 0;if(!t.startsWith("@"))throw new Error(`Invalid registry namespace: ${a.info(t)}. Registry names must start with @ (e.g., @acme).`);return {namespace:t,url:n}}function nr(e,t,r){return `${e} ${e===1?t:r}`}async function Gs(e$1,t,r){let n=Q__default.resolve(t,"components.json");if(!z$1.existsSync(n))throw new Error(`No ${a.info("components.json")} found. Run ${a.info("shadcn init")} first.`);let i=e$1.map(Bs),o=i.filter(g=>!g.url),s=[];if(o.length>0){let g=x("Fetching registries.",{silent:r.silent}).start(),w=await ma();if(!w)throw g.fail(),new Error("Failed to fetch registries.");g.succeed(),s=w;}let c={};for(let{namespace:g,url:w}of i){if(g in e){b.warn(`${a.info(g)} is a built-in registry and cannot be added.`);continue}if(w){if(!w.includes("{name}"))throw new Error(`Invalid registry URL for ${a.info(g)}. URL must include {name} placeholder. Example: ${a.info(`${g}=https://example.com/r/{name}.json`)}`);c[g]=w;}else {let x=s.find(v=>v.name===g);if(!x)throw new Error(`Registry ${a.info(g)} not found. Provide a URL: ${a.info(`${g}=https://.../{name}.json`)}`);c[g]=x.url;}}if(Object.keys(c).length===0)return {addedRegistries:[]};let a$1=await z$1.readJson(n),f=a$1.registries||{},l={},m=[];for(let[g,w]of Object.entries(c))f[g]?m.push(g):l[g]=w;if(Object.keys(l).length===0){if(m.length>0&&!r.silent){x(`Skipped ${nr(m.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let g of m)b.log(` - ${g}`);}else r.silent||b.info("No new registries to add.");return}let d={...a$1,registries:{...f,...l}},h=x("Updating components.json.",{silent:r.silent}).start();if(await z$1.writeJson(n,d,{spaces:2}),h.succeed(),!r.silent){let g=Object.keys(l);x(`Added ${nr(g.length,"registry","registries")}:`,{silent:r.silent})?.succeed();for(let w of g)b.log(` - ${w}`);if(m.length>0){x(`Skipped ${nr(m.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let w of m)b.log(` - ${w}`);}}}async function Js(e){let t=x("Fetching registries.",{silent:e.silent}).start(),r=await ma();if(!r)throw t.fail(),new Error("Failed to fetch registries.");t.succeed();let n=[...r].sort((o,s)=>o.name.localeCompare(s.name)),{selected:i}=await ae({type:"autocompleteMultiselect",name:"selected",message:"Which registries would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:false,choices:n.map(o=>({title:o.name,description:o.description,value:o.name}))});return i?.length||(b.warn("No registries selected. Exiting."),b.info(""),process.exit(1)),i}var lo=new Command().name("registry").description("manage registries").addCommand(co);var Ks=z.object({cwd:z.string(),query:z.string().optional(),limit:z.number().optional(),offset:z.number().optional()}),mo=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=Ks.parse({cwd:Q__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 q(r.cwd);let n=T({style:"new-york",resolvedPaths:{cwd:r.cwd}}),i=U(n),o=Q__default.resolve(r.cwd,"components.json");if(z$1.existsSync(o)){let l=await z$1.readJson(o),m=c.partial().parse(l);i=U({...n,...m});}let s=i;try{let l=await N(r.cwd);l&&(s=U(l));}catch{}let{config:c$1,newRegistries:a}=await _(e.map(l=>`${l}/registry`),s,{silent:!0,writeFile:!1});a.length>0&&(s.registries=c$1.registries),W$1(e,s);let f=await va(e,{query:r.query,limit:r.limit,offset:r.offset,config:s});console.log(JSON.stringify(f,null,2)),process.exit(0);}catch(r){$(r);}finally{V();}});var Xs=z.object({cwd:z.string()}),yo=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=Xs.parse({cwd:Q__default.resolve(t.cwd)});await q(r.cwd);let n=U({}),i=Q__default.resolve(r.cwd,"components.json");if(z$1.existsSync(i)){let f=await z$1.readJson(i),l=c.partial().parse(f);n=U(l);}let o=n;try{let f=await N(r.cwd);f&&(o=U(f));}catch{}let{config:s,newRegistries:c$1}=await _(e,o,{silent:!0,writeFile:!1});c$1.length>0&&(o.registries=s.registries),W$1(e,o);let a=await ba(e,{config:o});console.log(JSON.stringify(a,null,2)),process.exit(0);}catch(r){$(r);}finally{V();}});var wo={version:"4.0.1"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function ea(){let e=new Command().name("shadcn").description("build your component library").version(wo.version,"-v, --version","display the version number");e.addCommand(Sn).addCommand(Ln).addCommand(Gn).addCommand(Jn).addCommand(yo).addCommand(mo).addCommand(so).addCommand(Kn).addCommand(zn).addCommand(qt).addCommand(lo),e.parse();}ea();
|