untitledui 0.1.43-beta.1 → 0.1.44-beta

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.
@@ -52,8 +52,8 @@
52
52
 
53
53
  /* RADIUS */
54
54
  --radius-none: 0px;
55
- --radius-xs: 0.25rem;
56
- --radius-sm: 0.125rem;
55
+ --radius-xs: 0.125rem;
56
+ --radius-sm: 0.25rem;
57
57
  --radius-DEFAULT: 0.25rem;
58
58
  --radius-md: 0.375rem;
59
59
  --radius-lg: 0.5rem;
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import{Command as p0}from"commander";import o3 from"async-retry";import N from"chalk";import{Command as I0}from"commander";import{execa as L3}from"execa";import*as F from"fs";import Z3 from"ora";import N0 from"os";import*as T from"path";import Q3 from"prompts";import{Project as A0}from"ts-morph";import f3 from"node-fetch";import{Readable as J0,pipeline as K0}from"stream";import{x as U0}from"tar";import{promisify as V0}from"util";var b0=V0(K0);async function m3(W,Q){try{let z=await L0(Q);await b0(z,U0({cwd:W,strip:1}))}catch(z){throw new Error(`Failed to download or extract repository from API: ${z instanceof Error?z.message:z}`)}}async function L0(W){let Q=`https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api/download-repo?template=${W.template}`;try{let z=await f3(Q,{method:"GET",headers:{"Content-Type":"application/json",Accept:"application/octet-stream"}});if(z.status===403||z.status===404)throw new Error("Repository not found");if(!z.ok)throw new Error(`Failed to download from API. Status: ${z.status} ${z.statusText}`);if(!z.body)throw new Error("Response body is empty");return J0.from(z.body)}catch(z){throw new Error(`Error downloading tarball: ${z instanceof Error?z.message:z}`)}}async function B3(W){let Q=`https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api/validate-key?key=${W}`;try{return(await f3(Q)).status===200}catch{return!1}}import M0 from"node-fetch";var c3={invalid_key:"Invalid key provided",no_components_found:"No components found",no_components_provided:"No components provided"};async function J3(W,Q,z){let $=Q.map((q)=>{if(q.includes("modals/"))if(q.includes("-modal"))return q;else return q+"-modal";return q});try{let q=await M0("https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api/components",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({type:W,components:$,key:z})});if(!q.ok)console.log(c3?.[q.statusText]||c3.no_components_found),process.exit(1);return await q.json()}catch(q){return null}}import N3 from"node-fetch";var p={invalid_key:"Invalid key provided",no_components_found:"No components found",no_components_provided:"No components provided"};async function l3(W,Q=""){let z=`https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api/components/list?key=${Q}&type=${W}`;try{let X=await N3(z),$=await X.json();if(!X.ok)console.log(p?.[X.statusText]||p.no_components_found),process.exit(1);if(!$?.components?.length)return null;return $}catch(X){return console.error(X),null}}async function a3(W,Q="",z){let X=`https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api/components/list?key=${Q}&type=${W}&subfolders=${z.join(",")}`;try{let $=await N3(X);if(!$.ok)console.log(p?.[$.statusText]||p.no_components_found),process.exit(1);let q=await $.json();if(!q?.components?.length)return null;return q}catch($){return console.error($),null}}async function s3(W=""){let Q=`https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api/components/list?key=${W}`;try{let z=await N3(Q);if(!z.ok)console.log(p?.[z.statusText]||p.no_components_found),process.exit(1);let X=await z.json();if(!X?.types?.length)return null;return X}catch(z){return console.error(z),null}}import n3 from"fast-glob";import*as y3 from"fs";import*as A3 from"path";import{Project as j1}from"ts-morph";import{loadConfig as R0}from"tsconfig-paths";import B1 from"prettier";import V3 from"fast-glob";import*as K3 from"fs";import*as U3 from"path";import{loadConfig as j0}from"tsconfig-paths";var d=["**/node_modules/**",".next","public","dist","build"],r3={"next-app":"Next.js (App)","next-pages":"Next.js (Pages)",vite:"Vite",other:"Other"};async function o(W){let Q=K3.existsSync(U3.resolve(W,"src")),z=K3.existsSync(U3.resolve(W,`${Q?"src/":""}app`)),[X,$,q,L]=await Promise.all([V3.glob("**/{next,vite,astro}.config.*|gatsby-config.*",{cwd:W,deep:2,ignore:d}),H0(W),v0(W),G0(W)]),j={framework:"other",isTsx:$,tailwindFile:q||null,aliasPrefix:L,isSrcDir:Q,isUsingAppDir:z};if(X.find((b)=>b.startsWith("next.config."))?.length)return j.framework=z?"next-app":"next-pages",j;else if(X.find((b)=>b.startsWith("vite.config."))?.length)return j.framework="vite",j;else if(X?.length||K3.existsSync(U3.resolve(W,"package.json")))return j.framework="other",j;return null}async function H0(W){return(await V3.glob("tsconfig.*",{cwd:W,deep:2,ignore:d})).length>0}async function v0(W){let Q=await V3.glob("tailwind.config.*",{cwd:W,deep:2,ignore:d});if(!Q.length)return null;return Q[0]}async function G0(W){let Q=await j0(W);if(Q?.resultType==="failed"||!Object.keys(Q.paths).length)return null;let z={};for(let[X,$]of Object.entries(Q.paths)){let q=X.replace(/\/\*$/,"/");if($.some((L)=>L.includes("/app/*")))z.appPrefix=q;else if($.some((L)=>L.includes("/components/*")))z.componentsPrefix=q;else if($.some((L)=>L.includes("/utils/*")))z.utilsPrefix=q;else if($.some((L)=>L.includes("/styles/*")))z.stylesPrefix=q;else if($.some((L)=>L.includes("./*")||L.includes("/src/*")))z.srcPrefix=q}return z||null}function t(W){let Q=R0(W),z=n3.sync(["tailwind.config.*","**/globals.css","**/{layout,_app,main}.tsx","package.json"],{cwd:W,deep:4,absolute:!0,onlyFiles:!0,ignore:d}),X={tailwindFile:z.find(($)=>$.includes("tailwind.config.")),cssFile:z.find(($)=>$.includes("globals.css")),layoutFile:z.find(($)=>$.includes("layout")),appFile:z.find(($)=>$.includes("_app")),mainFile:z.find(($)=>$.includes("main")),packageJson:z.find(($)=>$.includes("package.json")),tsConfig:Q?.resultType==="success"?Q?.configFileAbsolutePath:void 0};if(Q.resultType==="failed")throw new Error(`Failed to load tsconfig.json. ${Q.message??""}`.trim());return X}function e(W,Q,z={},X=""){if(W.includes("components")){if(z?.componentsPrefix)return W.replace(/@\/components\//,A3.posix.join(z?.componentsPrefix,Q?Q.replace(/components\//,""):"","/"));if(Q){let $=z?.srcPrefix?A3.posix.join(z?.srcPrefix,Q,"/"):X;return W.replace(/@\/components\//,$)}}if(W.includes("app")&&z?.appPrefix)return W.replace(/^@\/app\//,z?.appPrefix);if(W.includes("utils")&&z?.utilsPrefix)return W.replace(/^@\/utils\//,z?.utilsPrefix);if(W.includes("styles")&&z?.stylesPrefix)return W.replace(/^@\/styles\//,z?.stylesPrefix);if(z?.srcPrefix)return W.replace(/^@\//,z?.srcPrefix);return W}function i3(W){let Q=n3.sync(["vite.config.*"],{cwd:W,absolute:!0,onlyFiles:!0,ignore:d})?.[0];if(!Q)return!1;try{let z=y3.readFileSync(Q,"utf-8");return u0(z)}catch{return!1}}function u0(W){let Q=W.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"");if(!["tailwindcss","@tailwindcss/vite","tailwind("].some((q)=>Q.includes(q)))return!1;return["plugins:","postcss:","css:"].some((q)=>Q.includes(q))}function C(){if("bun/1.2.18 npm/? node/v24.3.0 darwin arm64".startsWith("yarn"))return"yarn";if("bun/1.2.18 npm/? node/v24.3.0 darwin arm64".startsWith("pnpm"))return"pnpm";if("bun/1.2.18 npm/? node/v24.3.0 darwin arm64".startsWith("bun"))return"bun";return"npm"}function z3(){switch(C()){case"yarn":return"yarn";case"pnpm":return"pnpx";case"bun":return"bunx";default:return"npx"}}function p3(){switch(C()){case"yarn":return"yarn dev";case"pnpm":return"pnpm dev";case"bun":return"bun dev";default:return"npm run dev"}}function b3(W){return W.replace(/^[ \t]*\/\/\s*(TODO:|collapse-(start|end)).*\r?\n?|[ \t]*{\s*\/\*\s*(TODO:|collapse-(start|end)).*?\*\/\s*}\r?\n?/gm,"")}var y0=T.join(N0.homedir(),".untitledui"),c=T.join(y0,"config.json"),B={components:[],path:"",type:void 0,license:""};if(F.existsSync(c)){let W=JSON.parse(F.readFileSync(c,"utf-8"));B.license=W.license}var $3=(W)=>{if(W.aborted)process.stdout.write("\x1B[?25h"),process.stdout.write(`
3
- `),process.exit(1)},t3=new I0().name("add").description("add a component to your project").argument("[components...]","the components to add").option("-a, --all","add all available components",!1).option("-o, --overwrite","overwrite existing files.",!1).option("-p, --path <path>","the path to add the component to.").option("-d, --dir <directory>","the directory where the project is located.").option("-t, --type <base|marketing|shared-assets|application|foundations>","the type of the component to add.").action(async(W,Q)=>{if(W)B.components=W;if(Q)B.all=Q.all,B.dir=Q.dir,B.path=Q.path,B.overwrite=Q.overwrite,B.license=Q.license||B.license;try{await E3(B)}catch(z){console.error(N.red(z))}});async function E3(W){if(W)B={...B,...W};let Q=Z3().start(),z=T.posix.join(process.cwd(),B.dir||"");if(!F.existsSync(T.resolve(z,"package.json")))Q.warn("This command should be run in a project directory."),process.exit(1);let $=await o(z);if(B.license){if(!await B3(B.license))Q.fail("Invalid license key"),process.exit(1);if(!F.existsSync(c)){let K=T.dirname(c);F.mkdirSync(K,{recursive:!0}),F.writeFileSync(c,JSON.stringify({license:B.license},null,2))}if(JSON.parse(F.readFileSync(c,"utf-8")).license!==B.license)F.writeFileSync(c,JSON.stringify({license:B.license},null,2),"utf-8")}Q.stop();let q=[];if(B.components.length){let Y=await J3(B.type,B.components,B.license);if(Y&&Y.pro&&Y.pro.length>0){if(console.log(),Y.pro.length===1){let Z=Y.pro[0]?.split("/")[1]||Y.pro[0];console.log(N.yellow(`\uD83D\uDD12 The ${N.cyan(Z)} component requires PRO access.`))}else console.log(N.yellow("\uD83D\uDD12 The following components require PRO access:")),Y.pro.forEach((Z)=>{let K=Z?.split("/")[1]||Z;console.log(` • ${N.cyan(K)}`)});console.log(),console.log("To access PRO components:"),console.log(` ${N.green("→")} If you've already purchased: ${N.cyan(`${z3()} untitledui@latest login`)}`),console.log(` ${N.green("→")} To purchase PRO components: ${N.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(!Y?.components.length)console.log("No components found"),process.exit(1);q.push(...Y.components)}if(!B?.type&&!B?.components.length){let Y=await s3(B.license);if(!Y)console.log("No component types found"),process.exit(1);let Z=await Q3({type:"select",name:"type",onState:$3,message:`What type of ${N.cyan("component")} are you adding?`,choices:Y?.types.map((K)=>({title:K,value:K}))});B.type=Z.type}if(!B?.path){let Y=await Q3({type:"text",name:"path",onState:$3,message:`Where would you like to add the ${N.cyan("components")}?`,initial:"components"});B.path=Y.path}if(!B?.components.length){let Y=await l3(B?.type,B.license);if(!Y)console.log("No components found"),process.exit(1);let Z=await Q3({type:"multiselect",name:"components",onState:$3,message:`Which ${N.cyan("components")} would you like to add?`,choices:Y?.components?.map((V)=>({title:V?.name+(V?.count?` (${V?.count} variants)`:"")||"example",value:V||"example",selected:B.components.includes(V.name)})),instructions:!1,hint:"- Space to select. Return to submit"});if(!Z.components||!Z.components.length)console.log("No option selected. Exiting..."),process.exit(1);let K=Z.components.filter((V)=>V?.type==="file").map((V)=>V.name),R=Z.components.filter((V)=>V?.type==="dir").map((V)=>V.name),x=[];if(R.length){let V=await a3(B?.type,B.license,R);if(V&&V.components.length)for(let D of V.components){let[k,u]=Object.entries(D)[0]||[],I=await Q3({type:"select",name:"component",onState:$3,message:`Which ${N.cyan("variant")} from ${N.cyan(k)} would you like to add?`,choices:u?.map((P)=>({title:P?.name.replace(/-modal/g,"")||"example",value:P?.name||"example",selected:B.components.includes(P.name)})),instructions:!1,hint:"- Space to select. Return to submit"});if(!I.component)console.log("No variant selected for "+N.cyan(k));x.push(k+"/"+I.component)}else console.log("No variants found")}B.components=[...x,...K]}if(!B.components?.length)Q.warn("No components selected. Exiting."),process.exit(1);let L=t(z),j=new Set,b=new Set,y=new Set,S=new A0({tsConfigFilePath:L?.tsConfig});if(Q.start(),B.type&&B.components.length){let Y=await J3(B.type,B.components,B.license);if(!Y?.components.length)console.log("No components found"),process.exit(1);q.push(...Y.components)}let E=new Set;if(q.forEach((Y)=>{Y?.components?.forEach((Z)=>{E.add({name:Z.name,path:Z.path})})}),Q.stop(),E.size){let Y=Array.from(E).filter((Z)=>!F.existsSync(T.posix.join(z,`${$?.isSrcDir?"src":""}`,Z?.path?.replace(/components\//,B.path+"/"))));if(Y?.length){let Z=await Q3({type:"multiselect",name:"baseComponents",onState:$3,message:"Select which base components you want to add",choices:Y.map((K)=>({title:K?.name,value:K?.name,selected:!0})),instructions:!1,hint:"- Space to select. Return to submit"});if(B.baseComponents=Z.baseComponents,!Y.length&&!Z.baseComponents?.length)Q.warn("No components selected")}}if(Q.start(),B?.baseComponents?.length){let Y=await J3("",B.baseComponents,B.license);if(!Y||!Y?.components.length)console.log("No base components found");else q.push(...Y.components)}if(Q.stop(),q.forEach((Y)=>{let Z=Z3(`Adding ${Y.name}...`).start(),K=Y.files;Y?.dependencies?.forEach((R)=>b.add(R)),Y?.devDependencies?.forEach((R)=>y.add(R));try{if(K?.forEach(async({path:R,code:x})=>{let V=T.posix.join(z,`${$?.isSrcDir?"src":""}`,R.replace(/components\//,B.path+"/")),D=$?.framework==="vite"?x.replace(`"use client";
2
+ import{Command as e3}from"commander";import o0 from"async-retry";import y from"chalk";import{Command as y3}from"commander";import{execa as L0}from"execa";import*as F from"fs";import q0 from"ora";import E3 from"os";import*as D from"path";import W0 from"prompts";import{Project as _3}from"ts-morph";import d0 from"node-fetch";import{Readable as K3,pipeline as V3}from"stream";import{x as L3}from"tar";import{promisify as b3}from"util";var M3=b3(V3);async function f0(Q,W){try{let z=await j3(W);await M3(z,L3({cwd:Q,strip:1}))}catch(z){throw new Error(`Failed to download or extract repository from API: ${z instanceof Error?z.message:z}`)}}async function j3(Q){let W=`https://www.untitledui.com/react/api/download-repo?template=${Q.template}`;try{let z=await d0(W,{method:"GET",headers:{"Content-Type":"application/json",Accept:"application/octet-stream"}});if(z.status===403||z.status===404)throw new Error("Repository not found");if(!z.ok)throw new Error(`Failed to download from API. Status: ${z.status} ${z.statusText}`);if(!z.body)throw new Error("Response body is empty");return K3.from(z.body)}catch(z){throw new Error(`Error downloading tarball: ${z instanceof Error?z.message:z}`)}}async function U0(Q){let W=`https://www.untitledui.com/react/api/validate-key?key=${Q}`;try{return(await d0(W)).status===200}catch{return!1}}import H3 from"node-fetch";var m0={invalid_key:"Invalid key provided",no_components_found:"No components found",no_components_provided:"No components provided"};async function K0(Q,W,z){let Z=W.map((B)=>{if(B.includes("modals/"))if(B.includes("-modal"))return B;else return B+"-modal";return B});try{let B=await H3("https://www.untitledui.com/react/api/components",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({type:Q,components:Z,key:z})});if(!B.ok)console.log(m0?.[B.statusText]||m0.no_components_found),process.exit(1);return await B.json()}catch(B){return null}}import v0 from"node-fetch";var p={invalid_key:"Invalid key provided",no_components_found:"No components found",no_components_provided:"No components provided"};async function c0(Q,W=""){let z=`https://www.untitledui.com/react/api/components/list?key=${W}&type=${Q}`;try{let q=await v0(z),Z=await q.json();if(!q.ok)console.log(p?.[q.statusText]||p.no_components_found),process.exit(1);if(!Z?.components?.length)return null;return Z}catch(q){return console.error(q),null}}async function l0(Q,W="",z){let q=`https://www.untitledui.com/react/api/components/list?key=${W}&type=${Q}&subfolders=${z.join(",")}`;try{let Z=await v0(q);if(!Z.ok)console.log(p?.[Z.statusText]||p.no_components_found),process.exit(1);let B=await Z.json();if(!B?.components?.length)return null;return B}catch(Z){return console.error(Z),null}}async function a0(Q=""){let W=`https://www.untitledui.com/react/api/components/list?key=${Q}`;try{let z=await v0(W);if(!z.ok)console.log(p?.[z.statusText]||p.no_components_found),process.exit(1);let q=await z.json();if(!q?.types?.length)return null;return q}catch(z){return console.error(z),null}}import i0 from"fast-glob";import*as u0 from"fs";import*as m from"path";import{Project as N1}from"ts-morph";import{loadConfig as N3}from"tsconfig-paths";import K1 from"prettier";import $0 from"fast-glob";import*as f from"fs";import*as t from"path";import{loadConfig as R3}from"tsconfig-paths";import s0 from"fs";import G3 from"path";function r0(Q=""){let W=G3.join(Q,"package.json");if(!s0.existsSync(W))return null;else return JSON.parse(s0.readFileSync(W,"utf-8"))}var O=["**/node_modules/**",".next","public","dist","build"],n0={"next-app":"Next.js (App)","next-pages":"Next.js (Pages)",vite:"Vite",other:"Other"};async function o(Q){let W=f.existsSync(t.resolve(Q,"src")),z=f.existsSync(t.resolve(Q,`${W?"src/":""}app`)),[q,Z,B,u,G]=await Promise.all([$0.glob("**/{next,vite,astro}.config.*|gatsby-config.*",{cwd:Q,deep:2,ignore:O}),I3(Q),v3(Q),u3(Q),r0(Q)]),U=f.existsSync(t.resolve(Q,"components.json")),H=null;if(U)H=JSON.parse(f.readFileSync(t.resolve(Q,"components.json"),"utf-8"));let b=$0.sync(["**/**/theme.css"],{cwd:Q,absolute:!0,onlyFiles:!0,ignore:O}),I=b?.[0]&&f.readFileSync(b[0],"utf-8").match(/(--color-brand+-\d{1,3}):\s*(rgb\([^)]+\))/g)?.[1]||void 0,K={tailwind:{config:B||void 0,brandColor:I?.replace(/--color-([^-]+(?:-[^-]+)?)-\d+:.*/,"$1")||void 0},aliases:H?.aliases||u||{},isTsx:Z,isSrcDir:W,isAppDir:z,framework:"other"};if(q.find((Y)=>Y.startsWith("next.config."))?.length)return K.framework=z?"next-app":"next-pages",K;else if(q.find((Y)=>Y.startsWith("vite.config."))?.length)return K.framework="vite",K;else if(q?.length||f.existsSync(t.resolve(Q,"package.json")))return K.framework="other",K;else if(Object.keys(G?.dependencies||{}).includes("react"))return K.framework="next-pages",K;return null}async function I3(Q){return(await $0.glob("tsconfig.*",{cwd:Q,deep:2,ignore:O})).length>0}async function v3(Q){let W=await $0.glob("tailwind.config.*",{cwd:Q,deep:2,ignore:O});if(!W.length)return null;return W[0]}async function u3(Q){let W=await R3(Q);if(console.log(W),W?.resultType==="failed"||!Object.keys(W.paths).length)return null;let z={},q={app:/\/?app\/\*$/,components:/\/?components\/\*$/,ui:/\/?ui\/\*$/,utils:/\/?utils\/\*$/,styles:/\/?styles\/\*$/,hooks:/\/?hooks\/\*$/,src:/^(?:\.\/\*|\/\*|\*|src\/\*|\/src\/\*)$/};for(let[Z,B]of Object.entries(W.paths)){let u=Z.replace(/\/\*$/,"/");for(let[G,U]of Object.entries(q))if(B.some((H)=>U.test(H))){z[G]=u;break}}return z||null}function e(Q){let W=N3(Q),z=i0.sync(["tailwind.config.*","**/globals.css","**/{layout,_app,main}.tsx","package.json"],{cwd:Q,deep:4,absolute:!0,onlyFiles:!0,ignore:O}),q={tailwindFile:z.find((Z)=>Z.includes("tailwind.config.")),cssFile:z.find((Z)=>Z.includes("globals.css")),layoutFile:z.find((Z)=>Z.includes("layout")),appFile:z.find((Z)=>Z.includes("_app")),mainFile:z.find((Z)=>Z.includes("main")),packageJson:z.find((Z)=>Z.includes("package.json")),tsConfig:W?.resultType==="success"?W?.configFileAbsolutePath:void 0};if(W.resultType==="failed")throw new Error(`Failed to load tsconfig.json. ${W.message??""}`.trim());return q}function z0(Q,W,z={},q=""){if(Q.includes("components")){if(z?.components||z?.ui)return Q.replace(/@\/components\//,m.posix.join(z?.components||z?.ui||"",W?W.replace(/components\/?/,""):"","/"));if(W){let Z=z?.src?m.posix.join(z?.src,W,"/"):q;return Q.replace(/@\/components\//,Z)}}if(Q.includes("app"))if(z.app)return Q.replace(/^@\/app\//,m.posix.join(z?.app,"/"));else return Q.replace(/^@\//,q);if(Q.includes("utils"))if(z.utils)return Q.replace(/^@\/utils\//,m.posix.join(z?.utils,"/"));else return Q.replace(/^@\//,q);if(Q.includes("hooks"))if(z.hooks)return Q.replace(/^@\/hooks\//,m.posix.join(z?.hooks,"/"));else return Q.replace(/^@\//,q);if(Q.includes("styles"))if(z.styles)return Q.replace(/^@\/styles\//,m.posix.join(z?.styles,"/"));else return Q.replace(/^@\//,q);if(z?.src)return Q.replace(/^@\//,m.posix.join(z?.src,"/"));return Q}function p0(Q){let W=i0.sync(["vite.config.*"],{cwd:Q,absolute:!0,onlyFiles:!0,ignore:O})?.[0];if(!W)return!1;try{let z=u0.readFileSync(W,"utf-8");return A3(z)}catch{return!1}}function A3(Q){let W=Q.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"");if(!["tailwindcss","@tailwindcss/vite","tailwind("].some((B)=>W.includes(B)))return!1;return["plugins:","postcss:","css:"].some((B)=>W.includes(B))}function C(){if("bun/1.2.18 npm/? node/v24.3.0 darwin arm64".startsWith("yarn"))return"yarn";if("bun/1.2.18 npm/? node/v24.3.0 darwin arm64".startsWith("pnpm"))return"pnpm";if("bun/1.2.18 npm/? node/v24.3.0 darwin arm64".startsWith("bun"))return"bun";return"npm"}function Q0(){switch(C()){case"yarn":return"yarn";case"pnpm":return"pnpx";case"bun":return"bunx";default:return"npx"}}function t0(){switch(C()){case"yarn":return"yarn dev";case"pnpm":return"pnpm dev";case"bun":return"bun dev";default:return"npm run dev"}}function V0(Q){return Q.replace(/^[ \t]*\/\/\s*(TODO:|collapse-(start|end)).*\r?\n?|[ \t]*{\s*\/\*\s*(TODO:|collapse-(start|end)).*?\*\/\s*}\r?\n?/gm,"")}var D3=D.join(E3.homedir(),".untitledui"),l=D.join(D3,"config.json"),X={components:[],path:"",type:void 0,license:""};if(F.existsSync(l)){let Q=JSON.parse(F.readFileSync(l,"utf-8"));X.license=Q.license}var B0=(Q)=>{if(Q.aborted)process.stdout.write("\x1B[?25h"),process.stdout.write(`
3
+ `),process.exit(1)},e0=new y3().name("add").description("add a component to your project").argument("[components...]","the components to add").option("-a, --all","add all available components",!1).option("-o, --overwrite","overwrite existing files.",!1).option("-p, --path <path>","the path to add the component to.").option("-d, --dir <directory>","the directory where the project is located.").option("-t, --type <base|marketing|shared-assets|application|foundations>","the type of the component to add.").action(async(Q,W)=>{if(Q)X.components=Q;if(W)X.all=W.all,X.dir=W.dir,X.path=W.path,X.overwrite=W.overwrite,X.license=W.license||X.license;try{await N0(X)}catch(z){console.error(y.red(z))}});async function N0(Q){if(Q)X={...X,...Q};let W=q0().start(),z=D.posix.join(process.cwd(),X.dir||"");if(!F.existsSync(D.resolve(z,"package.json")))W.warn("This command should be run in a project directory."),process.exit(1);let Z=await o(z);if(X.license){if(!await U0(X.license))W.fail("Invalid license key"),process.exit(1);if(!F.existsSync(l)){let V=D.dirname(l);F.mkdirSync(V,{recursive:!0}),F.writeFileSync(l,JSON.stringify({license:X.license},null,2))}if(JSON.parse(F.readFileSync(l,"utf-8")).license!==X.license)F.writeFileSync(l,JSON.stringify({license:X.license},null,2),"utf-8")}if(W.stop(),!Z?.tailwind.brandColor)console.log(y.red("The project does not seem to be configured with Untitled UI Tailwind. Please follow the setup instructions in the documentation: https://www.untitledui.com/react/docs or run init command.")),process.exit(1);let B=[];if(X.components.length){let Y=await K0(X.type,X.components,X.license);if(Y&&Y.pro&&Y.pro.length>0){if(console.log(),Y.pro.length===1){let $=Y.pro[0]?.split("/")[1]||Y.pro[0];console.log(y.yellow(`\uD83D\uDD12 The ${y.cyan($)} component requires PRO access.`))}else console.log(y.yellow("\uD83D\uDD12 The following components require PRO access:")),Y.pro.forEach(($)=>{let V=$?.split("/")[1]||$;console.log(` • ${y.cyan(V)}`)});console.log(),console.log("To access PRO components:"),console.log(` ${y.green("→")} If you've already purchased: ${y.cyan(`${Q0()} untitledui@latest login`)}`),console.log(` ${y.green("→")} To purchase PRO components: ${y.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(!Y?.components.length)console.log("No components found"),process.exit(1);B.push(...Y.components)}if(!X?.type&&!X?.components.length){let Y=await a0(X.license);if(!Y)console.log("No component types found"),process.exit(1);let $=await W0({type:"select",name:"type",onState:B0,message:`What type of ${y.cyan("component")} are you adding?`,choices:Y?.types.map((V)=>({title:V,value:V}))});X.type=$.type}if(!X?.path){let Y=await W0({type:"text",name:"path",onState:B0,message:`Where would you like to add the ${y.cyan("components")}?`,initial:"components"});X.path=Y.path}if(!X?.components.length){let Y=await c0(X?.type,X.license);if(!Y)console.log("No components found"),process.exit(1);let $=await W0({type:"multiselect",name:"components",onState:B0,message:`Which ${y.cyan("components")} would you like to add?`,choices:Y?.components?.map((L)=>({title:L?.name+(L?.count?` (${L?.count} variants)`:"")||"example",value:L||"example",selected:X.components.includes(L.name)})),instructions:!1,hint:"- Space to select. Return to submit"});if(!$.components||!$.components.length)console.log("No option selected. Exiting..."),process.exit(1);let V=$.components.filter((L)=>L?.type==="file").map((L)=>L.name),E=$.components.filter((L)=>L?.type==="dir").map((L)=>L.name),S=[];if(E.length){let L=await l0(X?.type,X.license,E);if(L&&L.components.length)for(let j of L.components){let[N,k]=Object.entries(j)[0]||[],T=await W0({type:"select",name:"component",onState:B0,message:`Which ${y.cyan("variant")} from ${y.cyan(N)} would you like to add?`,choices:k?.map((g)=>({title:g?.name.replace(/-modal/g,"")||"example",value:g?.name||"example",selected:X.components.includes(g.name)})),instructions:!1,hint:"- Space to select. Return to submit"});if(!T.component)console.log("No variant selected for "+y.cyan(N));S.push(N+"/"+T.component)}else console.log("No variants found")}X.components=[...S,...V]}if(!X.components?.length)W.warn("No components selected. Exiting."),process.exit(1);let u=e(z),G=new Set,U=new Set,H=new Set,b=new _3({tsConfigFilePath:u?.tsConfig});if(W.start(),X.type&&X.components.length){let Y=await K0(X.type,X.components,X.license);if(!Y?.components.length)console.log("No components found"),process.exit(1);B.push(...Y.components)}let I=new Set;if(B.forEach((Y)=>{Y?.components?.forEach(($)=>{I.add({name:$.name,path:$.path})})}),W.stop(),I.size){let Y=Array.from(I).filter(($)=>!F.existsSync(D.posix.join(z,`${Z?.isSrcDir?"src":""}`,$?.path?.replace(/components\//,X.path+"/"))));if(Y?.length){let $=await W0({type:"multiselect",name:"baseComponents",onState:B0,message:"Select which base components you want to add",choices:Y.map((V)=>({title:V?.name,value:V?.name,selected:!0})),instructions:!1,hint:"- Space to select. Return to submit"});if(X.baseComponents=$.baseComponents,!Y.length&&!$.baseComponents?.length)W.warn("No components selected")}}if(W.start(),X?.baseComponents?.length){let Y=await K0("",X.baseComponents,X.license);if(!Y||!Y?.components.length)console.log("No base components found");else B.push(...Y.components)}if(W.stop(),B.forEach((Y)=>{let $=q0(`Adding ${Y.name}...`).start(),V=Y.files;Y?.dependencies?.forEach((E)=>U.add(E)),Y?.devDependencies?.forEach((E)=>H.add(E));try{if(V?.forEach(async({path:E,code:S})=>{let L=D.posix.join(z,`${Z?.isSrcDir?"src":""}`,E.replace(/components\//,X.path+"/")),j=Z?.framework==="vite"?S.replace(`"use client";
4
4
 
5
- `,""):x,k=b3(D),u=T.dirname(V);if(F.existsSync(V)&&!B.overwrite){if(F.readFileSync(V,"utf-8")!==k)j.add({code:k,path:V})}else{F.mkdirSync(u,{recursive:!0}),F.writeFileSync(V,k);let I=T.relative(T.posix.join(z,`${$?.isSrcDir?"src":""}`),V).split("/").length,P=I===1?"./":"../".repeat(I-1),O=S.addSourceFileAtPath(T.resolve(V));O.getImportDeclarations().forEach((i)=>{let g=i.getModuleSpecifierValue();i.setModuleSpecifier(e(g,B.path,$?.aliasPrefix,P))}),await O.save()}}),j.size)Z.warn(`Some files of ${N.yellow(Y.name)} already exist`);else Z.succeed(`${N.green(Y.name)} is added successfully`)}catch(R){Z.fail(`
6
- Failed to add the component ${N.red(Y.name)}`),console.error(N.red(R)),process.exit(1)}}),j.size&&!B?.overwrite)if(console.log(`
7
- Following files already exist in the directory.`),j.forEach((Z)=>{console.log(N.green(`- ${T.relative(z,Z.path)}`))}),(await Q3({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0})).overwrite){let Z=Z3("Overwriting files").start();j.forEach((K)=>{let R=T.relative(T.resolve(z,`${$?.isSrcDir?"src":""}`,B.path),K.path).split("/").length,x=R===1?"./":"../".repeat(R-1),V=S.addSourceFileAtPath(T.resolve(K.path));V.replaceWithText(K.code),V.getImportDeclarations().forEach((D)=>{let k=D.getModuleSpecifierValue();D.setModuleSpecifier(e(k,B.path,$?.aliasPrefix,x))}),V.saveSync()}),Z.succeed("Files are overwritten")}else console.log(`Use ${N.cyan("--overwrite")} or ${N.cyan("-o")} to overwrite existing files, or refer to the documentation ${N.cyan("https://www.untitled.com/docs")} for manual installation. The rest of the files are added.`);let U=C();if(b?.size){let Y=Z3("Installing component dependencies").start();await o3(()=>L3(U,[U==="npm"?"install":"add",...b],{cwd:z}).catch(async(Z)=>{if(Z.message.includes("peer"))Y.warn("Component dependencies conflict detected. Retrying with --legacy-peer-deps..."),Y.start("Installing component dependencies with --legacy-peer-deps flag"),await L3(U,[U==="npm"?"install":"add",...b,"--legacy-peer-deps"],{cwd:z})}),{retries:1}),Y.succeed("Component dependencies are installed")}if(y?.size){let Y=Z3("Installing component devDependencies").start();await o3(()=>L3(U,[U==="npm"?"install":"add","-D",...y],{cwd:z}).catch(async(Z)=>{if(Z.message.includes("peer"))Y.warn("Component devDependencies conflict detected. Retrying with --legacy-peer-deps..."),Y.start("Installing component devDependencies with --legacy-peer-deps flag"),await L3(U,[U==="npm"?"install":"add","-D",...y,"--legacy-peer-deps"],{cwd:z})}),{retries:1}),Y.succeed("Component devDependencies are installed")}if(B.message)console.log(B.message);process.exit(0)}import T3 from"chalk";import{Command as T0}from"commander";import*as f from"fs";import w0 from"http";import S0 from"open";import x0 from"ora";import C0 from"os";import*as S3 from"path";import{URL as F0}from"url";import*as M3 from"fs";import*as l from"path";import{fileURLToPath as E0}from"url";var _0=E0(import.meta.url),_3=l.dirname(_0);function D0(){let W=[l.join(_3,"..","templates","auth-template.html"),l.join(_3,"templates","auth-template.html"),l.join(process.cwd(),"node_modules","untitledui","templates","auth-template.html"),l.join(_3,"..","..","templates","auth-template.html")];for(let Q of W)if(M3.existsSync(Q))return Q;throw new Error("Auth template file not found. Please ensure the CLI package is properly installed.")}function e3(){try{let W=D0();return M3.readFileSync(W,"utf-8")}catch(W){return console.warn("Warning: Using fallback auth template. Some styling may be missing."),`<!doctype html>
5
+ `,""):S,N=V0(j),k=D.dirname(L);if(F.existsSync(L)&&!X.overwrite){if(F.readFileSync(L,"utf-8")!==N)G.add({code:N,path:L})}else{F.mkdirSync(k,{recursive:!0}),F.writeFileSync(L,N);let T=D.relative(D.posix.join(z,`${Z?.isSrcDir?"src":""}`),D.dirname(L)).split("/").length,g=T===1?"./":"../".repeat(T-1),P=b.addSourceFileAtPath(D.resolve(L));P.getImportDeclarations().forEach((h0)=>{let U3=h0.getModuleSpecifierValue();h0.setModuleSpecifier(z0(U3,X.path,Z?.aliases,g))}),await P.save()}}),G.size)$.warn(`Some files of ${y.yellow(Y.name)} already exist`);else $.succeed(`${y.green(Y.name)} is added successfully`)}catch(E){$.fail(`
6
+ Failed to add the component ${y.red(Y.name)}`),console.error(y.red(E)),process.exit(1)}}),G.size&&!X?.overwrite)if(console.log(`
7
+ Following files already exist in the directory.`),G.forEach(($)=>{console.log(y.green(`- ${D.relative(z,$.path)}`))}),(await W0({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0})).overwrite){let $=q0("Overwriting files").start();G.forEach((V)=>{let E=D.relative(D.resolve(z,`${Z?.isSrcDir?"src":""}`,X.path),D.dirname(V.path)).split("/").length,S=E===1?"./":"../".repeat(E-1),L=b.addSourceFileAtPath(D.resolve(V.path));L.replaceWithText(V.code),L.getImportDeclarations().forEach((j)=>{let N=j.getModuleSpecifierValue();j.setModuleSpecifier(z0(N,X.path,Z?.aliases,S))}),L.saveSync()}),$.succeed("Files are overwritten")}else console.log(`Use ${y.cyan("--overwrite")} or ${y.cyan("-o")} to overwrite existing files, or refer to the documentation ${y.cyan("https://www.untitled.com/docs")} for manual installation. The rest of the files are added.`);let K=C();if(U?.size){let Y=q0("Installing component dependencies").start();await o0(()=>L0(K,[K==="npm"?"install":"add",...U],{cwd:z}).catch(async($)=>{if($.message.includes("peer"))Y.warn("Component dependencies conflict detected. Retrying with --legacy-peer-deps..."),Y.start("Installing component dependencies with --legacy-peer-deps flag"),await L0(K,[K==="npm"?"install":"add",...U,"--legacy-peer-deps"],{cwd:z})}),{retries:1}),Y.succeed("Component dependencies are installed")}if(H?.size){let Y=q0("Installing component devDependencies").start();await o0(()=>L0(K,[K==="npm"?"install":"add","-D",...H],{cwd:z}).catch(async($)=>{if($.message.includes("peer"))Y.warn("Component devDependencies conflict detected. Retrying with --legacy-peer-deps..."),Y.start("Installing component devDependencies with --legacy-peer-deps flag"),await L0(K,[K==="npm"?"install":"add","-D",...H,"--legacy-peer-deps"],{cwd:z})}),{retries:1}),Y.succeed("Component devDependencies are installed")}if(X.message)console.log(X.message);process.exit(0)}import E0 from"chalk";import{Command as S3}from"commander";import*as d from"fs";import C3 from"http";import F3 from"open";import k3 from"ora";import P3 from"os";import*as D0 from"path";import{URL as g3}from"url";import*as b0 from"fs";import*as a from"path";import{fileURLToPath as T3}from"url";var w3=T3(import.meta.url),A0=a.dirname(w3);function x3(){let Q=[a.join(A0,"..","templates","auth-template.html"),a.join(A0,"templates","auth-template.html"),a.join(process.cwd(),"node_modules","untitledui","templates","auth-template.html"),a.join(A0,"..","..","templates","auth-template.html")];for(let W of Q)if(b0.existsSync(W))return W;throw new Error("Auth template file not found. Please ensure the CLI package is properly installed.")}function z3(){try{let Q=x3();return b0.readFileSync(Q,"utf-8")}catch(Q){return console.warn("Warning: Using fallback auth template. Some styling may be missing."),`<!doctype html>
8
8
  <html lang="en">
9
9
  <head>
10
10
  <meta charset="UTF-8" />
@@ -50,31 +50,31 @@ Following files already exist in the directory.`),j.forEach((Z)=>{console.log(N.
50
50
  {{AUTO_CLOSE_SCRIPT}}
51
51
  </div>
52
52
  </body>
53
- </html>`}}function z0(){return e3().replace("{{TITLE}}","Authentication successful").replace("{{HEADING}}","Authentication successful").replace("{{DESCRIPTION}}","You can now close this tab and return to your terminal.").replace("{{AUTO_CLOSE_SCRIPT}}","<script>setTimeout(() => window.close(), 10000);</script>")}function j3(W){return e3().replace("{{TITLE}}","Authentication failed").replace("{{HEADING}}","Authentication failed").replace("{{DESCRIPTION}}",W).replace("{{AUTO_CLOSE_SCRIPT}}","")}var w3=S3.join(C0.homedir(),".untitledui"),D3=S3.join(w3,"config.json"),Q0=new T0().name("login").description("authenticate with Untitled UI to access PRO components").action(async()=>{let W=x0("Starting authentication...").start();try{await k0(W),W.succeed("Authentication completed successfully!"),console.log(T3.green(`
54
- ✨ You can now access PRO components with the CLI!`)),process.exit(0)}catch(Q){W.fail(`Authentication failed: ${Q instanceof Error?Q.message:Q}`),process.exit(1)}});async function k0(W){return new Promise((Q,z)=>{let X=w0.createServer(($,q)=>{let L=new F0($.url,"http://localhost");if(L.pathname==="/callback"){let j=L.searchParams.get("apiKey"),b=L.searchParams.get("error");if(b){q.writeHead(400,{"Content-Type":"text/html"}),q.end(j3(decodeURIComponent(b))),X.close(),z(new Error(decodeURIComponent(b)));return}if(!j){q.writeHead(400,{"Content-Type":"text/html"}),q.end(j3("No Access Token received")),X.close(),z(new Error("No Access Token received"));return}try{P0(j),q.writeHead(200,{"Content-Type":"text/html"}),q.end(z0()),X.close(),Q()}catch(y){q.writeHead(500,{"Content-Type":"text/html"}),q.end(j3("Failed to save authentication data")),X.close(),z(y)}}else q.writeHead(404),q.end("Not found")});X.listen(0,"localhost",()=>{let L=`https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api/cli-auth?port=${X.address().port}`;W.text="Opening browser for authentication...",S0(L).catch((j)=>{console.log(T3.yellow(`
55
- Failed to open browser automatically: ${j.message}`)),console.log(T3.cyan(`Please manually open: ${L}
56
- `))}),W.text="Waiting for authentication in browser..."}),setTimeout(()=>{X.close(),z(new Error("Authentication timeout. Please try again."))},300000)})}function P0(W){if(!f.existsSync(w3))f.mkdirSync(w3,{recursive:!0});let Q={};if(f.existsSync(D3))try{Q=JSON.parse(f.readFileSync(D3,"utf-8"))}catch{Q={}}Q.license=W,f.writeFileSync(D3,JSON.stringify(Q,null,2),"utf-8")}import g3 from"async-retry";import M from"chalk";import{Command as l0}from"commander";import{execa as I3}from"execa";import*as w from"fs";import X3 from"ora";import a0 from"os";import*as v from"path";import r from"prompts";import{Project as s0}from"ts-morph";import O0 from"node-fetch";async function H3(W,Q){try{let X=await O0("https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api/components/example",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({example:W,key:Q})});if(!X.ok){if(X.status===401||X.status===403)return{type:"error",status:X.status,message:"PRO access required"};return console.error(`API error: ${X.status} - ${X.statusText}`),null}return await X.json()}catch(X){return console.error(X?.message||"Error fetching example data."),null}}import q3 from"async-retry";import A from"chalk";import{Command as g0}from"commander";import{execa as a}from"execa";import R3 from"fast-glob";import _ from"fs";import W3 from"ora";import d0 from"os";import*as G from"path";import u3 from"prompts";import{Project as h0}from"ts-morph";import{fileURLToPath as f0}from"url";import*as v3 from"fs";import*as W0 from"path";function x3(W,Q){let z=W0.join(W,"package.json");if(!v3.existsSync(z))return Q;let X=JSON.parse(v3.readFileSync(z,"utf-8")),$={...X.dependencies,...X.devDependencies},q=[];for(let L of Q){let j=$[L];if(!j){q.push(L);continue}if(L==="tailwindcss"){let b=j.match(/\d+/);if((b?parseInt(b[0],10):0)<4)q.push(L)}}return q}import C3 from"chalk";import*as m from"fs";import*as G3 from"path";function F3(W){if(!m.existsSync(G3.resolve(W)))console.log(C3.red(`Error: CSS file not found at ${W}`)),process.exit(1);let Q=m.readFileSync(G3.resolve(W),"utf-8"),z=/(--color-[a-zA-Z-]+-\d{1,3}):\s*(rgb\([^)]+\))/g,X={},$;while(($=z.exec(Q))!==null)if($[1]&&$[2])X[$[1]]=$[2];return X}function k3(W,Q,z){let X=G3.resolve(z);if(!m.existsSync(X)){console.log(C3.red(`Error: CSS file not found at ${X}`));return}let $=m.readFileSync(X,"utf-8"),q=F3(z),L={},j={};for(let[y,S]of Object.entries(q))if(y.startsWith(`--color-${W}-`)){let E=y.replace(`--color-${W}-`,"");L[E]=y}else if(y.startsWith(`--color-${Q}-`)){let E=y.replace(`--color-${Q}-`,"");j[E]=S}let b=!1;for(let[y,S]of Object.entries(L))if(j[y]){let E=j[y],U=new RegExp(`(${S}):\\s*rgb\\([^)]*\\);?`,"g");if(U.test($))$=$.replace(U,`$1: ${E};`),b=!0;else console.log(C3.yellow(`No match found for ${S}`))}if(b)m.writeFileSync(X,$,"utf-8")}var m0=f0(import.meta.url),Y0=G.dirname(m0),c0=G.join(d0.homedir(),".untitledui"),s=G.join(c0,"config.json"),$0="vite",q0="nextjs",Z0={[q0]:"Next.js",[$0]:"Vite"},h="",H={color:"",template:"",framework:void 0};if(_.existsSync(s)){let W=JSON.parse(_.readFileSync(s,"utf-8"));H.license=W.license}var P3=(W)=>{if(W.aborted)process.stdout.write("\x1B[?25h"),process.stdout.write(`
57
- `),process.exit(1)},X0=new g0().name("init").description("initialize a new project or adjust an existing one").argument("[directory]").usage("[directory] [options]").helpOption("-h, --help","display this help message.").option("--vite","initialize a Vite project.",!1).option("--nextjs","initialize a Next.js project.",!1).option("-o, --overwrite","overwrite existing files.",!1).option("--colors-list","show the colors list.",!1).option("-c, --color <color-name>","specify a color for the project.").action(async(W,Q)=>{if(W)h=W;if(Q){if(H.color=Q.color,H.template=Q.template,H.overwrite=Q.overwrite,H.colorsList=Q.colorsList,H.license=Q.license||H.license,H.vite=Q.vite,H.nextjs=Q.nextjs,Q.vite)H.framework=$0;if(Q.nextjs)H.framework=q0}try{await O3(Q),process.exit(0)}catch(z){console.error(A.red(z)),process.exit(1)}});async function O3(W,Q=null){let z=process.cwd(),X=_.existsSync(G.resolve(z,"package.json")),$=G.resolve(G.join(Y0,"../config/styles","theme.css")),q=F3($??""),L=Array.from(new Set(Object.keys(q).map((U)=>U?.split("--color-")?.[1]?.replace(/-\d{1,3}/,"")))),j=W3().start(),b=await o(z),y=X?R3.sync(["**/**/theme.css"],{cwd:z,absolute:!0,onlyFiles:!0,ignore:d}):[],S=y?.[0]&&_.readFileSync(y[0],"utf-8").match(/(--color-brand+-\d{1,3}):\s*(rgb\([^)]+\))/g)?.[1]||void 0;if(H.license){if(!_.existsSync(s)){let Y=G.dirname(s);_.mkdirSync(Y,{recursive:!0}),_.writeFileSync(s,JSON.stringify({license:H.license},null,2))}if(JSON.parse(_.readFileSync(s,"utf-8")).license!==H.license)_.writeFileSync(s,JSON.stringify({license:H.license},null,2))}if(!X){if(j.stop(),!h){let U=await u3({onState:P3,type:"text",name:"path",message:"What is your project named?",initial:"untitled-ui"});if(typeof U.path==="string")h=U.path.trim()}if(Q)Q.projectPath=h;if(_.existsSync(G.resolve(G.posix.join(z,h))))j.fail(A.red("Directory already exists!")),process.exit(1);if(H.vite&&H.nextjs||!H.framework){let U=await u3({type:"select",name:"framework",onState:P3,message:`Which ${A.cyan("framework")} would you like to use?`,choices:Object.entries(Z0).map(([Y,Z])=>({title:Z,value:Y}))});H.framework=U.framework}j.succeed("Framework is selected: "+A.green(Z0[H.framework]))}else if(b?.framework==="other")j.fail("Unsupported project framework"),console.log(`Please refer to the documentation ${A.cyan("https://www.untitled.com/docs")} for supported frameworks or proceed with manual installation.`),process.exit(1);else if(b?.framework.startsWith("next")||b?.framework.startsWith("vite"))if(!Q&&!S)j.succeed(A.yellow(`Detected ${r3[b.framework]} project, proceeding with the setup...`));else j.stop();if(H.colorsList||!H.color&&!S){let U=await u3({type:"select",name:"color",onState:P3,initial:W.color??"",message:`Which ${A.cyan("color")} would you like to use as the ${A.cyanBright("brand")} color?`,choices:L.map((Y)=>({title:Y,value:Y}))});H.color=U.color}let E=G.posix.join(z,h||"");if(h&&!X){let U=G.resolve(h);console.log(`
58
- Creating a new project in ${A.blue(h)}`);let Y=W3("Downloading and extracting the repository...").start();try{_.mkdirSync(U,{recursive:!0}),await q3(()=>m3(U,{template:H.framework}),{retries:2}),Y.succeed("Files are downloaded and extracted successfully!");let Z=W3({text:"Installing dependencies..."}).start(),K=R3.sync(["**/styles/theme.css"],{cwd:U,absolute:!0,onlyFiles:!0})[0];if(k3("brand",H.color||"",K??""),await q3(()=>a(C(),["install"],{cwd:E}).catch(async(R)=>{if(R.message.includes("peer"))Z.warn("Dependency conflict detected. Retrying with --legacy-peer-deps..."),Z.start("Installing dependencies with --legacy-peer-deps flag"),await a(C(),["install","--legacy-peer-deps"],{cwd:E})}),{retries:1}),await q3(()=>a("git",["init"],{cwd:E}),{retries:1}),Z.succeed("Dependencies are installed"),!Q)console.log(`
53
+ </html>`}}function Q3(){return z3().replace("{{TITLE}}","Authentication successful").replace("{{HEADING}}","Authentication successful").replace("{{DESCRIPTION}}","You can now close this tab and return to your terminal.").replace("{{AUTO_CLOSE_SCRIPT}}","<script>setTimeout(() => window.close(), 10000);</script>")}function M0(Q){return z3().replace("{{TITLE}}","Authentication failed").replace("{{HEADING}}","Authentication failed").replace("{{DESCRIPTION}}",Q).replace("{{AUTO_CLOSE_SCRIPT}}","")}var _0=D0.join(P3.homedir(),".untitledui"),y0=D0.join(_0,"config.json"),W3=new S3().name("login").description("authenticate with Untitled UI to access PRO components").action(async()=>{let Q=k3("Starting authentication...").start();try{await O3(Q),Q.succeed("Authentication completed successfully!"),console.log(E0.green(`
54
+ ✨ You can now access PRO components with the CLI!`)),process.exit(0)}catch(W){Q.fail(`Authentication failed: ${W instanceof Error?W.message:W}`),process.exit(1)}});async function O3(Q){return new Promise((W,z)=>{let q=C3.createServer((Z,B)=>{let u=new g3(Z.url,"http://localhost");if(u.pathname==="/callback"){let G=u.searchParams.get("apiKey"),U=u.searchParams.get("error");if(U){B.writeHead(400,{"Content-Type":"text/html"}),B.end(M0(decodeURIComponent(U))),q.close(),z(new Error(decodeURIComponent(U)));return}if(!G){B.writeHead(400,{"Content-Type":"text/html"}),B.end(M0("No Access Token received")),q.close(),z(new Error("No Access Token received"));return}try{h3(G),B.writeHead(200,{"Content-Type":"text/html"}),B.end(Q3()),q.close(),W()}catch(H){B.writeHead(500,{"Content-Type":"text/html"}),B.end(M0("Failed to save authentication data")),q.close(),z(H)}}else B.writeHead(404),B.end("Not found")});q.listen(0,"localhost",()=>{let u=`https://www.untitledui.com/react/api/cli-auth?port=${q.address().port}`;Q.text="Opening browser for authentication...",F3(u).catch((G)=>{console.log(E0.yellow(`
55
+ Failed to open browser automatically: ${G.message}`)),console.log(E0.cyan(`Please manually open: ${u}
56
+ `))}),Q.text="Waiting for authentication in browser..."}),setTimeout(()=>{q.close(),z(new Error("Authentication timeout. Please try again."))},300000)})}function h3(Q){if(!d.existsSync(_0))d.mkdirSync(_0,{recursive:!0});let W={};if(d.existsSync(y0))try{W=JSON.parse(d.readFileSync(y0,"utf-8"))}catch{W={}}W.license=Q,d.writeFileSync(y0,JSON.stringify(W,null,2),"utf-8")}import P0 from"async-retry";import M from"chalk";import{Command as r3}from"commander";import{execa as I0}from"execa";import*as x from"fs";import J0 from"ora";import n3 from"os";import*as R from"path";import n from"prompts";import{Project as i3}from"ts-morph";import d3 from"node-fetch";async function j0(Q,W){try{let q=await d3("https://www.untitledui.com/react/api/components/example",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({example:Q,key:W})});if(!q.ok){if(q.status===401||q.status===403)return{type:"error",status:q.status,message:"PRO access required"};return console.error(`API error: ${q.status} - ${q.statusText}`),null}return await q.json()}catch(q){return console.error(q?.message||"Error fetching example data."),null}}import X0 from"async-retry";import _ from"chalk";import{Command as f3}from"commander";import{execa as s}from"execa";import C0 from"fast-glob";import w from"fs";import Y0 from"ora";import m3 from"os";import*as A from"path";import R0 from"prompts";import{Project as c3}from"ts-morph";import{fileURLToPath as l3}from"url";import*as H0 from"fs";import*as Y3 from"path";function T0(Q,W){let z=Y3.join(Q,"package.json");if(!H0.existsSync(z))return W;let q=JSON.parse(H0.readFileSync(z,"utf-8")),Z={...q.dependencies,...q.devDependencies},B=[];for(let u of W){let G=Z[u];if(!G){B.push(u);continue}if(u==="tailwindcss"){let U=G.match(/\d+/);if((U?parseInt(U[0],10):0)<4)B.push(u)}}return B}import w0 from"chalk";import*as c from"fs";import*as G0 from"path";function x0(Q){if(!c.existsSync(G0.resolve(Q)))console.log(w0.red(`Error: CSS file not found at ${Q}`)),process.exit(1);let W=c.readFileSync(G0.resolve(Q),"utf-8"),z=/(--color-[a-zA-Z-]+-\d{1,3}):\s*(rgb\([^)]+\))/g,q={},Z;while((Z=z.exec(W))!==null)if(Z[1]&&Z[2])q[Z[1]]=Z[2];return q}function S0(Q,W,z){let q=G0.resolve(z);if(!c.existsSync(q)){console.log(w0.red(`Error: CSS file not found at ${q}`));return}let Z=c.readFileSync(q,"utf-8"),B=x0(z),u={},G={};for(let[H,b]of Object.entries(B))if(H.startsWith(`--color-${Q}-`)){let I=H.replace(`--color-${Q}-`,"");u[I]=H}else if(H.startsWith(`--color-${W}-`)){let I=H.replace(`--color-${W}-`,"");G[I]=b}let U=!1;for(let[H,b]of Object.entries(u))if(G[H]){let I=G[H],K=new RegExp(`(${b}):\\s*rgb\\([^)]*\\);?`,"g");if(K.test(Z))Z=Z.replace(K,`$1: ${I};`),U=!0;else console.log(w0.yellow(`No match found for ${b}`))}if(U)c.writeFileSync(q,Z,"utf-8")}var a3=l3(import.meta.url),Z3=A.dirname(a3),s3=A.join(m3.homedir(),".untitledui"),r=A.join(s3,"config.json"),q3="vite",B3="nextjs",$3={[B3]:"Next.js",[q3]:"Vite"},h="",v={color:"",template:"",framework:void 0};if(w.existsSync(r)){let Q=JSON.parse(w.readFileSync(r,"utf-8"));v.license=Q.license}var F0=(Q)=>{if(Q.aborted)process.stdout.write("\x1B[?25h"),process.stdout.write(`
57
+ `),process.exit(1)},X3=new f3().name("init").description("initialize a new project or adjust an existing one").argument("[directory]").usage("[directory] [options]").helpOption("-h, --help","display this help message.").option("--vite","initialize a Vite project.",!1).option("--nextjs","initialize a Next.js project.",!1).option("-o, --overwrite","overwrite existing files.",!1).option("--colors-list","show the colors list.",!1).option("-c, --color <color-name>","specify a color for the project.").action(async(Q,W)=>{if(Q)h=Q;if(W){if(v.color=W.color,v.template=W.template,v.overwrite=W.overwrite,v.colorsList=W.colorsList,v.license=W.license||v.license,v.vite=W.vite,v.nextjs=W.nextjs,W.vite)v.framework=q3;if(W.nextjs)v.framework=B3}try{await k0(W),process.exit(0)}catch(z){console.error(_.red(z)),process.exit(1)}});async function k0(Q,W=null){let z=process.cwd(),q=w.existsSync(A.resolve(z,"package.json")),Z=A.resolve(A.join(Z3,"../config/styles","theme.css")),B=x0(Z??""),u=Array.from(new Set(Object.keys(B).map((b)=>b?.split("--color-")?.[1]?.replace(/-\d{1,3}/,"")))),G=Y0().start(),U=await o(z);if(v.license){if(!w.existsSync(r)){let I=A.dirname(r);w.mkdirSync(I,{recursive:!0}),w.writeFileSync(r,JSON.stringify({license:v.license},null,2))}if(JSON.parse(w.readFileSync(r,"utf-8")).license!==v.license)w.writeFileSync(r,JSON.stringify({license:v.license},null,2))}if(!q){if(G.stop(),!h){let b=await R0({onState:F0,type:"text",name:"path",message:"What is your project named?",initial:"untitled-ui"});if(typeof b.path==="string")h=b.path.trim()}if(W)W.projectPath=h;if(w.existsSync(A.resolve(A.posix.join(z,h))))G.fail(_.red("Directory already exists!")),process.exit(1);if(v.vite&&v.nextjs||!v.framework){let b=await R0({type:"select",name:"framework",onState:F0,message:`Which ${_.cyan("framework")} would you like to use?`,choices:Object.entries($3).map(([I,K])=>({title:K,value:I}))});v.framework=b.framework}G.succeed("Framework is selected: "+_.green($3[v.framework]))}else if(U?.framework==="other")G.fail("Unsupported project framework"),console.log(`Please refer to the documentation ${_.cyan("https://www.untitled.com/docs")} for supported frameworks or proceed with manual installation.`),process.exit(1);else if(U?.framework.startsWith("next")||U?.framework.startsWith("vite"))if(!W&&!U.tailwind.brandColor)G.succeed(_.yellow(`Detected ${n0[U.framework]} project, proceeding with the setup...`));else G.stop();if(v.colorsList||!v.color&&!U?.tailwind.brandColor){let b=await R0({type:"select",name:"color",onState:F0,initial:Q.color??"",message:`Which ${_.cyan("color")} would you like to use as the ${_.cyanBright("brand")} color?`,choices:u.map((I)=>({title:I,value:I}))});if(v.color=b.color,v.colorsList&&U)U.tailwind.brandColor=b.color}let H=A.posix.join(z,h||"");if(h&&!q){let b=A.resolve(h);console.log(`
58
+ Creating a new project in ${_.blue(h)}`);let I=Y0("Downloading and extracting the repository...").start();try{w.mkdirSync(b,{recursive:!0}),await X0(()=>f0(b,{template:v.framework}),{retries:2}),I.succeed("Files are downloaded and extracted successfully!");let K=Y0({text:"Installing dependencies..."}).start(),Y=C0.sync(["**/styles/theme.css"],{cwd:b,absolute:!0,onlyFiles:!0})[0];if(S0("brand",v.color||"",Y??""),await X0(()=>s(C(),["install"],{cwd:H}).catch(async($)=>{if($.message.includes("peer"))K.warn("Dependency conflict detected. Retrying with --legacy-peer-deps..."),K.start("Installing dependencies with --legacy-peer-deps flag"),await s(C(),["install","--legacy-peer-deps"],{cwd:H})}),{retries:1}),await X0(()=>s("git",["init"],{cwd:H}),{retries:1}),K.succeed("Dependencies are installed"),!W)console.log(`
59
59
  Your project is ready, to get started run the following commands:
60
60
 
61
- cd ${A.cyan(h)}
62
- ${A.cyan(p3())}`)}catch(Z){if(Y.fail(A.red(`
63
- Failed to download and extract the repository`)),Z instanceof Error)console.error(Z.message);else console.error(`
64
- `);_.rmdirSync(U,{recursive:!0}),process.exit(1)}}else{let U=W3(),Y=new Set,Z=t(z),K=G.resolve(G.join(Y0,"../config")),R=R3.sync(["**"],{cwd:K,onlyFiles:!0,ignore:d}),x=x3(z,["tailwindcss","tailwindcss-animate","@tailwindcss/typography","tailwindcss-react-aria-components"]),V=x3(z,["@tailwindcss/postcss","postcss"]);if(!Q&&!S)U.start("Copying files to the project directory");if(R.forEach((u)=>{let I=u.includes("postcss.config"),P=G.posix.join(G.posix.join(K),u),O=G.posix.join(z,I?u:`${b?.isSrcDir?"src":""}/${u}`);if(_.existsSync(O)){if(H?.overwrite)_.copyFileSync(P,O);else{let i=_.readFileSync(O,"utf-8"),g=_.readFileSync(P,"utf-8");if(i!==g){if(u.endsWith("theme.css")&&S)return;Y.add({targetFile:O,sourceFile:P})}}return}_.mkdirSync(G.dirname(O),{recursive:!0}),_.writeFileSync(O,""),_.copyFileSync(P,O)}),U.stop(),Y.size&&!H?.overwrite)if(console.log(`
65
- `),U.fail("Following files already exist in the directory."),Y.forEach((I)=>{console.log(`- ${A.green(I.targetFile)}`)}),(await u3({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0})).overwrite){let I=W3("Overwriting files").start();Y.forEach((P)=>{_.copyFileSync(P.sourceFile,P.targetFile)}),I.succeed("Files are overwritten")}else console.log(`Use ${A.cyan("--overwrite")} or ${A.cyan("-o")} to overwrite existing files, or refer to the documentation ${A.cyan("https://www.untitled.com/docs")} for manual installation. The rest of the files are added.`);if(Z?.tailwindFile)console.log(`
61
+ cd ${_.cyan(h)}
62
+ ${_.cyan(t0())}`)}catch(K){if(I.fail(_.red(`
63
+ Failed to download and extract the repository`)),K instanceof Error)console.error(K.message);else console.error(`
64
+ `);w.rmdirSync(b,{recursive:!0}),process.exit(1)}}else{let b=Y0(),I=new Set,K=e(z),Y=A.resolve(A.join(Z3,"../config")),$=C0.sync(["**"],{cwd:Y,onlyFiles:!0,ignore:O}),V=T0(z,["tailwindcss","tailwindcss-animate","@tailwindcss/typography","tailwindcss-react-aria-components"]),E=T0(z,["@tailwindcss/postcss","postcss"]);if(!W&&!U?.tailwind.brandColor)b.start("Copying files to the project directory");if($.forEach((j)=>{let N=j.includes("postcss.config"),k=A.posix.join(A.posix.join(Y),j),T=A.posix.join(z,N?j:`${U?.isSrcDir?"src":""}/${j}`);if(w.existsSync(T)){if(v?.overwrite)w.copyFileSync(k,T);else{let g=w.readFileSync(T,"utf-8"),P=w.readFileSync(k,"utf-8");if(g!==P){if(j.endsWith("theme.css")&&U?.tailwind.brandColor)return;I.add({targetFile:T,sourceFile:k})}}return}w.mkdirSync(A.dirname(T),{recursive:!0}),w.writeFileSync(T,""),w.copyFileSync(k,T)}),b.stop(),I.size&&!v?.overwrite)if(console.log(`
65
+ `),b.fail("Following files already exist in the directory."),I.forEach((N)=>{console.log(`- ${_.green(N.targetFile)}`)}),(await R0({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0})).overwrite){let N=Y0("Overwriting files").start();I.forEach((k)=>{w.copyFileSync(k.sourceFile,k.targetFile)}),N.succeed("Files are overwritten")}else console.log(`Use ${_.cyan("--overwrite")} or ${_.cyan("-o")} to overwrite existing files, or refer to the documentation ${_.cyan("https://www.untitled.com/docs")} for manual installation. The rest of the files are added.`);if(K?.tailwindFile)console.log(`
66
66
  Tailwind config file exists in the project directory. You can add it to your globals.css as follows:`),console.log(`
67
- ${A.cyan(`@config "../${b?.isSrcDir?"../":""}${G.relative(z,Z.tailwindFile)}";`)}
68
- `);if(b?.framework==="vite"){if(!i3(z))console.log(`
69
- Tailwind CSS is not configured in your Vite project. Please refer to the documentation ${A.cyan("https://www.untitled.com/react/integrations/vite")} for manual installation.
70
- `)}let D=Z?.layoutFile||Z?.appFile||b?.framework==="vite"&&Z?.mainFile||"";if(!D)console.log(`Import following files to your main file:
71
- `),R.forEach((u)=>{console.log(A.cyan(u))});else{let I=new h0({tsConfigFilePath:G.resolve(Z?.tsConfig||"")}).addSourceFileAtPath(G.resolve(D)),P="globals.css";I.getImportDeclarations().filter((g)=>g.getModuleSpecifierValue().includes("globals.css")).forEach((g)=>g.remove());let O=G.relative(G.resolve(z,`${b?.isSrcDir?"src":""}`),D).split("/").length,i=b?.aliasPrefix?.stylesPrefix||b?.aliasPrefix?.srcPrefix||(O===1?"./":"../".repeat(O-1));I.addImportDeclarations(R.filter((g)=>g.includes("globals.css")).map((g)=>({moduleSpecifier:`${i}${b?.aliasPrefix?.stylesPrefix?g?.split("styles/")[1]:g}`}))),I.saveSync()}let k=R3.sync(["**/styles/theme.css"],{cwd:z,absolute:!0,onlyFiles:!0,ignore:d});if(!k?.length)return U.fail(`Failed to copy ${A.cyan("theme.css")} file.
72
- Ensure that the ${A.cyan("theme.css")} file exists in the project directory under ${A.yellow("styles/")} folder.`);if((H.color||!S)&&k3("brand",H.color||"brand",k[0]??""),x.length||V.length){let u=W3().start("Installing dependencies");x.length&&await q3(()=>a(C(),[C()==="npm"?"install":"add",...x],{cwd:E}).catch(async(I)=>{if(I.message.includes("peer"))u.warn("Dependency conflict detected. Retrying with --legacy-peer-deps..."),u.start("Installing dependencies with --legacy-peer-deps flag"),await a(C(),[C()==="npm"?"install":"add",...x,"--legacy-peer-deps"],{cwd:E})}),{retries:1}),V.length&&await q3(()=>a(C(),[C()==="npm"?"install":"add","-D",...V],{cwd:E}).catch(async(I)=>{if(I.message.includes("peer"))u.warn("DevDependency conflict detected. Retrying with --legacy-peer-deps..."),u.start("Installing dependencies with --legacy-peer-deps flag"),await a(C(),[C()==="npm"?"install":"add","-D",...V,"--legacy-peer-deps"],{cwd:E})}),{retries:1}),u.succeed("Dependencies are installed")}if(!Q&&!S)U.succeed(A.green("Project setup is completed!"));if(Q&&X){j.stop(),U.stop();return}else console.log(`
73
- Your project is ready, you can now start adding components.`)}}var r0=v.join(a0.homedir(),".untitledui"),n=v.join(r0,"config.json"),J={path:"",example:"",license:"",components:[]},d3={};if(w.existsSync(n)){let W=JSON.parse(w.readFileSync(n,"utf-8"));J.license=W.license}var Y3=(W)=>{if(W.aborted)process.stdout.write("\x1B[?25h"),process.stdout.write(`
74
- `),process.exit(1)},B0=new l0().name("example").description("add an example to the project").argument("[example]","the example to add").option("-o, --overwrite","overwrite existing files.",!1).option("-p, --path <path>","the path to add the component to.").option("-e, --example-path <example-path>","the path to add the example file to.").action(async(W,Q)=>{if(W)J.example=W;if(Q)J.path=Q.path,J.overwrite=Q.overwrite,J.examplePath=Q.examplePath,J.license=Q.license||J.license;try{await O3(Q,d3),await n0(J)}catch(z){console.error(M.red(z))}});async function n0(W){let Q=X3().start(),z=v.posix.join(process.cwd(),d3?.projectPath||"");if(!w.existsSync(v.posix.join(v.resolve(z,"package.json"))))Q.warn("This command should be run in a project directory."),process.exit(1);let $=await o(z);if(J.license){if(!await B3(J.license))Q.fail("Invalid license key"),process.exit(1);if(!w.existsSync(n)){let K=v.dirname(n);w.mkdirSync(K,{recursive:!0}),w.writeFileSync(n,JSON.stringify({license:J.license},null,2))}if(JSON.parse(w.readFileSync(n,"utf-8")).license!==J.license)w.writeFileSync(n,JSON.stringify({license:J.license},null,2),"utf-8")}if(Q.stop(),!J.example){let Y=await r({type:"select",name:"example",onState:Y3,message:"Select which type of example you want to add",choices:[{title:"Application",value:"application"},{title:"Marketing",value:"marketing"}]});J.example=Y.example}let q=null;if(J.example){let Y=await H3(J.example,J.license);if(Y?.type==="error"&&(Y.status===401||Y.status===403))console.log(),console.log(M.yellow(`\uD83D\uDD12 The ${M.cyan(J.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${M.green("→")} If you've already purchased: ${M.cyan(`${z3()} untitledui@latest login`)}`),console.log(` ${M.green("→")} To purchase PRO examples: ${M.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1);if(Y?.type==="directory"){let Z=await r({type:"select",name:"example",onState:Y3,message:`Select a folder or file in "${J.example}"`,choices:Y.results.map((K)=>({title:K,value:K}))});if(!Z.example)return;if(J.example=Z.example,Y=await H3(Z.example,J.license),Y?.type==="error"&&(Y.status===401||Y.status===403))console.log(),console.log(M.yellow(`\uD83D\uDD12 The ${M.cyan(Z.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${M.green("→")} If you've already purchased: ${M.cyan(`${z3()} untitledui@latest login`)}`),console.log(` ${M.green("→")} To purchase PRO examples: ${M.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(Y?.type==="json-files"){let Z=await r({type:"select",name:"example",onState:Y3,message:`Select which example you want to add from "${J.example}"`,choices:Y.results.map((K)=>({title:K,value:`${J.example}/${K}`}))});if(!Z.example)return;if(J.example=Z.example,Y=await H3(Z.example,J.license),Y?.type==="error"&&(Y.status===401||Y.status===403))console.log(),console.log(M.yellow(`\uD83D\uDD12 The ${M.cyan(Z.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${M.green("→")} If you've already purchased: ${M.cyan(`${z3()} untitledui@latest login`)}`),console.log(` ${M.green("→")} To purchase PRO examples: ${M.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(Y?.type==="json-file")q=Y.content}if(!q)Q.fail("No example found"),process.exit(1);if(!J?.examplePath){let Y=$?.isUsingAppDir?"app":"pages",Z=$?.isSrcDir?v.posix.join("src",Y):Y,K=await r({type:"text",name:"examplePath",onState:Y3,message:`Where would you like to add the ${M.cyan(J?.example)} example?`,initial:Z});J.examplePath=K.examplePath}else if(!w.existsSync(v.posix.join(z,J.examplePath)))w.mkdirSync(v.posix.join(z,J.examplePath),{recursive:!0}),console.log(M.green(`Created directory ${J.examplePath}`));if(!J?.path){let Y=await r({type:"text",name:"path",onState:Y3,message:`Where would you like to add the ${M.cyan("components")}?`,initial:"components"});J.path=Y.path}let L=q.components.filter((Y)=>!w.existsSync(v.posix.join(z,`${$?.isSrcDir?"src":""}`,Y?.path?.replace(/components\//,J.path+"/"))));if(L?.length){let Y=await r({type:"multiselect",name:"components",onState:Y3,message:`Select which components you want to add from ${M.cyan(q.name)} example`,choices:L.map((Z)=>({title:Z?.name,value:Z?.name,selected:!0})),instructions:!1,hint:"- Space to select. Return to submit"});if(J.components=Y.components,!L.length&&!Y.components?.length)Q.warn("No components selected")}let j=t(z),b=new Set,y=new s0({tsConfigFilePath:j?.tsConfig}),S=X3(`Adding ${J?.example}...`).start(),E="";try{if(q.files?.forEach(async({path:Y,code:Z})=>{let K=v.posix.join(z,`${$?.isSrcDir?"src":""}`,Y.replace(/components\//,J.path+"/")),R=$?.framework==="vite"?Z.replace(`"use client";
67
+ ${_.cyan(`@config "../${U?.isSrcDir?"../":""}${A.relative(z,K.tailwindFile)}";`)}
68
+ `);if(U?.framework==="vite"){if(!p0(z))console.log(`
69
+ Tailwind CSS is not configured in your Vite project. Please refer to the documentation ${_.cyan("https://www.untitled.com/react/integrations/vite")} for manual installation.
70
+ `)}let S=K?.layoutFile||K?.appFile||U?.framework==="vite"&&K?.mainFile||"";if(!S)console.log(`Import following files to your main file:
71
+ `),$.forEach((j)=>{console.log(_.cyan(j))});else{let N=new c3({tsConfigFilePath:A.resolve(K?.tsConfig||"")}).addSourceFileAtPath(A.resolve(S)),k="globals.css";N.getImportDeclarations().filter((P)=>P.getModuleSpecifierValue().includes("globals.css")).forEach((P)=>P.remove());let T=A.relative(A.resolve(z,`${U?.isSrcDir?"src":""}`),S).split("/").length,g=U?.aliases?.styles||U?.aliases?.src||(T===1?"./":"../".repeat(T-1));N.addImportDeclarations($.filter((P)=>P.includes("globals.css")).map((P)=>({moduleSpecifier:`${g}${U?.aliases?.styles?P?.split("styles/")[1]:P}`}))),N.saveSync()}let L=C0.sync(["**/styles/theme.css"],{cwd:z,absolute:!0,onlyFiles:!0,ignore:O});if(!L?.length)return b.fail(`Failed to copy ${_.cyan("theme.css")} file.
72
+ Ensure that the ${_.cyan("theme.css")} file exists in the project directory under ${_.yellow("styles/")} folder.`);if((v.color||!U?.tailwind.brandColor)&&S0("brand",v.color||"brand",L[0]??""),V.length||E.length){let j=Y0().start("Installing dependencies");V.length&&await X0(()=>s(C(),[C()==="npm"?"install":"add",...V],{cwd:H}).catch(async(N)=>{if(N.message.includes("peer"))j.warn("Dependency conflict detected. Retrying with --legacy-peer-deps..."),j.start("Installing dependencies with --legacy-peer-deps flag"),await s(C(),[C()==="npm"?"install":"add",...V,"--legacy-peer-deps"],{cwd:H})}),{retries:1}),E.length&&await X0(()=>s(C(),[C()==="npm"?"install":"add","-D",...E],{cwd:H}).catch(async(N)=>{if(N.message.includes("peer"))j.warn("DevDependency conflict detected. Retrying with --legacy-peer-deps..."),j.start("Installing dependencies with --legacy-peer-deps flag"),await s(C(),[C()==="npm"?"install":"add","-D",...E,"--legacy-peer-deps"],{cwd:H})}),{retries:1}),j.succeed("Dependencies are installed")}if(!W&&!U?.tailwind.brandColor)b.succeed(_.green("Project setup is completed!"));if(W&&q){G.stop(),b.stop();return}else console.log(`
73
+ Your project is ready, you can now start adding components.`)}}var p3=R.join(n3.homedir(),".untitledui"),i=R.join(p3,"config.json"),J={path:"",example:"",license:"",components:[]},g0={};if(x.existsSync(i)){let Q=JSON.parse(x.readFileSync(i,"utf-8"));J.license=Q.license}var Z0=(Q)=>{if(Q.aborted)process.stdout.write("\x1B[?25h"),process.stdout.write(`
74
+ `),process.exit(1)},J3=new r3().name("example").description("add an example to the project").argument("[example]","the example to add").option("-o, --overwrite","overwrite existing files.",!1).option("-p, --path <path>","the path to add the component to.").option("-e, --example-path <example-path>","the path to add the example file to.").action(async(Q,W)=>{if(Q)J.example=Q;if(W)J.path=W.path,J.overwrite=W.overwrite,J.examplePath=W.examplePath,J.license=W.license||J.license;try{await k0(W,g0),await t3(J)}catch(z){console.error(M.red(z))}});async function t3(Q){let W=J0().start(),z=R.posix.join(process.cwd(),g0?.projectPath||"");if(!x.existsSync(R.posix.join(R.resolve(z,"package.json"))))W.warn("This command should be run in a project directory."),process.exit(1);let Z=await o(z);if(J.license){if(!await U0(J.license))W.fail("Invalid license key"),process.exit(1);if(!x.existsSync(i)){let V=R.dirname(i);x.mkdirSync(V,{recursive:!0}),x.writeFileSync(i,JSON.stringify({license:J.license},null,2))}if(JSON.parse(x.readFileSync(i,"utf-8")).license!==J.license)x.writeFileSync(i,JSON.stringify({license:J.license},null,2),"utf-8")}if(W.stop(),!J.example){let Y=await n({type:"select",name:"example",onState:Z0,message:"Select which type of example you want to add",choices:[{title:"Application",value:"application"},{title:"Marketing",value:"marketing"}]});J.example=Y.example}let B=null;if(J.example){let Y=await j0(J.example,J.license);if(Y?.type==="error"&&(Y.status===401||Y.status===403))console.log(),console.log(M.yellow(`\uD83D\uDD12 The ${M.cyan(J.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${M.green("→")} If you've already purchased: ${M.cyan(`${Q0()} untitledui@latest login`)}`),console.log(` ${M.green("→")} To purchase PRO examples: ${M.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1);if(Y?.type==="directory"){let $=await n({type:"select",name:"example",onState:Z0,message:`Select a folder or file in "${J.example}"`,choices:Y.results.map((V)=>({title:V,value:V}))});if(!$.example)return;if(J.example=$.example,Y=await j0($.example,J.license),Y?.type==="error"&&(Y.status===401||Y.status===403))console.log(),console.log(M.yellow(`\uD83D\uDD12 The ${M.cyan($.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${M.green("→")} If you've already purchased: ${M.cyan(`${Q0()} untitledui@latest login`)}`),console.log(` ${M.green("→")} To purchase PRO examples: ${M.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(Y?.type==="json-files"){let $=await n({type:"select",name:"example",onState:Z0,message:`Select which example you want to add from "${J.example}"`,choices:Y.results.map((V)=>({title:V,value:`${J.example}/${V}`}))});if(!$.example)return;if(J.example=$.example,Y=await j0($.example,J.license),Y?.type==="error"&&(Y.status===401||Y.status===403))console.log(),console.log(M.yellow(`\uD83D\uDD12 The ${M.cyan($.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${M.green("→")} If you've already purchased: ${M.cyan(`${Q0()} untitledui@latest login`)}`),console.log(` ${M.green("→")} To purchase PRO examples: ${M.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(Y?.type==="json-file")B=Y.content}if(!B)W.fail("No example found"),process.exit(1);if(!J?.examplePath){let Y=Z?.isAppDir?"app":"pages",$=Z?.isSrcDir?R.posix.join("src",Y):Y,V=await n({type:"text",name:"examplePath",onState:Z0,message:`Where would you like to add the ${M.cyan(J?.example)} example?`,initial:$});J.examplePath=V.examplePath}else if(!x.existsSync(R.posix.join(z,J.examplePath)))x.mkdirSync(R.posix.join(z,J.examplePath),{recursive:!0}),console.log(M.green(`Created directory ${J.examplePath}`));if(!J?.path){let Y=await n({type:"text",name:"path",onState:Z0,message:`Where would you like to add the ${M.cyan("components")}?`,initial:"components"});J.path=Y.path}let u=B.components.filter((Y)=>!x.existsSync(R.posix.join(z,`${Z?.isSrcDir?"src":""}`,Y?.path?.replace(/components\//,J.path+"/"))));if(u?.length){let Y=await n({type:"multiselect",name:"components",onState:Z0,message:`Select which components you want to add from ${M.cyan(B.name)} example`,choices:u.map(($)=>({title:$?.name,value:$?.name,selected:!0})),instructions:!1,hint:"- Space to select. Return to submit"});if(J.components=Y.components,!u.length&&!Y.components?.length)W.warn("No components selected")}let G=e(z),U=new Set,H=new i3({tsConfigFilePath:G?.tsConfig}),b=J0(`Adding ${J?.example}...`).start(),I="";try{if(B.files?.forEach(async({path:Y,code:$})=>{let V=R.posix.join(z,`${Z?.isSrcDir?"src":""}`,Y.replace(/components\//,J.path+"/")),E=Z?.framework==="vite"?$.replace(`"use client";
75
75
 
76
- `,""):Z,x=b3(R);if(Y.includes("examples")){let D=v.basename(Y);K=v.posix.join(z,J?.examplePath??"",D),E=v.posix.join(J?.examplePath??"",D)}let V=v.dirname(K);if(w.existsSync(K)&&!J.overwrite){if(w.readFileSync(K,"utf-8")!==x)b.add({code:x,path:K})}else{w.mkdirSync(V,{recursive:!0}),w.writeFileSync(K,x);let D=v.relative(v.posix.join(z,`${$?.isSrcDir?"src":""}`),K).split("/").length,k=D===1?"./":"../".repeat(D-1),u=y.addSourceFileAtPath(v.resolve(K));u.getImportDeclarations().forEach((I)=>{let P=I.getModuleSpecifierValue();I.setModuleSpecifier(e(P,J.path,$?.aliasPrefix,k))}),await u.save()}}),b.size)S.warn(`Some files of ${M.yellow(J?.example)} already exist`);else S.succeed(`${M.green(J?.example)} is added successfully`)}catch(Y){S.fail(`
77
- Failed to add the component ${M.red(J?.example)}`),console.error(M.red(Y)),process.exit(1)}if(b.size&&!J?.overwrite)if(console.log(`
78
- Following files already exist in the directory.`),b.forEach((Z)=>{console.log(M.green(`- ${v.relative(z,Z.path)}`))}),(await r({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0})).overwrite){let Z=X3("Overwriting files").start();b.forEach((K)=>{let R=v.relative(v.resolve(z,`${$?.isSrcDir?"src":""}`,J.path),K.path).split("/").length,x=R===1?"./":"../".repeat(R-1),V=y.addSourceFileAtPath(v.resolve(K.path));V.replaceWithText(K.code),V.getImportDeclarations().forEach((D)=>{let k=D.getModuleSpecifierValue();D.setModuleSpecifier(e(k,J.path,$?.aliasPrefix,x))}),V.saveSync()}),Z.succeed("Files are overwritten")}else console.log(`Use ${M.cyan("--overwrite")} or ${M.cyan("-o")} to overwrite existing files, or refer to the documentation ${M.cyan("https://www.untitled.com/docs")} for manual installation. The rest of the files are added.`);let U=C();if(q?.dependencies?.length){let Y=X3("Installing example dependencies").start();await g3(()=>I3(U,[U==="npm"?"install":"add",...q.dependencies],{cwd:z}).catch(async(Z)=>{if(Z.message.includes("peer"))Y.warn("Dependency conflict detected. Retrying with --legacy-peer-deps..."),Y.start("Installing dependencies with --legacy-peer-deps flag"),await I3(U,[U==="npm"?"install":"add",...q.dependencies,"--legacy-peer-deps"],{cwd:z})}),{retries:1}),Y.succeed("Example dependencies are installed")}if(q?.devDependencies?.length){let Y=X3("Installing example devDependencies").start();await g3(()=>I3(U,[U==="npm"?"install":"add","-D",...q.devDependencies],{cwd:z}).catch(async(Z)=>{if(Z.message.includes("peer"))Y.warn("DevDependency conflict detected. Retrying with --legacy-peer-deps..."),Y.start("Installing devDependencies with --legacy-peer-deps flag"),await I3(U,[U==="npm"?"install":"add","-D",...q.devDependencies,"--legacy-peer-deps"],{cwd:z})}),{retries:1}),Y.succeed("Example devDependencies are installed")}if(J?.components?.length)await g3(()=>E3({components:J.components,dir:d3?.projectPath||"",path:J.path,message:`
79
- \uD83C\uDF89 Example ${M.green(J.example)} has been added to ${M.green(E)}`}),{retries:1});console.log(`
80
- \uD83C\uDF89 Example ${M.green(J.example)} has been added to ${M.green(E)}`),process.exit(0)}var h3={name:"untitledui",version:"0.1.43-beta.1",main:"dist/index.mjs",description:"The Untitled UI CLI tool helps you quickly scaffold projects with Untitled UI React and add components and page examples to your existing projects with an interactive interface in seconds.",type:"module",publishConfig:{access:"public"},scripts:{test:'echo "Error: no test specified" && exit 1',dev:"bun build --entrypoints ./index.ts --entry-naming=[name].mjs --outdir=dist --target=node --minify --packages=external --env=inline --define=process.env.API_URL=http://localhost:3000/react/api --watch",build:"bun build --entrypoints ./index.ts --entry-naming=[name].mjs --outdir=dist --target=node --minify --packages=external --env=inline --define=process.env.API_URL=https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api","publish:npm":"bun run build && npm publish --access public",start:"node dist/index.mjs"},bugs:{url:"https://github.com/untitleduico/react/issues"},homepage:"https://github.com/untitleduico/react#readme",keywords:["untitledui","untitled-ui","untitledui","untitledui-cli","untitledui-react","untitledui-components","untitledui-examples","untitledui-vite","untitledui-nextjs","cli","tailwindcss","nextjs","react","components","examples","vite"],files:["dist","config","templates","README.md"],author:{name:"Untitled UI",url:"https://www.untitledui.com/react"},contributors:[{name:"Dilshod Turobov",url:"https://x.com/deebovv"},{name:"Jordan Hughes",url:"https://x.com/jordanphughes"}],license:"MIT",bin:{untitledui:"dist/index.mjs"},exports:"./dist/index.mjs",dependencies:{"async-retry":"^1.3.3",chalk:"^5.4.1",commander:"^13.1.0",execa:"^7.0.0","fast-glob":"^3.3.3","node-fetch":"^3.3.2",open:"^10.1.0",ora:"^8.2.0",prettier:"^3.5.3",prompts:"^2.4.2",tar:"^7.4.3","ts-morph":"^25.0.1","tsconfig-paths":"^4.2.0","update-check":"^1.5.4"},devDependencies:{"@types/async-retry":"^1.4.9","@types/prompts":"^2.4.9","@types/tar":"^6.1.13","type-fest":"^4.37.0",typescript:"^5.8.2"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function o0(){let W=new p0().name(h3.name).version(h3.version);W.addCommand(X0).addCommand(t3).addCommand(B0).addCommand(Q0),W.parse()}o0();
76
+ `,""):$,S=V0(E);if(Y.includes("examples")){let j=R.basename(Y);V=R.posix.join(z,J?.examplePath??"",j),I=R.posix.join(J?.examplePath??"",j)}let L=R.dirname(V);if(x.existsSync(V)&&!J.overwrite){if(x.readFileSync(V,"utf-8")!==S)U.add({code:S,path:V})}else{x.mkdirSync(L,{recursive:!0}),x.writeFileSync(V,S);let j=R.relative(R.posix.join(z,`${Z?.isSrcDir?"src":""}`),R.dirname(V)).split("/").length,N=j===1?"./":"../".repeat(j-1),k=H.addSourceFileAtPath(R.resolve(V));k.getImportDeclarations().forEach((T)=>{let g=T.getModuleSpecifierValue();T.setModuleSpecifier(z0(g,J.path,Z?.aliases,N))}),await k.save()}}),U.size)b.warn(`Some files of ${M.yellow(J?.example)} already exist`);else b.succeed(`${M.green(J?.example)} is added successfully`)}catch(Y){b.fail(`
77
+ Failed to add the component ${M.red(J?.example)}`),console.error(M.red(Y)),process.exit(1)}if(U.size&&!J?.overwrite)if(console.log(`
78
+ Following files already exist in the directory.`),U.forEach(($)=>{console.log(M.green(`- ${R.relative(z,$.path)}`))}),(await n({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0})).overwrite){let $=J0("Overwriting files").start();U.forEach((V)=>{let E=R.relative(R.resolve(z,`${Z?.isSrcDir?"src":""}`,J.path),R.dirname(V.path)).split("/").length,S=E===1?"./":"../".repeat(E-1),L=H.addSourceFileAtPath(R.resolve(V.path));L.replaceWithText(V.code),L.getImportDeclarations().forEach((j)=>{let N=j.getModuleSpecifierValue();j.setModuleSpecifier(z0(N,J.path,Z?.aliases,S))}),L.saveSync()}),$.succeed("Files are overwritten")}else console.log(`Use ${M.cyan("--overwrite")} or ${M.cyan("-o")} to overwrite existing files, or refer to the documentation ${M.cyan("https://www.untitled.com/docs")} for manual installation. The rest of the files are added.`);let K=C();if(B?.dependencies?.length){let Y=J0("Installing example dependencies").start();await P0(()=>I0(K,[K==="npm"?"install":"add",...B.dependencies],{cwd:z}).catch(async($)=>{if($.message.includes("peer"))Y.warn("Dependency conflict detected. Retrying with --legacy-peer-deps..."),Y.start("Installing dependencies with --legacy-peer-deps flag"),await I0(K,[K==="npm"?"install":"add",...B.dependencies,"--legacy-peer-deps"],{cwd:z})}),{retries:1}),Y.succeed("Example dependencies are installed")}if(B?.devDependencies?.length){let Y=J0("Installing example devDependencies").start();await P0(()=>I0(K,[K==="npm"?"install":"add","-D",...B.devDependencies],{cwd:z}).catch(async($)=>{if($.message.includes("peer"))Y.warn("DevDependency conflict detected. Retrying with --legacy-peer-deps..."),Y.start("Installing devDependencies with --legacy-peer-deps flag"),await I0(K,[K==="npm"?"install":"add","-D",...B.devDependencies,"--legacy-peer-deps"],{cwd:z})}),{retries:1}),Y.succeed("Example devDependencies are installed")}if(J?.components?.length)await P0(()=>N0({components:J.components,dir:g0?.projectPath||"",path:J.path,message:`
79
+ \uD83C\uDF89 Example ${M.green(J.example)} has been added to ${M.green(I)}`}),{retries:1});console.log(`
80
+ \uD83C\uDF89 Example ${M.green(J.example)} has been added to ${M.green(I)}`),process.exit(0)}var O0={name:"untitledui",version:"0.1.44-beta",main:"dist/index.mjs",description:"The Untitled UI CLI tool helps you quickly scaffold projects with Untitled UI React and add components and page examples to your existing projects with an interactive interface in seconds.",type:"module",publishConfig:{access:"public"},scripts:{test:'echo "Error: no test specified" && exit 1',dev:"bun build --entrypoints ./index.ts --entry-naming=[name].mjs --outdir=dist --target=node --minify --packages=external --env=inline --define=process.env.API_URL=http://localhost:3000/react/api --watch",build:"bun build --entrypoints ./index.ts --entry-naming=[name].mjs --outdir=dist --target=node --minify --packages=external --env=inline --define=process.env.API_URL=https://www.untitledui.com/react/api","publish:npm":"bun run build && npm publish --access public",start:"node dist/index.mjs"},bugs:{url:"https://github.com/untitleduico/react/issues"},homepage:"https://github.com/untitleduico/react#readme",keywords:["untitledui","untitled-ui","untitledui","untitledui-cli","untitledui-react","untitledui-components","untitledui-examples","untitledui-vite","untitledui-nextjs","cli","tailwindcss","nextjs","react","components","examples","vite"],files:["dist","config","templates","README.md"],author:{name:"Untitled UI",url:"https://www.untitledui.com/react"},contributors:[{name:"Dilshod Turobov",url:"https://x.com/deebovv"},{name:"Jordan Hughes",url:"https://x.com/jordanphughes"}],license:"MIT",bin:{untitledui:"dist/index.mjs"},exports:"./dist/index.mjs",dependencies:{"async-retry":"^1.3.3",chalk:"^5.4.1",commander:"^13.1.0",execa:"^7.0.0","fast-glob":"^3.3.3","node-fetch":"^3.3.2",open:"^10.1.0",ora:"^8.2.0",prettier:"^3.5.3",prompts:"^2.4.2",tar:"^7.4.3","ts-morph":"^25.0.1","tsconfig-paths":"^4.2.0","update-check":"^1.5.4"},devDependencies:{"@types/async-retry":"^1.4.9","@types/prompts":"^2.4.9","@types/tar":"^6.1.13","type-fest":"^4.37.0",typescript:"^5.8.2"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function z1(){let Q=new e3().name(O0.name).version(O0.version);Q.addCommand(X3).addCommand(e0).addCommand(J3).addCommand(W3),Q.parse()}z1();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "untitledui",
3
- "version": "0.1.43-beta.1",
3
+ "version": "0.1.44-beta",
4
4
  "main": "dist/index.mjs",
5
5
  "description": "The Untitled UI CLI tool helps you quickly scaffold projects with Untitled UI React and add components and page examples to your existing projects with an interactive interface in seconds.",
6
6
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "test": "echo \"Error: no test specified\" && exit 1",
12
12
  "dev": "bun build --entrypoints ./index.ts --entry-naming=[name].mjs --outdir=dist --target=node --minify --packages=external --env=inline --define=process.env.API_URL=http://localhost:3000/react/api --watch",
13
- "build": "bun build --entrypoints ./index.ts --entry-naming=[name].mjs --outdir=dist --target=node --minify --packages=external --env=inline --define=process.env.API_URL=https://untitledui-docs-git-separate-s-3bf698-dilshod-turobovs-projects.vercel.app/react/api",
13
+ "build": "bun build --entrypoints ./index.ts --entry-naming=[name].mjs --outdir=dist --target=node --minify --packages=external --env=inline --define=process.env.API_URL=https://www.untitledui.com/react/api",
14
14
  "publish:npm": "bun run build && npm publish --access public",
15
15
  "start": "node dist/index.mjs"
16
16
  },