UNPKG

aceternity-ui

Version:

Add Aceternity UI components to your apps.

265 lines (255 loc) 33.2 kB
#!/usr/bin/env node import{existsSync as ee,promises as Ee}from"fs";import R from"path";import ce from"path";import{createMatchPath as Be}from"tsconfig-paths";async function V(e,t){return Be(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}import{cosmiconfig as Ve}from"cosmiconfig";import{loadConfig as ze}from"tsconfig-paths";import{z as d}from"zod";var le="@/components";var pe="@/lib/utils",me="app/globals.css",fe="tailwind.config.js";var Je=Ve("components",{searchPlaces:["components.json"]}),j=d.object({$schema:d.string().optional(),style:d.string(),rsc:d.coerce.boolean().default(!1),tsx:d.coerce.boolean().default(!0),tailwind:d.object({config:d.string(),css:d.string(),baseColor:d.string(),cssVariables:d.boolean().default(!0),prefix:d.string().default("").optional()}),aliases:d.object({components:d.string(),utils:d.string(),ui:d.string().optional(),examples:d.string().optional(),blocks:d.string().optional()})}).strict(),Ge=j.extend({resolvedPaths:d.object({tailwindConfig:d.string(),tailwindCss:d.string(),utils:d.string(),components:d.string(),ui:d.string()})});async function I(e){let t=await He(e);return t?await b(e,t):null}async function b(e,t){let n=await ze(e);if(n.resultType==="failed")throw new Error(`Failed to load ${t.tsx?"tsconfig":"jsconfig"}.json. ${n.message??""}`.trim());let r=await V(t.aliases.components,n),o=`${r}/ui`,i={ui:`${t.aliases.components}/ui`},s={...t,aliases:{...t.aliases,...i},resolvedPaths:{tailwindConfig:ce.resolve(e,t.tailwind.config),tailwindCss:ce.resolve(e,t.tailwind.css),utils:await V(t.aliases.utils,n),components:r,ui:o}};return Ge.parse(s)}async function He(e){try{let t=await Je.search(e);return t?j.parse(t.config):null}catch{throw new Error(`Invalid configuration found in ${e}/components.json.`)}}import{detect as Xe}from"@antfu/ni";async function L(e){let t=await Xe({programmatic:!0,cwd:e});return t==="yarn@berry"?"yarn":t==="pnpm@6"?"pnpm":t==="bun"?"bun":t??"npm"}import N from"chalk";import Ye from"gradient-string";var h={error(...e){console.log(N.red(...e))},warn(...e){console.log(N.yellow(...e))},info(...e){console.log(N.cyan(...e))},success(...e){console.log(N.green(...e))},break(){console.log("")}},qe=` \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u255A\u2588\u2588\u2557 \u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D `,Ze={magenta:"#FFFFFF",red:"#FFFFFF",yellow:"#FFFFFF"},Qe=Ye(Object.values(Ze)),E=Qe.multiline(qe);function O(e){typeof e=="string"&&(h.error(e),process.exit(1)),e instanceof Error&&(h.error(e.message),process.exit(1)),h.error("Something went wrong. Please try again."),process.exit(1)}import tt from"path";import{z as c}from"zod";var de=c.object({name:c.string(),dependencies:c.array(c.string()).optional(),devDependencies:c.array(c.string()).optional(),registryDependencies:c.array(c.string()).optional(),files:c.array(c.string()),type:c.enum(["components:ui","components:component","components:example","components:aceternityui","components:blocks"]),source:c.enum(["aceternityui","shadcn"]).optional()}),z=c.array(de),et=de.extend({files:c.array(c.object({name:c.string(),content:c.string()}))}),J=c.array(et),ge=c.array(c.object({name:c.string(),label:c.string()})),ue=c.object({inlineColors:c.object({light:c.record(c.string(),c.string()),dark:c.record(c.string(),c.string())}),cssVars:c.object({light:c.record(c.string(),c.string()),dark:c.record(c.string(),c.string())}),inlineColorsTemplate:c.string(),cssVarsTemplate:c.string()});import{HttpsProxyAgent as rt}from"https-proxy-agent";import nt from"node-fetch";var G="https://ui.aceternity.com",_="https://ui.shadcn.com",ot=process.env.https_proxy?new rt(process.env.https_proxy):void 0;async function he(){try{let[e]=await P(["index.json"],G);return z.parse([...e])}catch(e){throw console.error(e),new Error("Failed to fetch components from Aceternity UI registry.")}}async function xe(){try{let[e]=await P(["index.json"],_);return z.parse(e)}catch(e){throw console.error(e),new Error("Failed to fetch components from Shadcn UI registry.")}}async function H(){try{let[e]=await P(["styles/index.json"],_);return ge.parse(e)}catch{throw new Error("Failed to fetch styles from registry.")}}async function X(){return[{name:"slate",label:"Slate"},{name:"gray",label:"Gray"},{name:"zinc",label:"Zinc"},{name:"neutral",label:"Neutral"},{name:"stone",label:"Stone"}]}async function W(e){try{let[t]=await P([`colors/${e}.json`],_);return ue.parse(t)}catch{throw new Error("Failed to fetch base color from registry.")}}async function k(e,t,n,r=!1,o=!1){let i=[],s=[];for(let l of n)if(o){let p=e.find(m=>m.name===l);if(!p)continue;if(i.push(p),p.registryDependencies){let{shadcnTree:m}=await k(e,t,p.registryDependencies,r,!0);i.push(...m)}}else{let p=t.find(m=>m.name===l);if(!p){let m=l.split(":")[1],a=e.find(u=>u.name===m);if(!a)continue;if(i.push(a),a.registryDependencies){let{shadcnTree:u}=await k(e,t,a.registryDependencies,!0);i.push(...u)}}if(p&&s.push(p),r){let m=t.filter(a=>a.type==="components:example"&&a.registryDependencies?.includes(l));m.length&&s.push(...m)}if(p&&p.registryDependencies){let{aceternityuiTree:m,shadcnTree:a}=await k(e,t,p.registryDependencies,r,!1);i.push(...a),s.push(...m)}}return{shadcnTree:i.filter((l,p,m)=>m.findIndex(a=>a.name===l.name)===p),aceternityuiTree:s.filter((l,p,m)=>m.findIndex(a=>a.name===l.name)===p)}}async function ye(e){try{let n=e.map(o=>{let[i,s]=o.type.split(":");return`${i}/${s}/${o.name}.json`}),r=await P(n,G);return J.parse([...r])}catch{throw new Error("Failed to fetch tree from Aceternity UI registry.")}}async function we(e,t){try{let n=t.map(o=>`styles/${e}/${o.name}.json`),r=await P(n,_);return J.parse(r)}catch{throw new Error("Failed to fetch tree from Shadcn UI registry.")}}async function Te(e,t,n){if(n)return n;let[r,o]=t.type.split(":");return r in e.resolvedPaths?tt.join(e.resolvedPaths[r],o):null}async function P(e,t=G,n){try{return await Promise.all(e.map(async o=>await(await nt(`${t}/registry/${o}`,{agent:ot,headers:{}})).json()))}catch{throw new Error(`Failed to fetch registry from ${t}.`)}}import{promises as dt}from"fs";import{tmpdir as gt}from"os";import Ie from"path";import{SyntaxKind as it}from"ts-morph";var ve=async({sourceFile:e,config:t,baseColor:n})=>(t.tailwind?.cssVariables||!n?.inlineColors||e.getDescendantsOfKind(it.StringLiteral).forEach(r=>{let o=r.getText();if(o){let i=at(o.replace(/"/g,""),n.inlineColors);r.replaceWithText(`"${i.trim()}"`)}}),e);function Y(e){if(!e.includes("/")&&!e.includes(":"))return[null,e,null];let t=[],[n,r]=e.split("/");if(!n.includes(":"))return[null,n,r];let o=n.split(":"),i=o.pop(),s=o.join(":");return t.push(s??null,i??null,r??null),t}var st=["bg-","text-","border-","ring-offset-","ring-"];function at(e,t){e.includes(" border ")&&(e=e.replace(" border "," border border-border "));let n=e.split(" "),r=new Set,o=new Set;for(let i of n){let[s,l,p]=Y(i),m=st.find(u=>l?.startsWith(u));if(!m){r.has(i)||r.add(i);continue}let a=l?.replace(m,"");if(a&&a in t.light){r.add([s,`${m}${t.light[a]}`].filter(Boolean).join(":")+(p?`/${p}`:"")),o.add(["dark",s,`${m}${t.dark[a]}`].filter(Boolean).join(":")+(p?`/${p}`:""));continue}r.has(i)||r.add(i)}return[...Array.from(r),...Array.from(o)].join(" ").trim()}var q=async({sourceFile:e,config:t})=>{let n=e.getImportDeclarations();for(let r of n){let o=r.getModuleSpecifierValue();o.startsWith("@/registry/")&&(t.aliases.ui?r.setModuleSpecifier(o.replace(/^@\/registry\/[^/]+\/ui/,t.aliases.ui)):r.setModuleSpecifier(o.replace(/^@\/registry\/[^/]+/,t.aliases.components))),o=="@/lib/utils"&&r.getNamedImports().find(l=>l.getName()==="cn")&&r.setModuleSpecifier(o.replace(/^@\/lib\/utils/,t.aliases.utils))}return e};import{transformFromAstSync as ct}from"@babel/core";import{parse as lt}from"@babel/parser";import pt from"@babel/plugin-transform-typescript";import*as U from"recast";var mt={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,plugins:["asyncGenerators","bigInt","classPrivateMethods","classPrivateProperties","classProperties","classStaticBlock","decimal","decorators-legacy","doExpressions","dynamicImport","exportDefaultFrom","exportNamespaceFrom","functionBind","functionSent","importAssertions","importMeta","nullishCoalescingOperator","numericSeparator","objectRestSpread","optionalCatchBinding","optionalChaining",["pipelineOperator",{proposal:"minimal"}],["recordAndTuple",{syntaxType:"hash"}],"throwExpressions","topLevelAwait","v8intrinsic","typescript","jsx"]},Ce=async({sourceFile:e,config:t})=>{let n=e.getFullText();if(t.tsx)return n;let r=U.parse(n,{parser:{parse:i=>lt(i,mt)}}),o=ct(r,n,{cloneInputAst:!1,code:!1,ast:!0,plugins:[pt],configFile:!1});if(!o||!o.ast)throw new Error("Failed to transform JSX");return U.print(o.ast).code};import{SyntaxKind as ft}from"ts-morph";var Z=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let n=e.getFirstChildByKind(ft.ExpressionStatement);return n?.getText()==='"use client"'&&n.remove(),e};import{Project as ut,ScriptKind as ht}from"ts-morph";import{SyntaxKind as g}from"ts-morph";var Q=async({sourceFile:e,config:t})=>(t.tailwind?.prefix&&(e.getDescendantsOfKind(g.CallExpression).filter(n=>n.getExpression().getText()==="cva").forEach(n=>{if(n.getArguments()[0]?.isKind(g.StringLiteral)){let r=n.getArguments()[0];r&&r.replaceWithText(`"${v(r.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}n.getArguments()[1]?.isKind(g.ObjectLiteralExpression)&&n.getArguments()[1]?.getDescendantsOfKind(g.PropertyAssignment).find(r=>r.getName()==="variants")?.getDescendantsOfKind(g.PropertyAssignment).forEach(r=>{r.getDescendantsOfKind(g.PropertyAssignment).forEach(o=>{let i=o.getInitializerIfKind(g.StringLiteral);i&&i?.replaceWithText(`"${v(i.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)})})}),e.getDescendantsOfKind(g.JsxAttribute).forEach(n=>{if(n.getName()==="className"){if(n.getInitializer()?.isKind(g.StringLiteral)){let r=n.getInitializer();r&&r.replaceWithText(`"${v(r.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}if(n.getInitializer()?.isKind(g.JsxExpression)){let r=n.getInitializer()?.getDescendantsOfKind(g.CallExpression).find(o=>o.getExpression().getText()==="cn");r&&r.getArguments().forEach(o=>{(o.isKind(g.ConditionalExpression)||o.isKind(g.BinaryExpression))&&o.getChildrenOfKind(g.StringLiteral).forEach(i=>{i.replaceWithText(`"${v(i.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}),o.isKind(g.StringLiteral)&&o.replaceWithText(`"${v(o.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)})}}n.getName()==="classNames"&&n.getInitializer()?.isKind(g.JsxExpression)&&n.getDescendantsOfKind(g.PropertyAssignment).forEach(r=>{if(r.getInitializer()?.isKind(g.CallExpression)){let o=r.getInitializerIfKind(g.CallExpression);o&&o.getArguments().forEach(i=>{i.isKind(g.ConditionalExpression)&&i.getChildrenOfKind(g.StringLiteral).forEach(s=>{s.replaceWithText(`"${v(s.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}),i.isKind(g.StringLiteral)&&i.replaceWithText(`"${v(i.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)})}if(r.getInitializer()?.isKind(g.StringLiteral)&&r.getName()!=="variant"){let o=r.getInitializer();o&&o.replaceWithText(`"${v(o.getText()?.replace(/"/g,""),t.tailwind.prefix)}"`)}})})),e);function v(e,t=""){let n=e.split(" "),r=[];for(let o of n){let[i,s,l]=Y(o);i?l?r.push(`${i}:${t}${s}/${l}`):r.push(`${i}:${t}${s}`):l?r.push(`${t}${s}/${l}`):r.push(`${t}${s}`)}return r.join(" ")}function Se(e,t){let n=e.split(` `);for(let r of n)if(r.includes("@apply")){let o=r.replace("@apply","").trim(),i=v(o,t);e=e.replace(o,i)}return e}var xt=[q,Z,ve,Q],yt=[q,Z,Q],wt=new ut({compilerOptions:{}});async function Tt(e){let t=await dt.mkdtemp(Ie.join(gt(),"shadcn-"));return Ie.join(t,e)}async function be(e){let{source:t}=e,n=await Tt(e.filename),r=wt.createSourceFile(n,e.raw,{scriptKind:ht.TSX}),o=t==="aceternityui"?yt:xt;for(let i of o)i({sourceFile:r,...e});return await Ce({sourceFile:r,...e})}import Pe from"chalk";import{Command as vt}from"commander";import{execa as $e}from"execa";import Ct from"ora";import te from"prompts";import{z as T}from"zod";var St=T.object({components:T.array(T.string()).optional(),yes:T.boolean(),overwrite:T.boolean(),cwd:T.string(),all:T.boolean(),example:T.boolean(),shadcn:T.boolean(),path:T.string().optional()}),Fe=new vt().addHelpText("before",E).name("add").description("Add ui components to your project").argument("[components...]","the components to add").option("-y, --yes","skip confirmation prompt.",!0).option("-o, --overwrite","overwrite existing files.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-a, --all","add all available components",!1).option("-e, --example","include available examples & demos",!1).option("-s, --shadcn","include available components from shadcn-ui",!1).option("-p, --path <path>","the path to add the component to.").action(async(e,t)=>{try{let n=St.parse({components:e,...t}),r=R.resolve(n.cwd);ee(r)||(h.error(`The path ${r} does not exist. Please try again.`),process.exit(1));let o=await I(r);o||(h.warn(`Configuration is missing. Please run ${Pe.green("init")} to create a components.json file.`),process.exit(1));let i=n.shadcn?[]:await he(),s=await xe(),l=n.all?(n.shadcn?s:i).map(f=>f.name):n.components;if(!n.components?.length&&!n.all){let f=()=>i.filter(y=>{let x=y.type.split(":")[1];return["aceternityui","ui","blocks"].includes(x)||n.example&&x==="example"}),S=n.shadcn?s:f(),{components:ae}=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:!1,choices:S.map(y=>({title:`${y.name} (${y.type.split(":")[1]})`,value:y.name,selected:n.all?!0:n.components?.includes(y.name)}))});l=ae}l?.length||(h.warn("No components selected. Exiting."),process.exit(0));let{aceternityuiTree:p,shadcnTree:m}=await k(s,i,l,n.example,n.shadcn),a=await ye(p),u=await we(o.style,m),C=await W(o.tailwind.baseColor);!a.length&&!u.length?(h.warn("Selected components not found. Exiting."),process.exit(0)):(a.length!==0&&h.info(`Found ${a.length}x Aceternity UI components.`),u.length!==0&&h.info(`Found ${u.length}x Shadcn UI components.`)),a=a.map(f=>({...f,source:"aceternityui"})),u=u.map(f=>({...f,source:"shadcn"}));let A=[...a,...u];if(!n.yes){let{proceed:f}=await te({type:"confirm",name:"proceed",message:"Ready to install components and dependencies. Proceed?",initial:!0});f||process.exit(0)}let w=Ct("Installing components...").start();for(let f of A){w.text=`Installing ${f.name}...`;let S=await Te(o,f,n.path?R.resolve(r,n.path):void 0);if(!S)continue;if(ee(S)||await Ee.mkdir(S,{recursive:!0}),f.files.filter(x=>ee(R.resolve(S,x.name))).length&&!n.overwrite)if(l.includes(f.name)){w.stop();let{overwrite:x}=await te({type:"confirm",name:"overwrite",message:`Component ${f.name} already exists. Would you like to overwrite?`,initial:!1});if(!x){h.info(`Skipped ${f.name}. To overwrite, run with the ${Pe.green("--overwrite")} flag.`);continue}w.start(`Installing ${f.name}...`)}else continue;for(let x of f.files){let D=R.resolve(S,x.name),Me=await be({filename:x.name,raw:x.content,config:o,baseColor:C,source:f.source});o.tsx||(D=D.replace(/\.tsx$/,".jsx"),D=D.replace(/\.ts$/,".js")),await Ee.writeFile(D,Me)}let y=await L(r);if(f.dependencies?.length)try{await $e(y,[y==="npm"?"install":"add",...f.dependencies],{cwd:r})}catch(x){h.warn(` Failed to install dependencies for ${f.name}. -${f.dependencies.join(` - `)} Reason: ${x}`)}if(f.devDependencies?.length)try{await $e(y,[y==="npm"?"install":"add","-D",...f.devDependencies],{cwd:r})}catch(x){h.warn(` Failed to install devDependencies for ${f.name}. -${f.devDependencies.join(` - `)} Reason: ${x}`)}}w.succeed("Done.")}catch(n){console.log(n),O(n)}});import{existsSync as Ue,promises as $}from"fs";import F from"path";var Ae=`import { type ClassValue, clsx } from "clsx" import { twMerge } from "tailwind-merge" export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } `,De=`import { clsx } from "clsx" import { twMerge } from "tailwind-merge" export function cn(...inputs) { return twMerge(clsx(inputs)) } `,je=`/** @type {import('tailwindcss').Config} */ module.exports = { darkMode: ["class"], content: [ './pages/**/*.{<%- extension %>,<%- extension %>x}', './components/**/*.{<%- extension %>,<%- extension %>x}', './app/**/*.{<%- extension %>,<%- extension %>x}', './src/**/*.{<%- extension %>,<%- extension %>x}', ], prefix: "<%- prefix %>", theme: { container: { center: true, padding: "2rem", screens: { "2xl": "1400px", }, }, extend: { keyframes: { "accordion-down": { from: { height: "0" }, to: { height: "var(--radix-accordion-content-height)" }, }, "accordion-up": { from: { height: "var(--radix-accordion-content-height)" }, to: { height: "0" }, }, }, animation: { "accordion-down": "accordion-down 0.2s ease-out", "accordion-up": "accordion-up 0.2s ease-out", }, }, }, plugins: [require("tailwindcss-animate")], }`,ke=`/** @type {import('tailwindcss').Config} */ module.exports = { darkMode: ["class"], content: [ './pages/**/*.{<%- extension %>,<%- extension %>x}', './components/**/*.{<%- extension %>,<%- extension %>x}', './app/**/*.{<%- extension %>,<%- extension %>x}', './src/**/*.{<%- extension %>,<%- extension %>x}', ], prefix: "<%- prefix %>", theme: { container: { center: true, padding: "2rem", screens: { "2xl": "1400px", }, }, extend: { colors: { border: "hsl(var(--border))", input: "hsl(var(--input))", ring: "hsl(var(--ring))", background: "hsl(var(--background))", foreground: "hsl(var(--foreground))", primary: { DEFAULT: "hsl(var(--primary))", foreground: "hsl(var(--primary-foreground))", }, secondary: { DEFAULT: "hsl(var(--secondary))", foreground: "hsl(var(--secondary-foreground))", }, destructive: { DEFAULT: "hsl(var(--destructive))", foreground: "hsl(var(--destructive-foreground))", }, muted: { DEFAULT: "hsl(var(--muted))", foreground: "hsl(var(--muted-foreground))", }, accent: { DEFAULT: "hsl(var(--accent))", foreground: "hsl(var(--accent-foreground))", }, popover: { DEFAULT: "hsl(var(--popover))", foreground: "hsl(var(--popover-foreground))", }, card: { DEFAULT: "hsl(var(--card))", foreground: "hsl(var(--card-foreground))", }, }, borderRadius: { lg: "var(--radius)", md: "calc(var(--radius) - 2px)", sm: "calc(var(--radius) - 4px)", }, keyframes: { "accordion-down": { from: { height: "0" }, to: { height: "var(--radix-accordion-content-height)" }, }, "accordion-up": { from: { height: "var(--radix-accordion-content-height)" }, to: { height: "0" }, }, }, animation: { "accordion-down": "accordion-down 0.2s ease-out", "accordion-up": "accordion-up 0.2s ease-out", }, }, }, plugins: [require("tailwindcss-animate")], }`,Le=`import type { Config } from "tailwindcss" const config = { darkMode: ["class"], content: [ './pages/**/*.{<%- extension %>,<%- extension %>x}', './components/**/*.{<%- extension %>,<%- extension %>x}', './app/**/*.{<%- extension %>,<%- extension %>x}', './src/**/*.{<%- extension %>,<%- extension %>x}', ], prefix: "<%- prefix %>", theme: { container: { center: true, padding: "2rem", screens: { "2xl": "1400px", }, }, extend: { keyframes: { "accordion-down": { from: { height: "0" }, to: { height: "var(--radix-accordion-content-height)" }, }, "accordion-up": { from: { height: "var(--radix-accordion-content-height)" }, to: { height: "0" }, }, }, animation: { "accordion-down": "accordion-down 0.2s ease-out", "accordion-up": "accordion-up 0.2s ease-out", }, }, }, plugins: [require("tailwindcss-animate")], } satisfies Config export default config`,Ne=`import type { Config } from "tailwindcss" const config = { darkMode: ["class"], content: [ './pages/**/*.{<%- extension %>,<%- extension %>x}', './components/**/*.{<%- extension %>,<%- extension %>x}', './app/**/*.{<%- extension %>,<%- extension %>x}', './src/**/*.{<%- extension %>,<%- extension %>x}', ], prefix: "<%- prefix %>", theme: { container: { center: true, padding: "2rem", screens: { "2xl": "1400px", }, }, extend: { colors: { border: "hsl(var(--border))", input: "hsl(var(--input))", ring: "hsl(var(--ring))", background: "hsl(var(--background))", foreground: "hsl(var(--foreground))", primary: { DEFAULT: "hsl(var(--primary))", foreground: "hsl(var(--primary-foreground))", }, secondary: { DEFAULT: "hsl(var(--secondary))", foreground: "hsl(var(--secondary-foreground))", }, destructive: { DEFAULT: "hsl(var(--destructive))", foreground: "hsl(var(--destructive-foreground))", }, muted: { DEFAULT: "hsl(var(--muted))", foreground: "hsl(var(--muted-foreground))", }, accent: { DEFAULT: "hsl(var(--accent))", foreground: "hsl(var(--accent-foreground))", }, popover: { DEFAULT: "hsl(var(--popover))", foreground: "hsl(var(--popover-foreground))", }, card: { DEFAULT: "hsl(var(--card))", foreground: "hsl(var(--card-foreground))", }, }, borderRadius: { lg: "var(--radius)", md: "calc(var(--radius) - 2px)", sm: "calc(var(--radius) - 4px)", }, keyframes: { "accordion-down": { from: { height: "0" }, to: { height: "var(--radix-accordion-content-height)" }, }, "accordion-up": { from: { height: "var(--radix-accordion-content-height)" }, to: { height: "0" }, }, }, animation: { "accordion-down": "accordion-down 0.2s ease-out", "accordion-up": "accordion-up 0.2s ease-out", }, }, }, plugins: [require("tailwindcss-animate")], } satisfies Config export default config`;import Dt from"lodash.template";import K from"path";import ne from"fast-glob";import re,{pathExists as bt}from"fs-extra";import{loadConfig as Et}from"tsconfig-paths";var oe=["**/node_modules/**",".next","public","dist","build"];async function Oe(e){let t=await I(e);if(t)return t;let n=await Pt(e),r=await $t(e),o=await Ft(e);if(!n||!r||!o)return null;let i=await At(e),s={$schema:"https://ui.shadcn.com/schema.json",rsc:["next-app","next-app-src"].includes(n),tsx:i,style:"new-york",tailwind:{config:i?"tailwind.config.ts":"tailwind.config.js",baseColor:"zinc",css:r,cssVariables:!0,prefix:""},aliases:{utils:`${o}/lib/utils`,components:`${o}/components`,ui:`${o}/components/ui`,blocks:`${o}/components/blocks`,examples:`${o}/components/examples`}};return await b(e,s)}async function Pt(e){if(!(await ne.glob("**/*",{cwd:e,deep:3,ignore:oe})).find(i=>i.startsWith("next.config.")))return null;let r=await re.pathExists(K.resolve(e,"src"));return await re.pathExists(K.resolve(e,`${r?"src/":""}app`))?r?"next-app-src":"next-app":r?"next-pages-src":"next-pages"}async function $t(e){let t=await ne.glob("**/*.css",{cwd:e,deep:3,ignore:oe});if(!t.length)return null;for(let n of t)if((await re.readFile(K.resolve(e,n),"utf8")).includes("@tailwind base"))return n;return null}async function Ft(e){let t=await Et(e);if(t?.resultType==="failed"||!t?.paths)return null;for(let[n,r]of Object.entries(t.paths))if(r.includes("./*")||r.includes("./src/*"))return n.at(0);return null}async function At(e){return bt(K.resolve(e,"tsconfig.json"))}async function _e(e){if(!(await ne.glob("tailwind.config.*",{cwd:e,deep:3,ignore:oe})).length)throw new Error("Tailwind CSS is not installed. Visit https://tailwindcss.com/docs/installation to get started.");return!0}import se from"chalk";import{Command as jt}from"commander";import{execa as kt}from"execa";import B from"ora";import ie from"prompts";import{z as M}from"zod";var Lt=["tailwindcss-animate","class-variance-authority","clsx","tailwind-merge","framer-motion"],Nt=M.object({cwd:M.string(),yes:M.boolean(),defaults:M.boolean()}),Re=new jt().addHelpText("before",E).name("init").description("Initialize your project with shadcn-ui config & aceternity-ui").option("-y, --yes","skip confirmation prompt.",!1).option("-d, --defaults,","use default configuration.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async e=>{try{let t=Nt.parse(e),n=F.resolve(t.cwd);Ue(n)||(h.error(`The path ${n} does not exist. Please try again.`),process.exit(1)),_e(n);let r=await Oe(n);if(r){let o=await _t(n,r,e.defaults);await We(n,o)}else{let o=await I(n),i=await Ot(n,o,t.yes);await We(n,i)}h.info(""),h.info(`${se.green("Success!")} Project initialization completed. You may now add both shadcn-ui and aceternity-ui components.`),h.info("")}catch(t){O(t)}});async function Ot(e,t=null,n=!1){let r=a=>se.cyan(a),o=await H(),i=await X(),s=await ie([{type:"toggle",name:"typescript",message:`Would you like to use ${r("TypeScript")} (recommended)?`,initial:t?.tsx??!0,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${r("style")} would you like to use?`,choices:o.map(a=>({title:a.label,value:a.name}))},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as ${r("base color")}?`,choices:i.map(a=>({title:a.label,value:a.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${r("global CSS")} file?`,initial:t?.tailwind.css??me},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${r("CSS variables")} for colors?`,initial:t?.tailwind.cssVariables??!0,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${r("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${r("tailwind.config.js")} located?`,initial:t?.tailwind.config??fe},{type:"text",name:"components",message:`Configure the import alias for ${r("components")}:`,initial:t?.aliases.components??le},{type:"text",name:"utils",message:`Configure the import alias for ${r("utils")}:`,initial:t?.aliases.utils??pe},{type:"toggle",name:"rsc",message:`Are you using ${r("React Server Components")}?`,initial:t?.rsc??!0,active:"yes",inactive:"no"}]),l=j.parse({$schema:"https://ui.shadcn.com/schema.json",style:s.style,tailwind:{config:s.tailwindConfig,css:s.tailwindCss,baseColor:s.tailwindBaseColor,cssVariables:s.tailwindCssVariables,prefix:s.tailwindPrefix},rsc:s.rsc,tsx:s.typescript,aliases:{utils:s.utils,components:s.components,ui:`${s.components}/ui`,examples:`${s.components}/examples`,blocks:`${s.components}/blocks`}});if(!n){let{proceed:a}=await ie({type:"confirm",name:"proceed",message:`Write configuration to ${r("components.json")}. Proceed?`,initial:!0});a||process.exit(0)}h.info("");let p=B("Writing components.json...").start(),m=F.resolve(e,"components.json");return await $.writeFile(m,JSON.stringify(l,null,2),"utf8"),p.succeed(),await b(e,l)}async function _t(e,t,n=!1){let r=u=>se.cyan(u),o=t.style,i=t.tailwind.baseColor,s=t.tailwind.cssVariables;if(!n){let u=await H(),C=await X(),A=await ie([{type:"select",name:"style",message:`Which ${r("style")} would you like to use?`,choices:u.map(w=>({title:w.label,value:w.name}))},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as ${r("base color")}?`,choices:C.map(w=>({title:w.label,value:w.name}))},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${r("CSS variables")} for colors?`,initial:t?.tailwind.cssVariables,active:"yes",inactive:"no"}]);o=A.style,i=A.tailwindBaseColor,s=A.tailwindCssVariables}let l={$schema:t?.$schema,style:o,tailwind:{...t?.tailwind,baseColor:i,cssVariables:s},rsc:t?.rsc,tsx:t?.tsx,aliases:t?.aliases},p=j.parse(l);h.info("");let m=B("Writing components.json...").start(),a=F.resolve(e,"components.json");return await $.writeFile(a,JSON.stringify(p,null,2),"utf8"),m.succeed(),await b(e,p)}async function We(e,t){let n=B("Initializing project...")?.start();for(let[a,u]of Object.entries(t.resolvedPaths)){let C=F.extname(u)?F.dirname(u):u;a==="utils"&&u.endsWith("/utils")&&(C=C.replace(/\/utils$/,"")),Ue(C)||await $.mkdir(C,{recursive:!0})}let r=t.tsx?"ts":"js",o=F.extname(t.resolvedPaths.tailwindConfig),i;o===".ts"?i=t.tailwind.cssVariables?Ne:Le:i=t.tailwind.cssVariables?ke:je,await $.writeFile(t.resolvedPaths.tailwindConfig,Dt(i)({extension:r,prefix:t.tailwind.prefix}),"utf8");let s=await W(t.tailwind.baseColor);s&&await $.writeFile(t.resolvedPaths.tailwindCss,t.tailwind.cssVariables?t.tailwind.prefix?Se(s.cssVarsTemplate,t.tailwind.prefix):s.cssVarsTemplate:s.inlineColorsTemplate,"utf8"),await $.writeFile(`${t.resolvedPaths.utils}.${r}`,r==="ts"?Ae:De,"utf8"),n?.succeed();let l=B("Installing dependencies...")?.start(),p=await L(e),m=[...Lt,t.style==="new-york"?"@radix-ui/react-icons":"lucide-react"];await kt(p,[p==="npm"?"install":"add",...m],{cwd:e}),l?.succeed()}import{Command as Rt}from"commander";import Wt from"path";import Ut from"fs-extra";function Ke(){let e=Wt.join("package.json");return Ut.readJSONSync(e)}process.on("SIGINT",async()=>{process.exit(0)});process.on("SIGTERM",async()=>{process.exit(0)});async function Kt(){let e=await Ke(),t=new Rt().addHelpText("before",E).name("aceternity-ui").description("Add Aceternity UI components to your apps.").version(e.version||"1.0.0","-v, --version","display the version number");t.addCommand(Re).addCommand(Fe),t.parse()}Kt(); //# sourceMappingURL=index.js.map