hghcn 3.6.31 → 3.6.32
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 +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39,10 +39,10 @@ Some packages may fail to install due to peer dependency issues in npm (see http
|
|
|
39
39
|
`);let s=await je([{type:"select",name:"flag",message:"How would you like to proceed?",choices:[{title:"Use --force",value:"force"},{title:"Use --legacy-peer-deps",value:"legacy-peer-deps"}]}]);s&&(a=s.flag);}n$1?.start(),await Xr(o,e,t,r.resolvedPaths.cwd,a),n$1?.succeed();}function qr(e){let t=k(e.resolvedPaths.cwd,false);if(!t?.dependencies?.react)return false;let r=/^(?:\^|~)?19(?:\.\d+)*(?:-.*)?$/.test(t.dependencies.react),i=t.dependencies["react-day-picker"]?.startsWith("8");return r&&i}async function Hr(e){return k(e.resolvedPaths.cwd,false)?.dependencies?.expo?"expo":a$1(e.resolvedPaths.cwd)}async function Xr(e,t,r,i,n){if(e==="npm")return Zr(t,r,i,n);if(e==="deno")return Qr(t,r,i);if(e==="expo")return ei(t,r,i);t?.length&&await execa(e,["add",...t],{cwd:i}),r?.length&&await execa(e,["add","-D",...r],{cwd:i});}async function Zr(e,t,r,i){e.length&&await execa("npm",["install",...i?[`--${i}`]:[],...e],{cwd:r}),t.length&&await execa("npm",["install",...i?[`--${i}`]:[],"-D",...t],{cwd:r});}async function Qr(e,t,r){e?.length&&await execa("deno",["add",...e.map(i=>`npm:${i}`)],{cwd:r}),t?.length&&await execa("deno",["add","-D",...t.map(i=>`npm:${i}`)],{cwd:r});}async function ei(e,t,r){e.length&&await execa("npx",["expo","install",...e],{cwd:r}),t.length&&await execa("npx",["expo","install","-- -D",...t],{cwd:r});}async function _t(e,t,r){if(!e||Object.keys(e).length===0)return {envVarsAdded:[],envFileUpdated:null,envFileCreated:null};r={silent:false,...r};let i=o$1("Adding environment variables.",{silent:r.silent})?.start(),n$1=t.resolvedPaths.cwd,o=j__default.join(n$1,".env.local"),a=B(n$1);a&&(o=a);let s=existsSync(o),c=j__default.basename(o),m=Object.entries(e).map(([g,h])=>`${g}=${h}`).join(`
|
|
40
40
|
`),l=[],f=null,d$1=null;if(s){let g=await promises.readFile(o,"utf-8"),h=D(g,m);if(l=C(g,m),l.length>0){if(await promises.writeFile(o,h,"utf-8"),f=j__default.relative(n$1,o),i?.succeed(`Added the following variables to ${d.info(c)}:`),!r.silent)for(let y of l)n.log(` ${d.success("+")} ${y}`);}else i?.stop();}else if(await promises.writeFile(o,m+`
|
|
41
41
|
`,"utf-8"),d$1=j__default.relative(n$1,o),l=Object.keys(e),i?.succeed(`Added the following variables to ${d.info(c)}:`),!r.silent)for(let g of l)n.log(` ${d.success("+")} ${g}`);return !r.silent&&l.length>0&&n.break(),{envVarsAdded:l,envFileUpdated:f,envFileCreated:d$1}}async function Vt(e,t,r){if(!e?.length)return;let i=await l(t.resolvedPaths.cwd);if(!i||i.framework.name!=="next-app"&&i.framework.name!=="next-pages")return;let n=o$1("Updating fonts.",{silent:r.silent})?.start();try{await ai(e,t,i),n?.succeed("Updating fonts.");}catch(o){throw n?.fail("Failed to update fonts."),o}}async function ai(e,t,r){let i=await ci(t,r);if(!i)return;let n=await promises.readFile(i,"utf-8"),o=await li(n,e);o!==n&&await promises.writeFile(i,o,"utf-8");}async function ci(e,t){let r=e.resolvedPaths.cwd,i=t.isSrcDir,o=t.isTsx?"tsx":"jsx",a=i?[`src/app/layout.${o}`,`app/layout.${o}`]:[`app/layout.${o}`];for(let s of a){let c=j__default.join(r,s);if(existsSync(c))return c}return null}async function li(e,t,r){let n=new Project({compilerOptions:{}}).createSourceFile("layout.tsx",e,{scriptKind:ScriptKind.TSX}),o=t.filter(s=>s.font.provider==="google"),a=[];for(let s of o){let c=s.font.import;if(!c)continue;let m=pi(c),l=n.getImportDeclaration(g=>g.getModuleSpecifierValue()==="next/font/google"),f=mi(s);l?l.getNamedImports().some(y=>y.getName()===c)||l.addNamedImport(c):n.addImportDeclaration({moduleSpecifier:"next/font/google",namedImports:[c]});let d=fi(n,s.font.variable);if(d)d.setInitializer(`${c}(${f})`),d.getName()!==m&&d.rename(m);else {let g=di(n);n.insertVariableStatement(g,{declarationKind:VariableDeclarationKind.Const,declarations:[{name:m,initializer:`${c}(${f})`}]}).appendWhitespace(`
|
|
42
|
-
`);}a.push(m);}return a.length>0&&ui(n,a),n.getFullText()}function mi(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 fi(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 di(e){let t=e.getImportDeclarations();return t.length>0?t[t.length-1].getChildIndex()+1:0}function ui(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 m=t.map(l=>`${l}.variable`).join(", ");t.length===1?i.addAttribute({name:"className",initializer:`{${m}}`}):(fe(e),i.addAttribute({name:"className",initializer:`{cn(${m})}`}));return}if(o.getKind()!==SyntaxKind.JsxAttribute)return;let a=o.asKindOrThrow(SyntaxKind.JsxAttribute),s=a.getInitializer();if(!s)return;let c=t.map(m=>`${m}.variable`);if(s.getKind()===SyntaxKind.StringLiteral){let m=s.getText().slice(1,-1);fe(e),a.setInitializer(`{cn("${m}", ${c.join(", ")})}`);}else if(s.getKind()===SyntaxKind.JsxExpression){let m=s.asKindOrThrow(SyntaxKind.JsxExpression),l=m.getExpression();if(!l)return;let f=l.getText();if(f.startsWith("cn(")){if(c.every(y=>f.includes(y)))continue;let g=hi(f),h=yi(g,c);m.replaceWithText(`{${h}}`);}else if(/^\w+\.variable$/.test(f)){if(c.includes(f))continue;c.length===1?m.replaceWithText(`{${c[0]}}`):(fe(e),m.replaceWithText(`{cn(${c.join(", ")})}`));}else if(f.startsWith("`")&&f.endsWith("`")){let d=gi(f);fe(e),m.replaceWithText(`{cn(${[...d,...c].join(", ")})}`);}else fe(e),m.replaceWithText(`{cn(${f}, ${c.join(", ")})}`);}}}function fe(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 gi(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 hi(e){return e.replace(/,?\s*\w+\.variable/g,"").replace(/cn\(\s*,/,"cn(")}function yi(e,t){let r=t.join(", ");return e.replace(/\)$/,`, ${r})`)}async function se(e,t,r){r={overwrite:false,silent:false,isNewProject:false,baseStyle:true,...r};let i=await g(t);return i&&i.ui&&i.ui.resolvedPaths.cwd!==t.resolvedPaths.cwd?await xi(e,t,i,{...r,isRemote:e?.length===1&&!!e[0].match(/\/chat\/b\//)}):await bi(e,t,r)}async function bi(e,t,r){if(!r.baseStyle&&!e.length)return;let i=o$1("Checking registry.",{silent:r.silent})?.start(),n$1=await Q(e,J$1(t));if(!n$1)return i?.fail(),R(new Error("Failed to fetch components from registry."));try{Wt(n$1.files??[],t.resolvedPaths.cwd);}catch(o){return i?.fail(),R(o)}i?.succeed(),await L(n$1.dependencies,n$1.devDependencies,t,{silent:r.silent}),await F$1(n$1.files,t,{overwrite:r.overwrite,silent:r.silent,path:r.path}),n$1.docs&&n.info(n$1.docs);}async function xi(e,t,r,i$1){if(!i$1.baseStyle&&!e.length)return;let n$1=o$1("Checking registry.",{silent:i$1.silent})?.start(),o=await Q(e,J$1(t));if(!o)return n$1?.fail(),R(new Error("Failed to fetch components from registry."));try{Wt(o.files??[],t.resolvedPaths.cwd);}catch(y){return n$1?.fail(),R(y)}n$1?.succeed();let a=[],s=[],c=[],m$1=o$1("Installing components.")?.start(),l=r.ui,f=await m(l),d=i(t.resolvedPaths.cwd,l.resolvedPaths.ui);if(o.tailwind?.config&&(await O(o.tailwind?.config,l,{silent:true,tailwindVersion:f}),s.push(j__default.relative(d,l.resolvedPaths.tailwindConfig))),o.cssVars){let y=await vi(e,t);await At(o.cssVars,l,{silent:true,tailwindVersion:f,tailwindConfig:o.tailwind?.config,overwriteCssVars:y}),s.push(j__default.relative(d,l.resolvedPaths.tailwindCss));}o.css&&(await $t(o.css,l,{silent:true}),s.push(j__default.relative(d,l.resolvedPaths.tailwindCss))),o.envVars&&await _t(o.envVars,l,{silent:true}),await L(o.dependencies,o.devDependencies,l,{silent:true}),await Vt(o.fonts,l,{silent:true});let g=new Map;for(let y of o.files??[]){let I=y.type||"registry:ui";g.has(I)||g.set(I,[]),g.get(I).push(y);}for(let y of Array.from(g.keys())){let I=g.get(y),S=y==="registry:ui"?r.ui:t,B=i(t.resolvedPaths.cwd,S.resolvedPaths.ui||S.resolvedPaths.cwd),T=await h(B,S.resolvedPaths.cwd)??S.resolvedPaths.cwd,Y=await F$1(I,S,{overwrite:i$1.overwrite,silent:true,rootSpinner:m$1,isRemote:i$1.isRemote,isWorkspace:true,path:i$1.path});a.push(...Y.filesCreated.map(O=>j__default.relative(B,j__default.join(T,O)))),s.push(...Y.filesUpdated.map(O=>j__default.relative(B,j__default.join(T,O)))),c.push(...Y.filesSkipped.map(O=>j__default.relative(B,j__default.join(T,O))));}if(m$1?.succeed(),a.sort(),s.sort(),c.sort(),!(a.length||s.length)&&!c.length&&o$1("No files updated.",{silent:i$1.silent})?.info(),a.length){o$1(`Created ${a.length} ${a.length===1?"file":"files"}:`,{silent:i$1.silent})?.succeed();for(let y of a)n.log(` - ${y}`);}if(s.length){o$1(`Updated ${s.length} ${s.length===1?"file":"files"}:`,{silent:i$1.silent})?.info();for(let y of s)n.log(` - ${y}`);}if(c.length){o$1(`Skipped ${c.length} ${s.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:i$1.silent})?.info();for(let y of c)n.log(` - ${y}`);}o.docs&&n.info(o.docs);}async function vi(e,t){let r=await T(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 Wt(e,t){for(let r of e)if(r?.target&&!jt(r.target,t))throw new Error(`We found an unsafe file path "${r.target} in the registry item. Installation aborted.`)}var Be="https://codeload.github.com/shadcn-ui/ui/tar.gz/main",F={next:"next","next-monorepo":"next-monorepo",vite:"vite",start:"start"};async function Mt(e){e={srcDir:false,...e};let t=e.template&&F[e.template]?e.template:"next",r=e.name??(t===F.next||t===F.vite||t===F.start?"my-app":"my-monorepo"),i="latest",n$1=e.components?.length===1&&!!e.components[0].match(/\/chat\/b\//);if(e.components&&n$1)try{let[s]=await N(e.components),{meta:c}=z$1.object({meta:z$1.object({nextVersion:z$1.string()})}).parse(s);i=c.nextVersion,t=F.next;}catch(s){n.break(),R(s);}if(!e.force){let{type:s,name:c}=await je([{type:e.template||n$1?null:"select",name:"type",message:`The path ${d.info(e.cwd)} does not contain a package.json file.
|
|
42
|
+
`);}a.push(m);}return a.length>0&&ui(n,a),n.getFullText()}function mi(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 fi(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 di(e){let t=e.getImportDeclarations();return t.length>0?t[t.length-1].getChildIndex()+1:0}function ui(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 m=t.map(l=>`${l}.variable`).join(", ");t.length===1?i.addAttribute({name:"className",initializer:`{${m}}`}):(fe(e),i.addAttribute({name:"className",initializer:`{cn(${m})}`}));return}if(o.getKind()!==SyntaxKind.JsxAttribute)return;let a=o.asKindOrThrow(SyntaxKind.JsxAttribute),s=a.getInitializer();if(!s)return;let c=t.map(m=>`${m}.variable`);if(s.getKind()===SyntaxKind.StringLiteral){let m=s.getText().slice(1,-1);fe(e),a.setInitializer(`{cn("${m}", ${c.join(", ")})}`);}else if(s.getKind()===SyntaxKind.JsxExpression){let m=s.asKindOrThrow(SyntaxKind.JsxExpression),l=m.getExpression();if(!l)return;let f=l.getText();if(f.startsWith("cn(")){if(c.every(y=>f.includes(y)))continue;let g=hi(f),h=yi(g,c);m.replaceWithText(`{${h}}`);}else if(/^\w+\.variable$/.test(f)){if(c.includes(f))continue;c.length===1?m.replaceWithText(`{${c[0]}}`):(fe(e),m.replaceWithText(`{cn(${c.join(", ")})}`));}else if(f.startsWith("`")&&f.endsWith("`")){let d=gi(f);fe(e),m.replaceWithText(`{cn(${[...d,...c].join(", ")})}`);}else fe(e),m.replaceWithText(`{cn(${f}, ${c.join(", ")})}`);}}}function fe(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 gi(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 hi(e){return e.replace(/,?\s*\w+\.variable/g,"").replace(/cn\(\s*,/,"cn(")}function yi(e,t){let r=t.join(", ");return e.replace(/\)$/,`, ${r})`)}async function se(e,t,r){r={overwrite:false,silent:false,isNewProject:false,baseStyle:true,...r};let i=await g(t);return i&&i.ui&&i.ui.resolvedPaths.cwd!==t.resolvedPaths.cwd?await xi(e,t,i,{...r,isRemote:e?.length===1&&!!e[0].match(/\/chat\/b\//)}):await bi(e,t,r)}async function bi(e,t,r){if(!r.baseStyle&&!e.length)return;let i=o$1("Checking registry.",{silent:r.silent})?.start(),n$1=await Q(e,J$1(t));if(!n$1)return i?.fail(),R(new Error("Failed to fetch components from registry."));try{Wt(n$1.files??[],t.resolvedPaths.cwd);}catch(o){return i?.fail(),R(o)}console.log({tree:n$1}),i?.succeed(),await L(n$1.dependencies,n$1.devDependencies,t,{silent:r.silent}),await F$1(n$1.files,t,{overwrite:r.overwrite,silent:r.silent,path:r.path}),n$1.docs&&n.info(n$1.docs);}async function xi(e,t,r,i$1){if(!i$1.baseStyle&&!e.length)return;let n$1=o$1("Checking registry.",{silent:i$1.silent})?.start(),o=await Q(e,J$1(t));if(!o)return n$1?.fail(),R(new Error("Failed to fetch components from registry."));try{Wt(o.files??[],t.resolvedPaths.cwd);}catch(y){return n$1?.fail(),R(y)}n$1?.succeed();let a=[],s=[],c=[],m$1=o$1("Installing components.")?.start(),l=r.ui,f=await m(l),d=i(t.resolvedPaths.cwd,l.resolvedPaths.ui);if(o.tailwind?.config&&(await O(o.tailwind?.config,l,{silent:true,tailwindVersion:f}),s.push(j__default.relative(d,l.resolvedPaths.tailwindConfig))),o.cssVars){let y=await vi(e,t);await At(o.cssVars,l,{silent:true,tailwindVersion:f,tailwindConfig:o.tailwind?.config,overwriteCssVars:y}),s.push(j__default.relative(d,l.resolvedPaths.tailwindCss));}o.css&&(await $t(o.css,l,{silent:true}),s.push(j__default.relative(d,l.resolvedPaths.tailwindCss))),o.envVars&&await _t(o.envVars,l,{silent:true}),await L(o.dependencies,o.devDependencies,l,{silent:true}),await Vt(o.fonts,l,{silent:true});let g=new Map;for(let y of o.files??[]){let I=y.type||"registry:ui";g.has(I)||g.set(I,[]),g.get(I).push(y);}for(let y of Array.from(g.keys())){let I=g.get(y),S=y==="registry:ui"?r.ui:t,B=i(t.resolvedPaths.cwd,S.resolvedPaths.ui||S.resolvedPaths.cwd),T=await h(B,S.resolvedPaths.cwd)??S.resolvedPaths.cwd,Y=await F$1(I,S,{overwrite:i$1.overwrite,silent:true,rootSpinner:m$1,isRemote:i$1.isRemote,isWorkspace:true,path:i$1.path});a.push(...Y.filesCreated.map(O=>j__default.relative(B,j__default.join(T,O)))),s.push(...Y.filesUpdated.map(O=>j__default.relative(B,j__default.join(T,O)))),c.push(...Y.filesSkipped.map(O=>j__default.relative(B,j__default.join(T,O))));}if(m$1?.succeed(),a.sort(),s.sort(),c.sort(),!(a.length||s.length)&&!c.length&&o$1("No files updated.",{silent:i$1.silent})?.info(),a.length){o$1(`Created ${a.length} ${a.length===1?"file":"files"}:`,{silent:i$1.silent})?.succeed();for(let y of a)n.log(` - ${y}`);}if(s.length){o$1(`Updated ${s.length} ${s.length===1?"file":"files"}:`,{silent:i$1.silent})?.info();for(let y of s)n.log(` - ${y}`);}if(c.length){o$1(`Skipped ${c.length} ${s.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:i$1.silent})?.info();for(let y of c)n.log(` - ${y}`);}o.docs&&n.info(o.docs);}async function vi(e,t){let r=await T(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 Wt(e,t){for(let r of e)if(r?.target&&!jt(r.target,t))throw new Error(`We found an unsafe file path "${r.target} in the registry item. Installation aborted.`)}var Be="https://codeload.github.com/shadcn-ui/ui/tar.gz/main",F={next:"next","next-monorepo":"next-monorepo",vite:"vite",start:"start"};async function Mt(e){e={srcDir:false,...e};let t=e.template&&F[e.template]?e.template:"next",r=e.name??(t===F.next||t===F.vite||t===F.start?"my-app":"my-monorepo"),i="latest",n$1=e.components?.length===1&&!!e.components[0].match(/\/chat\/b\//);if(e.components&&n$1)try{let[s]=await N(e.components),{meta:c}=z$1.object({meta:z$1.object({nextVersion:z$1.string()})}).parse(s);i=c.nextVersion,t=F.next;}catch(s){n.break(),R(s);}if(!e.force){let{type:s,name:c}=await je([{type:e.template||n$1?null:"select",name:"type",message:`The path ${d.info(e.cwd)} does not contain a package.json file.
|
|
43
43
|
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:m=>m.trim(),validate:m=>m.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 v.access(e.cwd,v.constants.W_OK);}catch{n.break(),n.error(`The path ${d.info(e.cwd)} is not writable.`),n.error(`It is likely you do not have write permissions for this folder or the path ${d.info(e.cwd)} does not exist.`),n.break(),process.exit(1);}return v.existsSync(j__default.resolve(e.cwd,r,"package.json"))&&(n.break(),n.error(`A project with the name ${d.info(r)} already exists.`),n.error("Please choose a different name and try again."),n.break(),process.exit(1)),t===F.next&&await Ri(a,{version:i,cwd:e.cwd,packageManager:o,srcDir:!!e.srcDir}),t===F["next-monorepo"]&&await Ci(a,{packageManager:o}),t===F.vite&&await Ii(a,{packageManager:o}),t===F.start&&await ki(a,{packageManager:o}),{projectPath:a,projectName:r,template:t}}async function Ri(e,t){let r=o$1("Creating a new Next.js project. This may take a few minutes.").start(),i=["--tailwind","--eslint","--typescript","--app",t.srcDir?"--src-dir":"--no-src-dir","--no-import-alias",`--use-${t.packageManager}`];(t.version.startsWith("15")||t.version.startsWith("latest")||t.version.startsWith("canary"))&&i.push("--turbopack"),(t.version.startsWith("latest")||t.version.startsWith("canary"))&&i.push("--no-react-compiler");try{await execa("npx",[`create-next-app@${t.version}`,e,"--silent",...i],{cwd:t.cwd});}catch{n.break(),n.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 Ci(e,t){let r=o$1("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 v.ensureDir(i);let n=await fetch(Be);if(!n.ok)throw new Error(`Failed to download template: ${n.statusText}`);let o=j__default.resolve(i,"template.tar.gz");await v.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 v.move(a,e),await v.remove(i),await execa(t.packageManager,["install"],{cwd:e});let s=j__default.join(e,"package.json");if(v.existsSync(s)){let m=await v.readFile(s,"utf8"),l=JSON.parse(m);l.name=e.split("/").pop(),await v.writeFile(s,JSON.stringify(l,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."),R(i);}}async function Ii(e,t){let r=o$1("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 v.ensureDir(i);let n=await fetch(Be);if(!n.ok)throw new Error(`Failed to download template: ${n.statusText}`);let o=j__default.resolve(i,"template.tar.gz");await v.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 v.move(a,e),await v.remove(i),t.packageManager!=="pnpm"){let c=j__default.join(e,"pnpm-lock.yaml");v.existsSync(c)&&await v.remove(c);}await execa(t.packageManager,["install"],{cwd:e});let s=j__default.join(e,"package.json");if(v.existsSync(s)){let c=await v.readFile(s,"utf8"),m=JSON.parse(c);m.name=e.split("/").pop(),await v.writeFile(s,JSON.stringify(m,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."),R(i);}}async function ki(e,t){let r=o$1("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 v.ensureDir(i);let n=await fetch(Be);if(!n.ok)throw new Error(`Failed to download template: ${n.statusText}`);let o=j__default.resolve(i,"template.tar.gz");await v.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 v.move(a,e),await v.remove(i),t.packageManager!=="pnpm"){let c=j__default.join(e,"pnpm-lock.yaml");v.existsSync(c)&&await v.remove(c);}await execa(t.packageManager,["install"],{cwd:e});let s=j__default.join(e,"package.json");if(v.existsSync(s)){let c=await v.readFile(s,"utf8"),m=JSON.parse(c);m.name=e.split("/").pop(),await v.writeFile(s,JSON.stringify(m,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."),R(i);}}async function V(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){n.warn("Failed to load env files:",t);}}var Ue=".bak";function zt(e){if(!v.existsSync(e))return null;let t=`${e}${Ue}`;try{return v.renameSync(e,t),t}catch(r){return console.error(`Failed to create backup of ${e}: ${r}`),null}}function Bt(e){let t=`${e}${Ue}`;if(!v.existsSync(t))return false;try{return v.renameSync(t,e),!0}catch(r){return console.error(`Warning: Could not restore backup file ${t}: ${r}`),false}}function Ge(e){let t=`${e}${Ue}`;if(!v.existsSync(t))return false;try{return v.unlinkSync(t),!0}catch{return false}}async function Ut(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}=A$1(o);a&&!b$1[a]&&r.add(a);try{let[s]=await P([o],t,{useCache:!0});if(s?.registryDependencies)for(let c of s.registryDependencies){let{registry:m}=A$1(c);m&&!b$1[m]&&r.add(m),i.has(c)||n.push(c);}}catch(s){if(s instanceof u){let{registry:c}=A$1(o);c&&!b$1[c]&&r.add(c);continue}continue}}return Array.from(r)}async function A(e,t,r={}){r={silent:false,writeFile:true,...r};let n=(await Ut(e,t)).filter(m=>!t.registries?.[m]&&!Object.keys(b$1).includes(m));if(n.length===0)return {config:t,newRegistries:[]};let o=await ca({useCache:process.env.NODE_ENV!=="development"});if(!o)return {config:t,newRegistries:[]};let a={};for(let m of n)o[m]&&(a[m]=o[m]);if(Object.keys(a).length===0)return {config:t,newRegistries:[]};let s=Object.fromEntries(Object.entries(t.registries||{}).filter(([m])=>!Object.keys(b$1).includes(m))),c$1={...t,registries:{...s,...a}};if(r.writeFile){let{resolvedPaths:m,...l}=c$1,f=o$1("Updating components.json.",{silent:r.silent}).start(),d=c.parse(l);await v.writeFile(j__default.resolve(t.resolvedPaths.cwd,"components.json"),JSON.stringify(d,null,2)+`
|
|
44
44
|
`,"utf-8"),f.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?Ge(t):Bt(t)});var Je=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?F[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()}),Jt=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=Je.parse({cwd:j__default.resolve(t.cwd),isNewProject:!1,components:e,...t});if(await V(r.cwd),e.length>0){let i=J$1(j$1({resolvedPaths:{cwd:r.cwd}})),n=j__default.resolve(r.cwd,"components.json");if(v.existsSync(n)){let s=await v.readJson(n),c$1=c.partial().parse(s),m=j$1({resolvedPaths:{cwd:r.cwd}});i=J$1({...c$1,resolvedPaths:{...m.resolvedPaths,cwd:r.cwd}}),zt(n);}let{config:o}=await A(e,i,{silent:!0,writeFile:!1});i=o,M(e[0],i);let[a]=await T([e[0]],{config:i});a?.type==="registry:base"&&(a.config&&(i=J$1(Ti(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 ue(r),n.log(`${d.success("Success!")} Project initialization completed.
|
|
45
|
-
You may now add components.`),Ge(j__default.resolve(r.cwd,"components.json")),n.break();}catch(r){n.break(),R(r);}finally{K();}});async function ue(e$1){let r;if(e$1.skipPreflight)await l(e$1.cwd);else {let c=await Pt(e$1);if(c.errors["1"]){let{projectPath:m,template:l$1}=await Mt(e$1);m||process.exit(1),e$1.cwd=m,e$1.isNewProject=true,r=l$1,await l(e$1.cwd);}else c.projectInfo;}if(r==="next-monorepo")return e$1.cwd=j__default.resolve(e$1.cwd,"apps/web"),await e(e$1.cwd);let i={$schema:"https://ui.shadcn.com/schema.json",style:"default",rsc:true,tsx:true,tailwind:{config:"tailwind.config.js",css:"app/globals.css",baseColor:"neutral",cssVariables:true,prefix:""},aliases:{components:"@/components",utils:"@/lib/utils",lib:"@lib",hooks:"@hooks"}},n=[...e$1.baseStyle?["index"]:[],...e$1.components??[]],o=await f(e$1.cwd,i),{config:a}=await A(n,o,{silent:true});a.registries&&(i.registries=a.registries);let s=await f(e$1.cwd,i);await se(n,s,{overwrite:true,silent:e$1.silent,baseStyle:e$1.baseStyle,isNewProject:false});}var Ai=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()}),Kt=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$1,t)=>{try{let r=Ai.parse({components:e$1,cwd:j__default.resolve(t.cwd),...t});await V(r.cwd);let i=await e(r.cwd);i||(i=j$1({style:"new-york",resolvedPaths:{cwd:r.cwd}}));let n$1=["sidebar-","login-","signup-","otp-","calendar-"],o=["base-","radix-"];if(e$1.length>0&&i?.style&&o.some(f=>i?.style.startsWith(f))){let f=e$1.filter(d=>n$1.some(g=>d.startsWith(g)));f.length&&(n.warn(`The ${d.info(f.map(d=>d).join(", "))} component(s) are not available for the ${d.info(i.style)} style yet. They are coming soon.`),n.warn("In the meantime, you can visit the blocks page on https://ui.shadcn.com/blocks and copy the code."),n.break(),process.exit(1));}let a=!1;if(e$1.length>0){let{config:l,newRegistries:f}=await A(e$1,i,{silent:r.silent,writeFile:!1});i=l,a=f.length>0;}let s,c=!0;if(e$1.length>0){let[l]=await T([e$1[0]],{config:i});if(s=l?.type,c=s!=="registry:theme"&&s!=="registry:style",I(l)){await se(e$1,i,{...r,baseStyle:c});return}if(!r.yes&&(s==="registry:style"||s==="registry:theme")){n.break();let{confirm:f}=await je({type:"confirm",name:"confirm",message:d.warn(`You are about to install a new ${s.replace("registry:","")}.
|
|
45
|
+
You may now add components.`),Ge(j__default.resolve(r.cwd,"components.json")),n.break();}catch(r){n.break(),R(r);}finally{K();}});async function ue(e$1){let r;if(e$1.skipPreflight)await l(e$1.cwd);else {let c=await Pt(e$1);if(c.errors["1"]){let{projectPath:m,template:l$1}=await Mt(e$1);m||process.exit(1),e$1.cwd=m,e$1.isNewProject=true,r=l$1,await l(e$1.cwd);}else c.projectInfo;}if(r==="next-monorepo")return e$1.cwd=j__default.resolve(e$1.cwd,"apps/web"),await e(e$1.cwd);let i={$schema:"https://ui.shadcn.com/schema.json",style:"default",rsc:true,tsx:true,tailwind:{config:"tailwind.config.js",css:"app/globals.css",baseColor:"neutral",cssVariables:true,prefix:""},aliases:{components:"@/components",utils:"@/lib/utils",lib:"@lib",hooks:"@hooks"}},n=[...e$1.baseStyle?["index"]:[],...e$1.components??[]],o=await f(e$1.cwd,i),{config:a}=await A(n,o,{silent:true});a.registries&&(i.registries=a.registries);let s=await f(e$1.cwd,i);console.log({options:e$1,fullConfig:s,components:n}),await se(n,s,{overwrite:true,silent:e$1.silent,baseStyle:e$1.baseStyle,isNewProject:false});}var Ai=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()}),Kt=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$1,t)=>{try{let r=Ai.parse({components:e$1,cwd:j__default.resolve(t.cwd),...t});await V(r.cwd);let i=await e(r.cwd);i||(i=j$1({style:"new-york",resolvedPaths:{cwd:r.cwd}}));let n$1=["sidebar-","login-","signup-","otp-","calendar-"],o=["base-","radix-"];if(e$1.length>0&&i?.style&&o.some(f=>i?.style.startsWith(f))){let f=e$1.filter(d=>n$1.some(g=>d.startsWith(g)));f.length&&(n.warn(`The ${d.info(f.map(d=>d).join(", "))} component(s) are not available for the ${d.info(i.style)} style yet. They are coming soon.`),n.warn("In the meantime, you can visit the blocks page on https://ui.shadcn.com/blocks and copy the code."),n.break(),process.exit(1));}let a=!1;if(e$1.length>0){let{config:l,newRegistries:f}=await A(e$1,i,{silent:r.silent,writeFile:!1});i=l,a=f.length>0;}let s,c=!0;if(e$1.length>0){let[l]=await T([e$1[0]],{config:i});if(s=l?.type,c=s!=="registry:theme"&&s!=="registry:style",I(l)){await se(e$1,i,{...r,baseStyle:c});return}if(!r.yes&&(s==="registry:style"||s==="registry:theme")){n.break();let{confirm:f}=await je({type:"confirm",name:"confirm",message:d.warn(`You are about to install a new ${s.replace("registry:","")}.
|
|
46
46
|
Existing CSS variables and components will be overwritten. Continue?`)});f||(n.break(),n.log("Installation cancelled."),n.break(),process.exit(1));}}if(r.components?.length||(r.components=await Di(r)),(await l(r.cwd))?.tailwindVersion==="v4"){let l=c$1.filter(f=>r.components?.includes(f.name));l?.length&&(n.break(),l.forEach(f=>{n.warn(d.warn(f.message));}),n.break(),process.exit(1));}await ue({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});}catch(r){n.break(),R(r);}finally{K();}});async function Di(e){let t=await W();if(!t)return n.break(),R(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 je({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||(n.warn("No components selected. Exiting."),n.info(""),process.exit(1));let i=z$1.array(z$1.string()).safeParse(r);return i.success?i.data:(n.error(""),R(new Error("Something went wrong. Please try again.")),[])}async function Xt(e){let t={},r={cwd:e.cwd,registryFile:j__default.resolve(e.cwd,e.registryFile),outputDir:j__default.resolve(e.cwd,e.outputDir)};return v.existsSync(r.registryFile)||(t["13"]=true),await v.mkdir(r.outputDir,{recursive:true}),Object.keys(t).length>0&&(t["13"]&&(n.break(),n.error(`The path ${d.info(r.registryFile)} does not exist.`)),n.break(),process.exit(1)),{errors:t,resolvePaths:r}}var Li=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string()}),Zt=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)=>{try{let r=Li.parse({cwd:j.resolve(t.cwd),registryFile:e,outputDir:t.output}),{resolvePaths:i}=await Xt(r),n$2=await z.readFile(i.registryFile,"utf-8"),o$2=o.safeParse(JSON.parse(n$2));o$2.success||(n.error(`Invalid registry file found at ${d.info(i.registryFile)}.`),process.exit(1));let a=o$1("Building registry...");for(let s of o$2.data.items){a.start(`Building ${s.name}...`),s.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let m of s.files??[])m.content=await z.readFile(j.resolve(i.cwd,m.path),"utf-8");let c=n$1.safeParse(s);if(!c.success){n.error(`Invalid registry item found for ${d.info(s.name)}.`);continue}await z.writeFile(j.resolve(i.outputDir,`${c.data.name}.json`),JSON.stringify(c.data,null,2));}await z.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),a.succeed("Building registry.");}catch(r){n.break(),R(r);}});var er="https://ui.shadcn.com",Mi={next:"Next.js",vite:"Vite",start:"TanStack Start"},tr=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 h=rr();n.log("Build your own shadcn/ui."),n.log(`You will be taken to ${d.info(h)} to build your custom design system.`),n.break();let{proceed:y}=await je({type:"confirm",name:"proceed",message:"Open in browser?",initial:!0});y&&await Qt(h),process.exit(0);}let i=e;if(!i){let{enteredName:h}=await je({type:"text",name:"enteredName",message:"What is your project named?",initial:t.template?`${t.template}-app`:"my-app",format:y=>y.trim(),validate:y=>y.length>128?"Name should be less than 128 characters.":!0});h||process.exit(0),i=h;}let n$1=t.template;if(!n$1){let{selectedTemplate:h}=await je({type:"select",name:"selectedTemplate",message:`Which ${d.info("template")} would you like to use?`,choices:Object.entries(Mi).map(([y,I])=>({title:I,value:y}))});h||process.exit(0),n$1=h;}let o=await Bi(t.preset??!0);o||process.exit(0);let a,s;"_isUrl"in o?(a=o.url,s=new URL(o.url).searchParams.get("baseColor")??"neutral"):(a=zi(o),s=o.baseColor);let c=J$1({}),{config:m}=await A([a],c,{silent:!0});c=m;let[l]=await T([a],{config:c}),f;l?.type==="registry:base"&&l.config&&(f=l.config);let d$1=Je.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$1,baseColor:s,baseStyle:!1,registryBaseConfig:f,skipPreflight:!1}),g=await ue(d$1);if(g){await se(["component-example"],g,{baseStyle:!1,silent:!0,overwrite:!0});let h=Ui(n$1);h.length>0&&await F$1(h,g,{overwrite:!0,silent:!0});}n.log(`${d.success("Success!")} Project initialization completed.
|
|
47
47
|
You may now add components.`),n.break();}catch(r){n.break(),R(r);}finally{K();}});function zi(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 `${Gi()}?${t.toString()}`}async function Bi(e){if(e===true){let t=await da(),{selectedPreset:r}=await je({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=rr();return n.info(`
|
|
48
48
|
Opening ${d.info(i)} in your browser...
|
|
@@ -81,5 +81,5 @@ args = ["shadcn@${le}", "mcp"]`),n.break(),n.info("3. Restart Codex to load the
|
|
|
81
81
|
`).map(I=>{if(I.trim().startsWith("import "))return I;let S=I;return S=S.replace(/\b(asChild\s*\?\s*)Slot(\s*:)/g,"$1__SLOT_PLACEHOLDER__$2"),S=S.replace(/\bReact\.ComponentProps<typeof\s+Slot>/g,"React.ComponentProps<typeof __SLOT_PLACEHOLDER__>"),S=S.replace(/\bComponentProps<typeof\s+Slot>/g,"ComponentProps<typeof __SLOT_PLACEHOLDER__>"),S=S.replace(/(<\/?)Slot(\s*\/?>)/g,"$1__SLOT_PLACEHOLDER__$2"),S=S.replace(/\bSlot\b/g,(B,T,Y)=>{let O=Y.substring(0,T),Te=(O.match(/"/g)||[]).length,Pr=(O.match(/'/g)||[]).length;return Te%2!==0||Pr%2!==0?B:"__SLOT_PLACEHOLDER__"}),S=S.replace(/__SLOT_PLACEHOLDER__/g,"SlotPrimitive.Slot"),S}).join(`
|
|
82
82
|
`));let g=Array.from(new Set(n));return {content:s,replacedPackages:g}}async function dr(e$1){let t={};if(!v.existsSync(e$1.cwd)||!v.existsSync(j__default.resolve(e$1.cwd,"package.json")))return t["1"]=true,{errors:t,config:null};if(!v.existsSync(j__default.resolve(e$1.cwd,"components.json")))return t["3"]=true,{errors:t,config:null};try{let r=await e(e$1.cwd);return {errors:t,config:r}}catch{n.break(),n.error(`An invalid ${d.info("components.json")} file was found at ${d.info(e$1.cwd)}.
|
|
83
83
|
Before you can run a migration, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),n.error(`Learn more at ${d.info("https://ui.shadcn.com/docs/components-json")}.`),n.break(),process.exit(1);}}var ur=[{name:"icons",description:"migrate your ui components to a different icon library."},{name:"radix",description:"migrate to radix-ui."}],vo=z$1.object({cwd:z$1.string(),list:z$1.boolean(),yes:z$1.boolean(),migration:z$1.string().refine(e=>e&&ur.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional()}),gr=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=vo.parse({cwd:j__default.resolve(t.cwd),migration:e,list:t.list,yes:t.yes});if(r.list||!r.migration){n.info("Available migrations:");for(let o of ur)n.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$1}=await dr(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$1)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");r.migration==="icons"&&await mr(n$1),r.migration==="radix"&&await pr(n$1,{yes:r.yes});}catch(r){n.break(),R(r);}});async function hr(e$1){let t={},r={cwd:e$1.cwd,registryFile:j__default.resolve(e$1.cwd,e$1.registryFile),outputDir:j__default.resolve(e$1.cwd,e$1.outputDir)};if(!v.existsSync(r.registryFile))return t["13"]=true,{errors:t,resolvePaths:null,config:null};if(!v.existsSync(j__default.resolve(e$1.cwd,"components.json")))return t["3"]=true,{errors:t,resolvePaths:null,config:null};await v.mkdir(r.outputDir,{recursive:true});try{let i=await e(e$1.cwd);return {errors:t,config:i,resolvePaths:r}}catch{n.break(),n.error(`An invalid ${d.info("components.json")} file was found at ${d.info(e$1.cwd)}.
|
|
84
|
-
Before you can build the registry, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),n.break(),process.exit(1);}}var Ro=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),yr=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 Co({cwd:j.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function Co(e){try{let t=Ro.parse(e),[{errors:r,resolvePaths:i,config:n$2},o$2]=await Promise.all([hr(t),l(t.cwd)]);(r["3"]||!n$2||!o$2)&&(n.error(`A ${d.info("components.json")} file is required to build the registry. Run ${d.info("shadcn init")} to create one.`),n.break(),process.exit(1)),(r["13"]||!i)&&(n.error(`We could not find a registry file at ${d.info(j.resolve(t.cwd,t.registryFile))}.`),n.break(),process.exit(1));let a=await z.readFile(i.registryFile,"utf-8"),s=o.safeParse(JSON.parse(a));s.success||(n.error(`Invalid registry file found at ${d.info(i.registryFile)}.`),n.break(),process.exit(1));let c=o$1("Building registry..."),m=await Io(s.data,n$2,o$2);for(let l of m.items)l.files=l.files?.filter((f,d,g)=>d===g.findIndex(h=>h.path===f.path)),l.dependencies&&(l.dependencies=l.dependencies.filter((f,d,g)=>d===g.findIndex(h=>h===f)));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 d of l.files){let g=j.resolve(i.cwd,d.path);try{if(!(await z.stat(g)).isFile())continue;d.content=await z.readFile(g,"utf-8");}catch(h){console.error("Error reading file in registry build:",g,h);continue}}let f=n$1.safeParse(l);if(!f.success){n.error(`Invalid registry item found for ${d.info(l.name)}.`);continue}await z.writeFile(j.resolve(i.outputDir,`${f.data.name}.json`),JSON.stringify(f.data,null,2));}if(await z.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t.verbose){o$1(`The registry has ${d.info(m.items.length.toString())} items:`).succeed();for(let l of m.items){n.log(` - ${l.name} (${d.info(l.type)})`);for(let f of l.files??[])n.log(` - ${f.path}`);}}}catch(t){n.break(),R(t);}}async function Io(e,t,r){for(let i of e.items)if(i.files?.length)for(let n of i.files){let o=await G(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 wr=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()=>{n.warn(`The ${d.info("shadcn registry:mcp")} command is deprecated. Use the ${d.info("shadcn mcp")} command instead.`),n.break();});var jo=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),vr=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$1,t)=>{try{let r=jo.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 V(r.cwd);let i=j$1({style:"new-york",resolvedPaths:{cwd:r.cwd}}),n=J$1(i),o=j__default.resolve(r.cwd,"components.json");if(v.existsSync(o)){let l=await v.readJson(o),f=c.partial().parse(l);n=J$1({...i,...f});}let a=n;try{let l=await e(r.cwd);l&&(a=J$1(l));}catch{}let{config:s,newRegistries:c$1}=await A(e$1.map(l=>`${l}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),L$1(e$1,a);let m=await fa(e$1,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(m,null,2)),process.exit(0);}catch(r){R(r);}finally{K();}});var $o=z$1.object({cwd:z$1.string()}),Ir=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$1,t)=>{try{let r=$o.parse({cwd:j__default.resolve(t.cwd)});await V(r.cwd);let i=J$1({}),n=j__default.resolve(r.cwd,"components.json");if(v.existsSync(n)){let m=await v.readJson(n),l=c.partial().parse(m);i=J$1(l);}let o=i;try{let m=await e(r.cwd);m&&(o=J$1(m));}catch{}let{config:a,newRegistries:s}=await A(e$1,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),L$1(e$1,o);let c$1=await T(e$1,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){R(r);}finally{K();}});var kr={version:"3.6.
|
|
84
|
+
Before you can build the registry, you must create a valid ${d.info("components.json")} file by running the ${d.info("init")} command.`),n.break(),process.exit(1);}}var Ro=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(false)}),yr=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 Co({cwd:j.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function Co(e){try{let t=Ro.parse(e),[{errors:r,resolvePaths:i,config:n$2},o$2]=await Promise.all([hr(t),l(t.cwd)]);(r["3"]||!n$2||!o$2)&&(n.error(`A ${d.info("components.json")} file is required to build the registry. Run ${d.info("shadcn init")} to create one.`),n.break(),process.exit(1)),(r["13"]||!i)&&(n.error(`We could not find a registry file at ${d.info(j.resolve(t.cwd,t.registryFile))}.`),n.break(),process.exit(1));let a=await z.readFile(i.registryFile,"utf-8"),s=o.safeParse(JSON.parse(a));s.success||(n.error(`Invalid registry file found at ${d.info(i.registryFile)}.`),n.break(),process.exit(1));let c=o$1("Building registry..."),m=await Io(s.data,n$2,o$2);for(let l of m.items)l.files=l.files?.filter((f,d,g)=>d===g.findIndex(h=>h.path===f.path)),l.dependencies&&(l.dependencies=l.dependencies.filter((f,d,g)=>d===g.findIndex(h=>h===f)));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 d of l.files){let g=j.resolve(i.cwd,d.path);try{if(!(await z.stat(g)).isFile())continue;d.content=await z.readFile(g,"utf-8");}catch(h){console.error("Error reading file in registry build:",g,h);continue}}let f=n$1.safeParse(l);if(!f.success){n.error(`Invalid registry item found for ${d.info(l.name)}.`);continue}await z.writeFile(j.resolve(i.outputDir,`${f.data.name}.json`),JSON.stringify(f.data,null,2));}if(await z.copyFile(i.registryFile,j.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t.verbose){o$1(`The registry has ${d.info(m.items.length.toString())} items:`).succeed();for(let l of m.items){n.log(` - ${l.name} (${d.info(l.type)})`);for(let f of l.files??[])n.log(` - ${f.path}`);}}}catch(t){n.break(),R(t);}}async function Io(e,t,r){for(let i of e.items)if(i.files?.length)for(let n of i.files){let o=await G(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 wr=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()=>{n.warn(`The ${d.info("shadcn registry:mcp")} command is deprecated. Use the ${d.info("shadcn mcp")} command instead.`),n.break();});var jo=z$1.object({cwd:z$1.string(),query:z$1.string().optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}),vr=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$1,t)=>{try{let r=jo.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 V(r.cwd);let i=j$1({style:"new-york",resolvedPaths:{cwd:r.cwd}}),n=J$1(i),o=j__default.resolve(r.cwd,"components.json");if(v.existsSync(o)){let l=await v.readJson(o),f=c.partial().parse(l);n=J$1({...i,...f});}let a=n;try{let l=await e(r.cwd);l&&(a=J$1(l));}catch{}let{config:s,newRegistries:c$1}=await A(e$1.map(l=>`${l}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),L$1(e$1,a);let m=await fa(e$1,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(m,null,2)),process.exit(0);}catch(r){R(r);}finally{K();}});var $o=z$1.object({cwd:z$1.string()}),Ir=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$1,t)=>{try{let r=$o.parse({cwd:j__default.resolve(t.cwd)});await V(r.cwd);let i=J$1({}),n=j__default.resolve(r.cwd,"components.json");if(v.existsSync(n)){let m=await v.readJson(n),l=c.partial().parse(m);i=J$1(l);}let o=i;try{let m=await e(r.cwd);m&&(o=J$1(m));}catch{}let{config:a,newRegistries:s}=await A(e$1,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),L$1(e$1,o);let c$1=await T(e$1,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){R(r);}finally{K();}});var kr={version:"3.6.32"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Oo(){let e=new Command().name("shadcn").description("add items from registries to your project").version(kr.version,"-v, --version","display the version number");e.addCommand(Jt).addCommand(tr).addCommand(Kt).addCommand(or).addCommand(Ir).addCommand(vr).addCommand(gr).addCommand(nr).addCommand(Zt).addCommand(Xe),e.addCommand(yr).addCommand(wr),e.parse();}Oo();//# sourceMappingURL=index.js.map
|
|
85
85
|
//# sourceMappingURL=index.js.map
|