untitledui 0.1.59 → 0.1.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +107 -107
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as
|
|
3
|
-
⚠ Could not resolve path aliases from components.json - no paths configured in tsconfig.json.`));else console.log(
|
|
4
|
-
⚠ Could not resolve path aliases from components.json - tsconfig.json not found.`));console.log(
|
|
5
|
-
`)),
|
|
2
|
+
import{Command as i3}from"commander";import O from"chalk";import{Command as r1}from"commander";import*as s from"fs";import w$ from"ora";import*as m from"path";import V$ from"prompts";import{Project as i1}from"ts-morph";import*as Q$ from"fs";import*as e$ from"path";import w1 from"os";var I0=e$.join(w1.homedir(),".untitledui"),$0=e$.join(I0,"config.json");function E0($=$0){if(!Q$.existsSync($))return{};try{return JSON.parse(Q$.readFileSync($,"utf-8"))}catch{return{}}}function q$($=$0){return E0($).license||""}function u$($,z=I0,Q=$0){if(!Q$.existsSync(z))Q$.mkdirSync(z,{recursive:!0});let U=E0(Q);if(U.license!==$)U.license=$,Q$.writeFileSync(Q,JSON.stringify(U,null,2),"utf-8")}import*as P$ from"fs";import*as T0 from"path";function A$($,z){if(z)return z;let Q=T0.resolve($,"components.json");if(P$.existsSync(Q))try{return JSON.parse(P$.readFileSync(Q,"utf-8")).version??"8"}catch{}return"8"}import v1 from"node-fetch";var x0={invalid_key:"Invalid key provided",no_components_found:"No components found",no_components_provided:"No components provided"};async function g$($,z,Q,U){let Y=z.map((X)=>{if(X.includes("modals/"))if(X.includes("-modal"))return X;else return X+"-modal";return X});try{let X=await v1("https://www.untitledui.com/react/api/components",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({type:$,components:Y,key:Q,version:U})});if(!X.ok)console.log(x0?.[X.statusText]||x0.no_components_found),process.exit(1);return await X.json()}catch(X){return null}}import z0 from"node-fetch";var D$={invalid_key:"Invalid key provided",no_components_found:"No components found",no_components_provided:"No components provided"};async function R0($,z="",Q){let U=`https://www.untitledui.com/react/api/components/list?key=${z}&type=${$}${Q?`&version=${Q}`:""}`;try{let Z=await z0(U),Y=await Z.json();if(!Z.ok)console.log(D$?.[Z.statusText]||D$.no_components_found),process.exit(1);if(!Y?.components?.length)return null;return Y}catch(Z){return console.error(Z),null}}async function S0($,z="",Q,U){let Z=`https://www.untitledui.com/react/api/components/list?key=${z}&type=${$}&subfolders=${Q.join(",")}${U?`&version=${U}`:""}`;try{let Y=await z0(Z);if(!Y.ok)console.log(D$?.[Y.statusText]||D$.no_components_found),process.exit(1);let X=await Y.json();if(!X?.components?.length)return null;return X}catch(Y){return console.error(Y),null}}async function w0($="",z){let Q=`https://www.untitledui.com/react/api/components/list?key=${$}${z?`&version=${z}`:""}`;try{let U=await z0(Q);if(!U.ok)console.log(D$?.[U.statusText]||D$.no_components_found),process.exit(1);let Z=await U.json();if(!Z?.types?.length)return null;return Z}catch(U){return console.error(U),null}}import Z0 from"fast-glob";import*as h$ from"fs";import*as W$ from"path";import{Project as g1}from"ts-morph";import{loadConfig as d0}from"tsconfig-paths";import C1 from"prettier";async function v0($,z="typescript"){try{return await C1.format($,{parser:z,printWidth:160,tabWidth:4})}catch(Q){return console.error("Error formatting with Prettier:",Q),$}}import Z$ from"chalk";import J$ from"fast-glob";import*as U$ from"fs";import*as Y$ from"path";import{loadConfig as f$}from"tsconfig-paths";import C0 from"fs";import F1 from"path";function F0($=""){let z=F1.join($,"package.json");if(!C0.existsSync(z))return null;else return JSON.parse(C0.readFileSync(z,"utf-8"))}import Q0 from"fs";import O0 from"path";import{createMatchPath as k0}from"tsconfig-paths";function u0($,z){let Q=O0.posix.join($,"index"),U=(Y)=>{try{return Q0.existsSync(Y)}catch{return!0}},Z=k0(z.absoluteBaseUrl,z.paths)(Q,void 0,U,[".ts",".tsx",".jsx",".js",".css"]);if(!Z)Z=k0(z.absoluteBaseUrl,z.paths)(Q,void 0,()=>!0,[".ts",".tsx",".jsx",".js",".css"]);if(Z){let Y=Z.split("/").slice(0,-1).join("/");try{if(Q0.existsSync(Y)&&Q0.statSync(Y).isFile())return O0.dirname(Y)}catch{}return Y}else return}var a=["**/node_modules/**",".next","public","dist","build"],d$=!1,P0={"next-app":"Next.js (App)","next-pages":"Next.js (Pages)",vite:"Vite",other:"Other"};async function M$($){let z=U$.existsSync(Y$.resolve($,"src")),Q=U$.existsSync(Y$.resolve($,`${z?"src/":""}app`)),[U,Z,Y,X,H]=await Promise.all([J$.glob("**/{next,vite,astro}.config.*|gatsby-config.*",{cwd:$,deep:2,ignore:a}),O1($),u1($),P1($),F0($)]),B=U$.existsSync(Y$.resolve($,"components.json")),J=null;if(B)J=JSON.parse(U$.readFileSync(Y$.resolve($,"components.json"),"utf-8"));let j=J$.sync(["**/**/theme.css"],{cwd:$,absolute:!0,onlyFiles:!0,ignore:a}),_=j?.[0]&&U$.readFileSync(j[0],"utf-8").match(/(--color-brand+-\d{1,3}):\s*(rgb\([^)]+\))/g)?.[1]||void 0,L={tailwind:{config:Y||void 0,brandColor:_?.replace(/--color-([^-]+(?:-[^-]+)?)-\d+:.*/,"$1")||void 0},examples:J?.examples||void 0,aliases:J?.aliases||X||{},paths:await k1(J?.aliases||{})||{},isTsx:Z,isSrcDir:z,isAppDir:Q,isComponentsJson:!!B,framework:"other",version:J?.version||void 0};if(U.find((b)=>b.startsWith("next.config."))?.length)return L.framework=Q?"next-app":"next-pages",L;else if(U.find((b)=>b.startsWith("vite.config."))?.length)return L.framework="vite",L;else if(Object.keys(H?.dependencies||{}).includes("react"))return L.framework="next-pages",L;else if(U?.length||U$.existsSync(Y$.resolve($,"package.json")))return L.framework="other",L;return null}async function O1($){return(await J$.glob("tsconfig.*",{cwd:$,deep:2,ignore:a})).length>0}async function k1($){let z={},Q=[],U=Object.entries($).filter(([,B])=>B);if(U.length===0)return null;let Z=process.cwd(),X=f$(Z).resultType==="success",H=await g0(Z);if(!H){if(!d$){if(d$=!0,process.stdout.write("\r\x1B[K"),X)console.log(Z$.yellow(`
|
|
3
|
+
⚠ Could not resolve path aliases from components.json - no paths configured in tsconfig.json.`));else console.log(Z$.yellow(`
|
|
4
|
+
⚠ Could not resolve path aliases from components.json - tsconfig.json not found.`));console.log(Z$.dim(` The following aliases will be used for imports but files will be placed in default locations:
|
|
5
|
+
`)),U.forEach(([B,J])=>{console.log(Z$.dim(` ${B}: ${J}`))}),console.log(Z$.dim(`
|
|
6
6
|
To fix this, add matching paths to your tsconfig.json.
|
|
7
|
-
`))}return null}for(let[
|
|
8
|
-
⚠ Could not resolve the following path aliases from tsconfig.json:`)),
|
|
9
|
-
These aliases will be used for imports but files will be placed in default locations.`)),console.log(
|
|
10
|
-
`));return
|
|
11
|
-
"paths": ${JSON.stringify(
|
|
12
|
-
`),process.exit(1)};function
|
|
13
|
-
|
|
14
|
-
`,""):E,
|
|
15
|
-
Please check your path aliases in components.json and tsconfig.json.`);
|
|
16
|
-
Failed to add the component ${
|
|
17
|
-
Following files already exist in the directory.`),
|
|
18
|
-
Use ${
|
|
7
|
+
`))}return null}for(let[B,J]of Object.entries($))if(J){let j=await u0(J.replace(/\/\*$/,""),H);if(j)z[B]=Y$.relative(process.cwd(),j);else Q.push(`${B}: ${J}`)}if(Q.length>0&&!d$)d$=!0,process.stdout.write("\r\x1B[K"),console.log(Z$.yellow(`
|
|
8
|
+
⚠ Could not resolve the following path aliases from tsconfig.json:`)),Q.forEach((B)=>{console.log(Z$.dim(` ${B}`))}),console.log(Z$.dim(`
|
|
9
|
+
These aliases will be used for imports but files will be placed in default locations.`)),console.log(Z$.dim(` To fix this, add matching paths to your tsconfig.json.
|
|
10
|
+
`));return z}async function g0($){let[z,Q]=await Promise.all([J$.glob("next.config.*",{cwd:$,deep:1,ignore:a}),J$.glob("vite.config.*",{cwd:$,deep:1,ignore:a})]),U=z.length>0,Z=Q.length>0,Y=null;if(U)Y=f$($);else if(Z){if(Y=f$($),Y?.resultType==="failed"||!Object.keys(Y.paths||{}).length){let X=await J$.glob(["tsconfig.app.*","*/tsconfig.app.*"],{cwd:$,deep:1,onlyFiles:!0,absolute:!0,ignore:a}),[H]=X;if(H)try{let J=function(L){return L.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"").replace(/,(\s*[}\]])/g,"$1")},B=U$.readFileSync(H,"utf-8"),j=J(B),_=JSON.parse(j);if(_.compilerOptions?.paths)Y={resultType:"success",paths:_?.compilerOptions?.paths,baseUrl:_.compilerOptions.baseUrl||".",configFileAbsolutePath:H,absoluteBaseUrl:Y$.resolve($,_.compilerOptions.baseUrl||".")}}catch{}}}else Y=f$($);if(!Y||Y?.resultType==="failed"||!Object.keys(Y.paths).length)return null;return Y}async function u1($){let z=await J$.glob("tailwind.config.*",{cwd:$,deep:2,ignore:a});if(!z.length)return null;return z[0]}async function P1($){let z=await g0($);if(!z)return null;let Q={},U={app:/\/?app\/\*$/,components:/\/?components\/\*$/,utils:/\/?utils\/\*$/,styles:/\/?styles\/\*$/,hooks:/\/?hooks\/\*$/,src:/^(\.\/src\/\*|\.\/\*|\/src\/\*|src\/\*|\/\*|\*)$/};for(let[Z,Y]of Object.entries(z.paths)){let X=Z.replace(/\/\*$/,"/");for(let[H,B]of Object.entries(U))if(Y.some((J)=>B.test(J))){Q[H]=X;break}}return Q||null}function I$($,z){let Q=d0($),U=Z0.sync(["tailwind.config.*","**/globals.css","package.json"],{cwd:$,deep:4,absolute:!0,onlyFiles:!0,ignore:a}),Z=Z0.sync("**/{layout,_app,main}.tsx",{cwd:z?W$.posix.join($,z):$,deep:4,absolute:!0,onlyFiles:!0,ignore:a});return{tailwindFile:U.find((X)=>X.includes("tailwind.config.")),cssFile:U.find((X)=>X.includes("globals.css")),packageJson:U.find((X)=>X.includes("package.json")),tsConfig:Q?.resultType==="success"?Q?.configFileAbsolutePath:void 0,layoutFile:Z.find((X)=>X.includes("layout")),appFile:Z.find((X)=>X.includes("_app")),mainFile:Z.find((X)=>X.includes("main"))}}function E$($,z,Q={}){if($.startsWith("@/components/")){if(Q?.components)return $.replace(/^@\/components\//,W$.posix.join(Q.components,"/"));if(z)return $.replace(/^@\/components\//,W$.posix.join("@",z,"/"))}if($.startsWith("@/app/")&&Q?.app)return $.replace(/^@\/app\//,W$.posix.join(Q.app,"/"));if($.startsWith("@/utils/")&&Q?.utils)return $.replace(/^@\/utils\//,W$.posix.join(Q.utils,"/"));if($.startsWith("@/hooks/")&&Q?.hooks)return $.replace(/^@\/hooks\//,W$.posix.join(Q.hooks,"/"));if($.startsWith("@/styles/")&&Q?.styles)return $.replace(/^@\/styles\//,W$.posix.join(Q.styles,"/"));if($.startsWith("@/")&&Q?.src)return $.replace(/^@\//,W$.posix.join(Q.src,"/"));return $}async function f0($,z,Q="@/*"){let U=await d0($);if(U?.resultType==="failed")return null;let Z={};if(!Object.keys(U.paths).length){U.paths={[Q]:[`./${z?"src/":""}*`]},Z.src=Q.replace(/\/\*$/,"");let Y=await h$.promises.readFile(U.configFileAbsolutePath,"utf-8"),X,H=/(?:\/\/\s*)?"paths":\s*\{(?:[^{}]|\{[^}]*\})*\}/;if(!H.test(Y))X=Y.replace(/"compilerOptions":\s*{/,`"compilerOptions": {
|
|
11
|
+
"paths": ${JSON.stringify(U.paths)},`);else X=Y.replace(H,`"paths": ${JSON.stringify(U.paths)}`);let J=new g1,j=await v0(X,"json");return J.createSourceFile(U.configFileAbsolutePath,j,{overwrite:!0}),await J.save(),Z}return Z||null}function h0($){let z=Z0.sync(["vite.config.*"],{cwd:$,absolute:!0,onlyFiles:!0,ignore:a})?.[0];if(!z)return!1;try{let Q=h$.readFileSync(z,"utf-8");return d1(Q)}catch{return!1}}function d1($){let z=$.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"");if(!["tailwindcss","@tailwindcss/vite","tailwind("].some((Y)=>z.includes(Y)))return!1;return["plugins:","postcss:","css:"].some((Y)=>z.includes(Y))}var f1=["npm","config","user","agent"].join("_");function L$($){if($===void 0)$=process.env[f1]||"";if($.startsWith("yarn"))return"yarn";if($.startsWith("pnpm"))return"pnpm";if($.startsWith("bun"))return"bun";return"npm"}function X$(){switch(L$()){case"yarn":return"yarn";case"pnpm":return"pnpx";case"bun":return"bunx";default:return"npx"}}function m0(){switch(L$()){case"yarn":return"yarn dev";case"pnpm":return"pnpm dev";case"bun":return"bun dev";default:return"npm run dev"}}import h1 from"async-retry";import{execa as c0}from"execa";async function B$($,z){let Q=Array.isArray($)?$:Array.from($);if(!Q.length)return;let{cwd:U,dev:Z=!1,spinner:Y,label:X=Z?"devDependencies":"dependencies"}=z,H=L$(),J=[H==="npm"?"install":"add",...Z?["-D"]:[],...Q];Y.start(`Installing ${X}`),await h1(()=>c0(H,J,{cwd:U}).catch(async(j)=>{if(j.message.includes("peer"))Y.warn(`${X} conflict detected. Retrying with --legacy-peer-deps...`),Y.start(`Installing ${X} with --legacy-peer-deps flag`),await c0(H,[...J,"--legacy-peer-deps"],{cwd:U});else throw j}),{retries:1}),Y.succeed(`${X} installed`)}var f=($)=>{if($.aborted)process.stdout.write("\x1B[?25h"),process.stdout.write(`
|
|
12
|
+
`),process.exit(1)};function m$($){return $.replace(/^[ \t]*\/\/\s*(TODO:|collapse-(start|end)).*\r?\n?|[ \t]*{\s*\/\*\s*(TODO:|collapse-(start|end)).*?\*\/\s*}\r?\n?/gm,"")}import H$ from"path";function c$($,z,Q){let U=$.replace(/^(components|utils|hooks|styles)\//,"");if($.includes("components")&&z?.components)return H$.relative(process.cwd(),H$.posix.join(z.components,U));if($.includes("utils")&&z?.utils)return H$.relative(process.cwd(),H$.posix.join(z.utils,U));if($.includes("hooks")&&z?.hooks)return H$.relative(process.cwd(),H$.posix.join(z.hooks,U));if($.includes("styles")&&z?.styles)return H$.relative(process.cwd(),H$.posix.join(z.styles,U));return H$.posix.join(Q?"src":"",$)}import l0 from"node-fetch";import{Readable as m1,pipeline as c1}from"stream";import{x as l1}from"tar";import{promisify as p1}from"util";var a1=p1(c1);async function p0($,z){try{let Q=await s1(z);await a1(Q,l1({cwd:$,strip:1}))}catch(Q){throw Error(`Failed to download or extract repository from API: ${Q instanceof Error?Q.message:Q}`)}}async function s1($){let z=`https://www.untitledui.com/react/api/download-repo?template=${$.template}`;try{let Q=await l0(z,{method:"GET",headers:{"Content-Type":"application/json",Accept:"application/octet-stream"}});if(Q.status===403||Q.status===404)throw Error("Repository not found");if(!Q.ok)throw Error(`Failed to download from API. Status: ${Q.status} ${Q.statusText}`);if(!Q.body)throw Error("Response body is empty");return m1.from(Q.body)}catch(Q){throw Error(`Error downloading tarball: ${Q instanceof Error?Q.message:Q}`)}}async function a0($){let z=`https://www.untitledui.com/react/api/validate-key?key=${$}`;try{return(await l0(z)).status===200}catch{return!1}}async function l$($,z){if(!await a0($))z.fail("Invalid license key"),process.exit(1);u$($)}var N={components:[],path:"",type:void 0,license:q$()},s0=new r1().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.").option("--include-all-components","automatically include all base components without prompting.",!1).option("-y, --yes","non-interactive mode - use defaults for all prompts (for AI agents/CI).",!1).option("--license <key>","API key for PRO access (alternative to stored config)").option("--lib-version <version>","component library version (7 or 8)").action(async($,z)=>{if($)N.components=$;if(z){if(N.all=z.all,N.dir=z.dir,N.path=z.path,N.overwrite=z.overwrite,N.includeAllComponents=z.includeAllComponents,N.license=z.license||N.license,N.version=z.libVersion,N.yes=z.yes,z.yes)N.includeAllComponents=!0,N.overwrite=!0}try{await Y0(N)}catch(Q){console.error(O.red(Q))}});async function Y0($){if($)N={...N,...$};let z=w$().start(),Q=m.posix.join(process.cwd(),N.dir||"");if(!s.existsSync(m.resolve(Q,"package.json")))z.warn("This command should be run in a project directory."),process.exit(1);let Z=A$(Q,N.version),Y=await M$(Q);if(N.license)await l$(N.license,z);z.stop();let X=[];if(N.components.length){let W=await g$(N.type,N.components,N.license,Z);if(W&&W.pro&&W.pro.length>0){if(console.log(),W.pro.length===1){let y=W.pro[0]?.split("/")[1]||W.pro[0];console.log(O.yellow(`\uD83D\uDD12 The ${O.cyan(y)} component requires PRO access.`))}else console.log(O.yellow("\uD83D\uDD12 The following components require PRO access:")),W.pro.forEach((y)=>{let V=y?.split("/")[1]||y;console.log(` • ${O.cyan(V)}`)});console.log(),console.log("To access PRO components:"),console.log(` ${O.green("→")} If you've already purchased: ${O.cyan(`${X$()} untitledui@latest login`)}`),console.log(` ${O.green("→")} To purchase PRO components: ${O.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(!W?.components.length)console.log("No components found"),process.exit(1);X.push(...W.components)}if(!N?.type&&!N?.components.length){if(N.yes)console.log(O.red("Error: In non-interactive mode (--yes), you must specify components as arguments.")),process.exit(1);let W=await w0(N.license,Z);if(!W)console.log("No component types found"),process.exit(1);let y=await V$({type:"select",name:"type",onState:f,message:`What type of ${O.cyan("component")} are you adding?`,choices:W?.types.map((V)=>({title:V,value:V}))});N.type=y.type}if(!N?.path&&!Y?.paths?.components)if(N.yes)N.path="components";else{let W=await V$({type:"text",name:"path",onState:f,message:`Where would you like to add the ${O.cyan("components")}?`,initial:"components"});N.path=W.path}if(N?.path&&Y&&Y.paths)Y.paths.components=m.posix.join(Y?.isSrcDir?"src":"",N.path);if(Y&&!Object.keys(Y?.aliases).length){let W="@/*";if(!N.yes){let y=/^[^*"]+\/\*\s*$/;W=(await V$({type:"text",name:"aliasPrefix",onState:f,initial:"@/*",message:`What is the ${O.cyan("import alias")} for your project?`,validate:(w)=>y.test(w)?!0:"Import alias must follow the pattern <prefix>/*"}))?.aliasPrefix}Y.aliases=await f0(Q,Y?.isSrcDir,W)}if(!N?.components.length){if(N.yes)console.log(O.red("Error: In non-interactive mode (--yes), you must specify components as arguments.")),process.exit(1);let W=await R0(N?.type,N.license,Z);if(!W)console.log("No components found"),process.exit(1);let y=await V$({type:"multiselect",name:"components",onState:f,message:`Which ${O.cyan("components")} would you like to add?`,choices:W?.components?.map((E)=>({title:E?.name+(E?.count?` (${E?.count} variants)`:"")||"example",value:E||"example",selected:N.components.includes(E.name)})),instructions:!1,hint:"- Space to select. Return to submit"});if(!y.components||!y.components.length)console.log("No option selected. Exiting..."),process.exit(1);let V=y.components.filter((E)=>E?.type==="file").map((E)=>E.name),w=y.components.filter((E)=>E?.type==="dir").map((E)=>E.name),T=[];if(w.length){let E=await S0(N?.type,N.license,w,Z);if(E&&E.components.length)for(let C of E.components){let[d,F]=Object.entries(C)[0]||[],R=await V$({type:"select",name:"component",onState:f,message:`Which ${O.cyan("variant")} from ${O.cyan(d)} would you like to add?`,choices:F?.map((q)=>({title:q?.name.replace(/-modal/g,"")||"example",value:q?.name||"example",selected:N.components.includes(q.name)})),instructions:!1,hint:"- Space to select. Return to submit"});if(!R.component)console.log("No variant selected for "+O.cyan(d));T.push(d+"/"+R.component)}else console.log("No variants found")}N.components=[...T,...V]}if(!N.components?.length)z.warn("No components selected. Exiting."),process.exit(1);let H=I$(Q),B=new Map,J=new Set,j=new Set,_=new i1({tsConfigFilePath:H?.tsConfig});if(z.start(),N.type&&N.components.length){let W=await g$(N.type,N.components,N.license,Z);if(!W?.components.length)console.log("No components found"),process.exit(1);X.push(...W.components)}let L=new Set;if(X.forEach((W)=>{W?.components?.forEach((y)=>{L.add({name:y.name,path:y.path})})}),z.stop(),L.size){let W=Array.from(L).filter((y)=>!s.existsSync(m.posix.join(Q,`${Y?.isSrcDir?"src":""}`,y?.path?.replace(/components\//,N.path+"/"))));if(W?.length)if(N.includeAllComponents)N.baseComponents=W.map((y)=>y.name);else{let y=await V$({type:"multiselect",name:"baseComponents",onState:f,message:"Select which base components you want to add",choices:W.map((V)=>({title:V?.name,value:V?.name,selected:!0})),instructions:!1,hint:"- Space to select. Return to submit"});if(N.baseComponents=y.baseComponents,!W.length&&!y.baseComponents?.length)z.warn("No components selected")}}if(z.start(),N?.baseComponents?.length){let W=await g$("",N.baseComponents,N.license,Z);if(!W||!W?.components.length)console.log("No base components found");else X.push(...W.components)}z.stop();let b=new Set;for(let W of X){let y=w$(`Adding ${W.name}...`).start(),V=W.files;W?.dependencies?.forEach((T)=>J.add(T)),W?.devDependencies?.forEach((T)=>j.add(T));let w=!1;try{for(let{path:T,code:E}of V||[]){let C=m.posix.join(Q,c$(T,Y?.paths,Y?.isSrcDir)),d=Y?.framework==="vite"?E.replace(`"use client";
|
|
13
|
+
|
|
14
|
+
`,""):E,F=m$(d),R=m.dirname(C);if(s.existsSync(C)&&!N.overwrite&&!b.has(C)){if(s.readFileSync(C,"utf-8")!==F)B.set(C,{code:F,path:C}),w=!0}else if(!b.has(C)){let q=R.split(m.sep),K="";for(let A of q)if(K=K?m.join(K,A):A,K&&s.existsSync(K)&&s.statSync(K).isFile())throw Error(`Cannot create directory '${R}' because '${K}' is an existing file.
|
|
15
|
+
Please check your path aliases in components.json and tsconfig.json.`);s.mkdirSync(R,{recursive:!0}),s.writeFileSync(C,F),b.add(C);let M=_.getSourceFile(m.resolve(C));if(M)M.replaceWithText(F);else M=_.addSourceFileAtPath(m.resolve(C));M.getImportDeclarations().forEach((A)=>{let x=A.getModuleSpecifierValue();A.setModuleSpecifier(E$(x,N.path,Y?.aliases))}),await M.save()}}if(w)y.warn(`Some files of ${O.yellow(W.name)} already exist`);else y.succeed(`${O.green(W.name)} is added successfully`)}catch(T){y.fail(`
|
|
16
|
+
Failed to add the component ${O.red(W.name)}`),console.error(O.red(T)),process.exit(1)}}if(B.size&&!N?.overwrite){console.log(`
|
|
17
|
+
Following files already exist in the directory.`),B.forEach((y)=>{console.log(O.green(`- ${m.relative(Q,y.path)}`))});let W=!1;if(N.yes)W=!0;else{let y=await V$({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0});if(y.overwrite===void 0)console.log(`
|
|
18
|
+
Use ${O.cyan("--overwrite")} or ${O.cyan("-o")} flag to overwrite existing files, or run with ${O.cyan("node")} instead of ${O.cyan("bun")}.`),process.exit(1);W=y.overwrite}if(W){let y=w$("Overwriting files").start();B.forEach((V)=>{let w=_.addSourceFileAtPath(m.resolve(V.path));w.replaceWithText(V.code),w.getImportDeclarations().forEach((T)=>{let E=T.getModuleSpecifierValue();T.setModuleSpecifier(E$(E,N.path,Y?.aliases))}),w.saveSync()}),y.succeed("Files are overwritten")}}if(J.size){let W=w$().start();await B$(J,{cwd:Q,spinner:W,label:"component dependencies"})}if(j.size){let W=w$().start();await B$(j,{cwd:Q,dev:!0,spinner:W,label:"component devDependencies"})}if(N.message!==void 0){if(N.message)console.log(N.message);return}process.exit(0)}import X0 from"chalk";import{Command as e1}from"commander";import*as K$ from"fs";import $3 from"http";import z3 from"open";import Q3 from"ora";import Z3 from"os";import*as H0 from"path";import{URL as Y3}from"url";import*as p$ from"fs";import*as j$ from"path";import{fileURLToPath as n1}from"url";var o1=n1(import.meta.url),U0=j$.dirname(o1);function t1(){let $=[j$.join(U0,"..","templates","auth-template.html"),j$.join(U0,"templates","auth-template.html"),j$.join(process.cwd(),"node_modules","untitledui","templates","auth-template.html"),j$.join(U0,"..","..","templates","auth-template.html")];for(let z of $)if(p$.existsSync(z))return z;throw Error("Auth template file not found. Please ensure the CLI package is properly installed.")}function r0(){try{let $=t1();return p$.readFileSync($,"utf-8")}catch($){return console.warn("Warning: Using fallback auth template. Some styling may be missing."),`<!doctype html>
|
|
19
19
|
<html lang="en">
|
|
20
20
|
<head>
|
|
21
21
|
<meta charset="UTF-8" />
|
|
@@ -61,120 +61,120 @@ Use ${u.cyan("--overwrite")} or ${u.cyan("-o")} flag to overwrite existing files
|
|
|
61
61
|
{{AUTO_CLOSE_SCRIPT}}
|
|
62
62
|
</div>
|
|
63
63
|
</body>
|
|
64
|
-
</html>`}}function
|
|
65
|
-
✨ You can now access PRO components with the CLI!`)),process.exit(0)}catch(
|
|
66
|
-
Failed to open browser automatically: ${
|
|
67
|
-
`))})
|
|
68
|
-
Creating a new project in ${h.blue(
|
|
64
|
+
</html>`}}function i0(){return r0().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 a$($){return r0().replace("{{TITLE}}","Authentication failed").replace("{{HEADING}}","Authentication failed").replace("{{DESCRIPTION}}",$).replace("{{AUTO_CLOSE_SCRIPT}}","")}var B0=H0.join(Z3.homedir(),".untitledui"),W0=H0.join(B0,"config.json"),n0=new e1().name("login").description("authenticate with Untitled UI to access PRO components").action(async()=>{let $=Q3("Starting authentication...").start();try{await U3($),$.succeed("Authentication completed successfully!"),console.log(X0.green(`
|
|
65
|
+
✨ You can now access PRO components with the CLI!`)),process.exit(0)}catch(z){$.fail(`Authentication failed: ${z instanceof Error?z.message:z}`),process.exit(1)}});async function U3($){return new Promise((z,Q)=>{let U=$3.createServer((Z,Y)=>{let X=new Y3(Z.url,"http://localhost");if(X.pathname==="/callback"){let H=X.searchParams.get("apiKey"),B=X.searchParams.get("error");if(B){Y.writeHead(400,{"Content-Type":"text/html"}),Y.end(a$(decodeURIComponent(B))),U.close(),Q(Error(decodeURIComponent(B)));return}if(!H){Y.writeHead(400,{"Content-Type":"text/html"}),Y.end(a$("No Access Token received")),U.close(),Q(Error("No Access Token received"));return}try{W3(H),Y.writeHead(200,{"Content-Type":"text/html"}),Y.end(i0()),U.close(),z()}catch(J){Y.writeHead(500,{"Content-Type":"text/html"}),Y.end(a$("Failed to save authentication data")),U.close(),Q(J)}}else Y.writeHead(404),Y.end("Not found")});U.listen(0,"localhost",()=>{let X=`https://www.untitledui.com/react/api/cli-auth?port=${U.address().port}`;$.text="Opening browser for authentication...",z3(X).catch((H)=>{console.log(X0.yellow(`
|
|
66
|
+
Failed to open browser automatically: ${H.message}`)),console.log(X0.cyan(`Please manually open: ${X}
|
|
67
|
+
`))}),$.text="Waiting for authentication in browser..."}),setTimeout(()=>{U.close(),Q(Error("Authentication timeout. Please try again."))},300000)})}function W3($){if(!K$.existsSync(B0))K$.mkdirSync(B0,{recursive:!0});let z={};if(K$.existsSync(W0))try{z=JSON.parse(K$.readFileSync(W0,"utf-8"))}catch{z={}}z.license=$,K$.writeFileSync(W0,JSON.stringify(z,null,2),"utf-8")}import J3 from"async-retry";import I from"chalk";import{Command as y3}from"commander";import*as c from"fs";import v$ from"ora";import*as S from"path";import N$ from"prompts";import{Project as G3}from"ts-morph";import X3 from"node-fetch";async function T$($,z,Q){try{let Z=await X3("https://www.untitledui.com/react/api/components/example",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({example:$,key:z,version:Q})});if(!Z.ok){if(Z.status===401||Z.status===403)return{type:"error",status:Z.status,message:"PRO access required"};return console.error(`API error: ${Z.status} - ${Z.statusText}`),null}return await Z.json()}catch(Z){return console.error(Z),null}}import G0 from"async-retry";import h from"chalk";import{Command as B3}from"commander";import{execa as M0}from"execa";import i$ from"fast-glob";import r from"fs";import x$ from"ora";import*as u from"path";import n$ from"prompts";import{Project as H3}from"ts-morph";import{fileURLToPath as K3}from"url";import*as s$ from"fs";import*as o0 from"path";function K0($,z){let Q=o0.join($,"package.json");if(!s$.existsSync(Q))return z;let U=JSON.parse(s$.readFileSync(Q,"utf-8")),Z={...U.dependencies,...U.devDependencies},Y=[];for(let X of z){let H=Z[X];if(!H){Y.push(X);continue}if(X==="tailwindcss"){let B=H.match(/\d+/);if((B?parseInt(B[0],10):0)<4)Y.push(X)}}return Y}import q0 from"chalk";import*as y$ from"fs";import*as r$ from"path";function J0($){if(!y$.existsSync(r$.resolve($)))console.log(q0.red(`Error: CSS file not found at ${$}`)),process.exit(1);let z=y$.readFileSync(r$.resolve($),"utf-8"),Q=/(--color-[a-zA-Z-]+-\d{1,3}):\s*(rgb\([^)]+\))/g,U={},Z;while((Z=Q.exec(z))!==null)if(Z[1]&&Z[2])U[Z[1]]=Z[2];return U}function y0($,z,Q){let U=r$.resolve(Q);if(!y$.existsSync(U)){console.log(q0.red(`Error: CSS file not found at ${U}`));return}let Z=y$.readFileSync(U,"utf-8"),Y=J0(Q),X={},H={};for(let[J,j]of Object.entries(Y))if(J.startsWith(`--color-${$}-`)){let _=J.replace(`--color-${$}-`,"");X[_]=J}else if(J.startsWith(`--color-${z}-`)){let _=J.replace(`--color-${z}-`,"");H[_]=j}let B=!1;for(let[J,j]of Object.entries(X))if(H[J]){let _=H[J],L=new RegExp(`(${j}):\\s*rgb\\([^)]*\\);?`,"g");if(L.test(Z))Z=Z.replace(L,`$1: ${_};`),B=!0;else console.log(q0.yellow(`No match found for ${j}`))}if(B)y$.writeFileSync(U,Z,"utf-8")}var q3=K3(import.meta.url),t0=u.dirname(q3),$1="vite",z1="nextjs",e0={[z1]:"Next.js",[$1]:"Vite"},o="",v={color:"",template:"",framework:void 0,license:q$()},Q1=new B3().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.").option("--license <key>","API key for PRO access (alternative to stored config)").option("--lib-version <version>","component library version (7 or 8)").action(async($,z)=>{if($)o=$;if(z){if(v.color=z.color,v.template=z.template,v.overwrite=z.overwrite,v.colorsList=z.colorsList,v.license=z.license||v.license,v.version=z.libVersion,v.vite=z.vite,v.nextjs=z.nextjs,z.vite)v.framework=$1;if(z.nextjs)v.framework=z1}try{await L0(z),process.exit(0)}catch(Q){console.error(h.red(Q)),process.exit(1)}});async function L0($,z=null){let Q=process.cwd(),U=r.existsSync(u.resolve(Q,"package.json")),Z=u.resolve(u.join(t0,"../config/styles","theme.css")),Y=J0(Z??""),X=Array.from(new Set(Object.keys(Y).map((j)=>j?.split("--color-")?.[1]?.replace(/-\d{1,3}/,"")))),H=x$().start(),B=await M$(Q);if(v.license)u$(v.license);if(!U){if(H.stop(),!o){let _=await n$({onState:f,type:"text",name:"path",message:"What is your project named?",initial:"untitled-ui"});if(typeof _.path==="string")o=_.path.trim()}if(z)z.projectPath=o;let j=r.existsSync(u.resolve(u.posix.join(Q,o,"package.json")));if(r.existsSync(u.resolve(u.posix.join(Q,o)))&&j)H.fail(h.red("Directory already exists!")),process.exit(1);if(v.vite&&v.nextjs||!v.framework){let _=await n$({type:"select",name:"framework",onState:f,message:`Which ${h.cyan("framework")} would you like to use?`,choices:Object.entries(e0).map(([L,b])=>({title:b,value:L}))});v.framework=_.framework}H.succeed("Framework is selected: "+h.green(e0[v.framework]))}else if(B?.framework==="other")H.fail("Unsupported project framework"),console.log(`Please refer to the documentation ${h.cyan("https://www.untitledui.com/docs")} for supported frameworks or proceed with manual installation.`),process.exit(1);else if(B?.framework.startsWith("next")||B?.framework.startsWith("vite"))if(!z&&!B.tailwind.brandColor)H.succeed(h.yellow(`Detected ${P0[B.framework]} project, proceeding with the setup...`));else H.stop();if(v.colorsList||!v.color&&!B?.tailwind.brandColor){let j=await n$({type:"select",name:"color",onState:f,initial:$.color??"",message:`Which ${h.cyan("color")} would you like to use as the ${h.cyanBright("brand")} color?`,choices:X.map((_)=>({title:_,value:_}))});if(v.color=j.color,v.colorsList&&B)B.tailwind.brandColor=j.color}let J=u.posix.join(Q,o||"");if(o&&!U){let j=u.resolve(o);console.log(`
|
|
68
|
+
Creating a new project in ${h.blue(o)}`);let _=x$("Downloading and extracting the repository...").start();try{r.mkdirSync(j,{recursive:!0}),await G0(()=>p0(j,{template:v.framework}),{retries:2}),_.succeed("Files are downloaded and extracted successfully!");let L=x$({text:"Installing dependencies..."}).start(),b=i$.sync(["**/styles/theme.css"],{cwd:j,absolute:!0,onlyFiles:!0})[0];if(y0("brand",v.color||"",b??""),await G0(()=>M0(L$(),["install"],{cwd:J}).catch(async(W)=>{if(W.message.includes("peer"))L.warn("Dependency conflict detected. Retrying with --legacy-peer-deps..."),L.start("Installing dependencies with --legacy-peer-deps flag"),await M0(L$(),["install","--legacy-peer-deps"],{cwd:J})}),{retries:1}),await G0(()=>M0("git",["init"],{cwd:J}),{retries:1}),L.succeed("Dependencies are installed"),!z)console.log(`
|
|
69
69
|
Your project is ready, to get started run the following commands:
|
|
70
70
|
|
|
71
|
-
cd ${h.cyan(
|
|
72
|
-
${h.cyan(
|
|
73
|
-
Failed to download and extract the repository`)),
|
|
74
|
-
`);
|
|
75
|
-
`),
|
|
71
|
+
cd ${h.cyan(o)}
|
|
72
|
+
${h.cyan(m0())}`)}catch(L){if(_.fail(h.red(`
|
|
73
|
+
Failed to download and extract the repository`)),L instanceof Error)console.error(L.message);else console.error(`
|
|
74
|
+
`);r.rmdirSync(j,{recursive:!0}),process.exit(1)}}else{let j=x$(),_=new Set,L=B?.examples||"",b=I$(Q,L),W=u.resolve(u.join(t0,"../config")),V=A$(Q,v.version)==="7"?u.join(W,"v7"):W,w=i$.sync(["styles/**"],{cwd:V,onlyFiles:!0});w.push(...i$.sync(["postcss.config.*"],{cwd:W,onlyFiles:!0}));let T=K0(Q,["tailwindcss","tailwindcss-animate","@tailwindcss/typography","tailwindcss-react-aria-components"]),E=B?.framework==="vite",C=E?[]:K0(Q,["@tailwindcss/postcss","postcss"]);if(!z&&!B?.tailwind.brandColor)j.start("Copying files to the project directory");if(w.forEach((R)=>{let q=R.includes("postcss.config");if(q&&E)return;let K=u.posix.join(q?W:V,R),M=u.posix.join(Q,q?R:c$(R,B?.paths,B?.isSrcDir));if(r.existsSync(M)){if(v?.overwrite)r.copyFileSync(K,M);else{let A=r.readFileSync(M,"utf-8"),x=r.readFileSync(K,"utf-8");if(A!==x){if(R.endsWith("theme.css")&&B?.tailwind.brandColor)return;_.add({targetFile:M,sourceFile:K})}}return}r.mkdirSync(u.dirname(M),{recursive:!0}),r.writeFileSync(M,""),r.copyFileSync(K,M)}),j.stop(),_.size&&!v?.overwrite){if(console.log(`
|
|
75
|
+
`),j.fail("Following files already exist in the directory."),_.forEach((q)=>{console.log(`- ${h.green(q.targetFile)}`)}),(await n$({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0})).overwrite){let q=x$("Overwriting files").start();_.forEach((K)=>{r.copyFileSync(K.sourceFile,K.targetFile)}),q.succeed("Files are overwritten")}}if(b?.tailwindFile)console.log(`
|
|
76
76
|
Tailwind config file exists in the project directory. You can add it to your globals.css as follows:`),console.log(`
|
|
77
|
-
${h.cyan(`@config "../${
|
|
78
|
-
`);if(
|
|
77
|
+
${h.cyan(`@config "../${B?.isSrcDir?"../":""}${u.relative(Q,b.tailwindFile)}";`)}
|
|
78
|
+
`);if(B?.framework==="vite"){if(!h0(Q))console.log(`
|
|
79
79
|
Tailwind CSS is not configured in your Vite project. Please refer to the documentation ${h.cyan("https://www.untitledui.com/react/integrations/vite")} for manual installation.
|
|
80
|
-
`)}let
|
|
81
|
-
Ensure that the ${h.cyan("theme.css")} file exists in the project directory under your ${h.yellow("styles")} folder.`);if((
|
|
82
|
-
Your project is ready, you can now start adding components.`)}}var
|
|
83
|
-
|
|
84
|
-
`,""):
|
|
85
|
-
Please check your path aliases in components.json and tsconfig.json.`);
|
|
86
|
-
Failed to add the component ${
|
|
87
|
-
Following files already exist in the directory.`),
|
|
88
|
-
Use ${
|
|
89
|
-
\uD83C\uDF89 Example ${
|
|
90
|
-
`);for(let Y=0;Y<
|
|
91
|
-
|
|
92
|
-
`+
|
|
93
|
-
`;if(
|
|
80
|
+
`)}let d=b?.layoutFile||b?.appFile||B?.framework==="vite"&&b?.mainFile||"";if(d){let q=new H3({tsConfigFilePath:u.resolve(b?.tsConfig||"")}).addSourceFileAtPath(u.resolve(d)),K="styles/globals.css";if(!q.getImportDeclarations().some((A)=>{let x=A.getModuleSpecifierValue();return/(?:styles\/)?globals\.css$/.test(x)})){let A=B?.aliases?.styles||B?.aliases?.src||"",x=B?.aliases?.styles?`${A}globals.css`:`${A}styles/globals.css`;q.addImportDeclaration({moduleSpecifier:x})}q.saveSync()}let F=i$.sync(["**/theme.css"],{cwd:Q,absolute:!0,onlyFiles:!0,ignore:a});if(!F?.length)return j.fail(`Failed to copy ${h.cyan("theme.css")} file.
|
|
81
|
+
Ensure that the ${h.cyan("theme.css")} file exists in the project directory under your ${h.yellow("styles")} folder.`);if((v.color||!B?.tailwind.brandColor)&&y0("brand",v.color||"brand",F[0]??""),T.length||C.length){let R=x$().start("Installing dependencies");if(T.length)await B$(T,{cwd:J,spinner:R,label:"dependencies"});if(C.length)await B$(C,{cwd:J,dev:!0,spinner:R,label:"devDependencies"});R.succeed("Dependencies are installed")}if(!z&&!B?.tailwind.brandColor)j.succeed(h.green("Project setup is completed!"));if(z&&U){H.stop(),j.stop();return}else console.log(`
|
|
82
|
+
Your project is ready, you can now start adding components.`)}}var G={path:"",example:"",license:q$(),components:[]},V0={},Z1=new y3().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 components to.").option("-e, --example-path <example-path>","the path to add the example file to.").option("--include-all-components","automatically include all components from the example without prompting.",!1).option("-y, --yes","non-interactive mode - use defaults for all prompts (for AI agents/CI).",!1).option("--license <key>","API key for PRO access (alternative to stored config)").option("--lib-version <version>","component library version (7 or 8)").action(async($,z)=>{if($)G.example=$;if(z){if(G.path=z.path,G.overwrite=z.overwrite,G.examplePath=z.examplePath,G.includeAllComponents=z.includeAllComponents,G.yes=z.yes,G.license=z.license||G.license,G.version=z.libVersion,z.yes)G.includeAllComponents=!0,G.overwrite=!0}try{await L0(z,V0),await M3()}catch(Q){console.error(I.red(Q))}});async function M3(){let $=v$().start(),z=S.posix.join(process.cwd(),V0?.projectPath||"");if(!c.existsSync(S.posix.join(S.resolve(z,"package.json"))))$.warn("This command should be run in a project directory."),process.exit(1);let U=A$(z,G.version),Z=await M$(z);if(G.license)await l$(G.license,$);if($.stop(),!G.example){if(G.yes)console.error(I.red("Error: Example name is required in non-interactive mode.")),console.log(`Usage: ${I.cyan("npx untitledui example <example-name> --yes")}`),console.log(`Example: ${I.cyan("npx untitledui example dashboards-01/01 --yes")}`),process.exit(1);let W=await N$({type:"select",name:"example",onState:f,message:"Select which type of example you want to add",choices:[{title:"Application",value:"application"},{title:"Marketing",value:"marketing"}]});G.example=W.example}let Y=null;if(G.example){let W=await T$(G.example,G.license,U);if(W?.type==="error"&&(W.status===401||W.status===403))console.log(),console.log(I.yellow(`\uD83D\uDD12 The ${I.cyan(G.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${I.green("→")} If you've already purchased: ${I.cyan(`${X$()} untitledui@latest login`)}`),console.log(` ${I.green("→")} To purchase PRO examples: ${I.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1);if(W?.type==="directory"){if(G.yes)if(W.results.length>0)G.example=W.results[0]||"",console.log(I.yellow(`Auto-selecting: ${G.example}`)),W=await T$(G.example,G.license,U);else console.error(I.red("Error: No examples found in directory.")),process.exit(1);else{let y=await N$({type:"select",name:"example",onState:f,message:`Select a folder or file in "${G.example}"`,choices:W.results.map((V)=>({title:V,value:V}))});if(!y.example)return;G.example=y.example,W=await T$(y.example,G.license,U)}if(W?.type==="error"&&(W.status===401||W.status===403))console.log(),console.log(I.yellow(`\uD83D\uDD12 The ${I.cyan(G.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${I.green("→")} If you've already purchased: ${I.cyan(`${X$()} untitledui@latest login`)}`),console.log(` ${I.green("→")} To purchase PRO examples: ${I.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(W?.type==="json-files"){if(G.yes)if(W.results.length>0)G.example=`${G.example}/${W.results[0]}`,console.log(I.yellow(`Auto-selecting: ${G.example}`)),W=await T$(G.example,G.license,U);else console.error(I.red("Error: No example files found.")),process.exit(1);else{let y=await N$({type:"select",name:"example",onState:f,message:`Select which example you want to add from "${G.example}"`,choices:W.results.map((V)=>({title:V,value:`${G.example}/${V}`}))});if(!y.example)return;G.example=y.example,W=await T$(y.example,G.license,U)}if(W?.type==="error"&&(W.status===401||W.status===403))console.log(),console.log(I.yellow(`\uD83D\uDD12 The ${I.cyan(G.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${I.green("→")} If you've already purchased: ${I.cyan(`${X$()} untitledui@latest login`)}`),console.log(` ${I.green("→")} To purchase PRO examples: ${I.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(W?.type==="json-file")Y=W.content}if(!Y)$.fail("No example found"),process.exit(1);let X=Z?.examples||"";if(X){let W=await M$(S.posix.join(z,X));if(W)Z={...W,aliases:Z?.aliases||{}};G.examplePath=X}if(!G?.examplePath){let W=Z?.isAppDir?"app":"pages",y=Z?.isSrcDir?S.posix.join("src",W):W;if(G.yes)G.examplePath=y,console.log(I.yellow(`Using default example path: ${y}`));else{let V=await N$({type:"text",name:"examplePath",onState:f,message:`Where would you like to add the ${I.cyan(G?.example)} example?`,initial:y});G.examplePath=V.examplePath}}if(G.examplePath&&!c.existsSync(S.posix.join(z,G.examplePath)))c.mkdirSync(S.posix.join(z,G.examplePath),{recursive:!0}),console.log(I.green(`Created directory ${G.examplePath}`));if(!G?.path&&!Z?.paths?.components)if(G.yes)G.path="components",console.log(I.yellow("Using default components path: components"));else{let W=await N$({type:"text",name:"path",onState:f,message:`Where would you like to add the ${I.cyan("components")}?`,initial:"components"});G.path=W.path}if(G?.path&&Z?.paths&&!Z.paths.components)Z.paths.components=S.posix.join(Z?.isSrcDir?"src":"",G.path);if(!G?.path&&Z?.paths?.components)G.path=Z.paths.components.replace(/^src\//,"");let H=Y.components.filter((W)=>!c.existsSync(S.posix.join(z,`${Z?.isSrcDir?"src":""}`,W?.path?.replace(/components\//,G.path+"/"))));if(H?.length)if(G.includeAllComponents)G.components=H.map((W)=>W.name);else{let W=await N$({type:"multiselect",name:"components",onState:f,message:`Select which components you want to add from ${I.cyan(Y.name)} example`,choices:H.map((y)=>({title:y?.name,value:y?.name,selected:!0})),instructions:!1,hint:"- Space to select. Return to submit"});if(G.components=W.components,!H.length&&!W.components?.length)$.warn("No components selected")}let B=I$(z),J=new Set,j=new G3({tsConfigFilePath:B?.tsConfig}),_=v$(`Adding ${G?.example}...`).start(),L="",b=new Set(Y.components.filter((W)=>G.components?.includes(W.name)).map((W)=>S.dirname(W.path)));try{for(let{path:W,code:y}of Y.files||[]){let V=S.dirname(W);if(Array.from(b).some((F)=>V===F||V.startsWith(F+"/")))continue;let T=S.posix.join(z,`${Z?.isSrcDir?"src":""}`,W.replace(/components\//,G.path+"/")),E=Z?.framework==="vite"?y.replace(`"use client";
|
|
83
|
+
|
|
84
|
+
`,""):y,C=m$(E);if(W.includes("examples")){let F=S.basename(W);T=S.posix.join(z,G?.examplePath??"",F),L=S.posix.join(G?.examplePath??"",F)}let d=S.dirname(T);if(c.existsSync(T)&&!G.overwrite){if(c.readFileSync(T,"utf-8")!==C)J.add({code:C,path:T})}else{let F=d.split(S.sep),R="";for(let K of F)if(R=R?S.join(R,K):K,R&&c.existsSync(R)&&c.statSync(R).isFile())throw Error(`Cannot create directory '${d}' because '${R}' is an existing file.
|
|
85
|
+
Please check your path aliases in components.json and tsconfig.json.`);c.mkdirSync(d,{recursive:!0}),c.writeFileSync(T,C);let q=j.getSourceFile(S.resolve(T));if(q)q.replaceWithText(C);else q=j.addSourceFileAtPath(S.resolve(T));q.getImportDeclarations().forEach((K)=>{let M=K.getModuleSpecifierValue();K.setModuleSpecifier(E$(M,G.path,Z?.aliases))}),await q.save()}}if(J.size)_.warn(`Some files of ${I.yellow(G?.example)} already exist`);else _.succeed(`${I.green(G?.example)} is added successfully`)}catch(W){_.fail(`
|
|
86
|
+
Failed to add the component ${I.red(G?.example)}`),console.error(I.red(W)),process.exit(1)}if(J.size&&!G?.overwrite){console.log(`
|
|
87
|
+
Following files already exist in the directory.`),J.forEach((y)=>{console.log(I.green(`- ${S.relative(z,y.path)}`))});let W=!1;if(G.yes)W=!0,console.log(I.yellow("Auto-overwriting existing files (--yes mode)"));else{let y=await N$({type:"confirm",name:"overwrite",onState:f,message:"Do you want to overwrite the existing files?",initial:!0});if(y.overwrite===void 0)console.log(`
|
|
88
|
+
Use ${I.cyan("--overwrite")} or ${I.cyan("-o")} flag to overwrite existing files, or run with ${I.cyan("node")} instead of ${I.cyan("bun")}.`),process.exit(1);W=y.overwrite}if(W){let y=v$("Overwriting files").start();J.forEach((V)=>{let w=j.addSourceFileAtPath(S.resolve(V.path));w.replaceWithText(V.code),w.getImportDeclarations().forEach((T)=>{let E=T.getModuleSpecifierValue();T.setModuleSpecifier(E$(E,G.path,Z?.aliases))}),w.saveSync()}),y.succeed("Files are overwritten")}}if(Y?.dependencies?.length){let W=v$().start();await B$(Y.dependencies,{cwd:z,spinner:W,label:"example dependencies"})}if(Y?.devDependencies?.length){let W=v$().start();await B$(Y.devDependencies,{cwd:z,dev:!0,spinner:W,label:"example devDependencies"})}if(G?.components?.length)await J3(()=>Y0({components:G.components,dir:V0?.projectPath||"",path:G.path,message:""}),{retries:1});console.log(`
|
|
89
|
+
\uD83C\uDF89 Example ${I.green(G.example)} has been added to ${I.green(L)}`),process.exit(0)}import P from"chalk";import{Command as L3}from"commander";import W1 from"fast-glob";import _$ from"fs";import Y1 from"ora";import C$ from"path";import V3 from"prompts";var j3={ArrowRight:"ArrowNext",ArrowLeft:"ArrowPrevious",ChevronRight:"ChevronNext",ChevronLeft:"ChevronPrevious",ChevronRightDouble:"ChevronNextDouble",ChevronLeftDouble:"ChevronPreviousDouble"},N3=[{pattern:/\bml-/g,replace:"ms-",description:"ml- → ms-"},{pattern:/\bmr-/g,replace:"me-",description:"mr- → me-"},{pattern:/\bpl-/g,replace:"ps-",description:"pl- → ps-"},{pattern:/\bpr-/g,replace:"pe-",description:"pr- → pe-"},{pattern:/(?<!from-|to-|placement-)(?<!\bin-placement-)\bleft-/g,replace:"start-",description:"left- → start-"},{pattern:/(?<!from-|to-|placement-)(?<!\bin-placement-)\bright-/g,replace:"end-",description:"right- → end-"},{pattern:/\brounded-l-/g,replace:"rounded-s-",description:"rounded-l- → rounded-s-"},{pattern:/\brounded-r-/g,replace:"rounded-e-",description:"rounded-r- → rounded-e-"},{pattern:/\brounded-tl-/g,replace:"rounded-ss-",description:"rounded-tl- → rounded-ss-"},{pattern:/\brounded-tr-/g,replace:"rounded-se-",description:"rounded-tr- → rounded-se-"},{pattern:/\brounded-bl-/g,replace:"rounded-es-",description:"rounded-bl- → rounded-es-"},{pattern:/\brounded-br-/g,replace:"rounded-ee-",description:"rounded-br- → rounded-ee-"},{pattern:/\bborder-l-/g,replace:"border-s-",description:"border-l- → border-s-"},{pattern:/\bborder-r-/g,replace:"border-e-",description:"border-r- → border-e-"},{pattern:/\bborder-l\b/g,replace:"border-s",description:"border-l → border-s"},{pattern:/\bborder-r\b/g,replace:"border-e",description:"border-r → border-e"},{pattern:/\btext-left\b/g,replace:"text-start",description:"text-left → text-start"},{pattern:/\btext-right\b/g,replace:"text-end",description:"text-right → text-end"},{pattern:/\bfloat-left\b/g,replace:"float-start",description:"float-left → float-start"},{pattern:/\bfloat-right\b/g,replace:"float-end",description:"float-right → float-end"},{pattern:/\bclear-left\b/g,replace:"clear-start",description:"clear-left → clear-start"},{pattern:/\bclear-right\b/g,replace:"clear-end",description:"clear-right → clear-end"},{pattern:/\bscroll-ml-/g,replace:"scroll-ms-",description:"scroll-ml- → scroll-ms-"},{pattern:/\bscroll-mr-/g,replace:"scroll-me-",description:"scroll-mr- → scroll-me-"},{pattern:/\bscroll-pl-/g,replace:"scroll-ps-",description:"scroll-pl- → scroll-ps-"},{pattern:/\bscroll-pr-/g,replace:"scroll-pe-",description:"scroll-pr- → scroll-pe-"}],G$="(?:(sm|md|lg|xl|2xl):)?";function b$($,z){let Q=$.match(/^(sm|md|lg|xl|2xl):/);return Q?`${$} ${Q[1]}:rtl:${z}`:`${$} rtl:${z}`}var b3=[{pattern:/(?<!placement-\w+:|in-placement-\w+:|rtl:)\bslide-in-from-right(?:-([\d.]+|\[\S+\]))?\b(?!\s+rtl:slide-in-from-left)/g,replace:($)=>`${$} rtl:slide-in-from-left${$.replace("slide-in-from-right","")}`,description:"slide-in-from-right + rtl:slide-in-from-left",needsReview:!0},{pattern:/(?<!placement-\w+:|in-placement-\w+:|rtl:)\bslide-in-from-left(?:-([\d.]+|\[\S+\]))?\b(?!\s+rtl:slide-in-from-right)/g,replace:($)=>`${$} rtl:slide-in-from-right${$.replace("slide-in-from-left","")}`,description:"slide-in-from-left + rtl:slide-in-from-right",needsReview:!0},{pattern:/(?<!placement-\w+:|in-placement-\w+:|rtl:)\bslide-out-to-right(?:-([\d.]+|\[\S+\]))?\b(?!\s+rtl:slide-out-to-left)/g,replace:($)=>`${$} rtl:slide-out-to-left${$.replace("slide-out-to-right","")}`,description:"slide-out-to-right + rtl:slide-out-to-left",needsReview:!0},{pattern:/(?<!placement-\w+:|in-placement-\w+:|rtl:)\bslide-out-to-left(?:-([\d.]+|\[\S+\]))?\b(?!\s+rtl:slide-out-to-right)/g,replace:($)=>`${$} rtl:slide-out-to-right${$.replace("slide-out-to-left","")}`,description:"slide-out-to-left + rtl:slide-out-to-right",needsReview:!0},{pattern:new RegExp(`(?<![-:])${G$}translate-x-([\\d./]+(?=\\s|$|")|full|px|\\[\\S+\\])(?!\\s+rtl:)`,"g"),replace:($)=>b$($,`-${$.replace(/^(sm|md|lg|xl|2xl):/,"")}`),description:"translate-x + rtl:-translate-x",needsReview:!0},{pattern:new RegExp(`(?<=^|\\s|")${G$}-translate-x-([\\d./]+(?=\\s|$|")|full|px|\\[\\S+\\])(?!\\s+rtl:)`,"g"),replace:($)=>{let z=$.match(/^(sm|md|lg|xl|2xl):/),Q=$.slice($.indexOf("-translate-x-")+13);return z?`${$} ${z[1]}:rtl:translate-x-${Q}`:`${$} rtl:translate-x-${Q}`},description:"-translate-x + rtl:translate-x",needsReview:!0},{pattern:new RegExp(`\\b${G$}space-x-(\\d+(?:\\.\\d+)?|\\[\\S+\\])(?!\\s+(?:sm:|md:|lg:|xl:|2xl:)?rtl:space-x-reverse)`,"g"),replace:($)=>b$($,"space-x-reverse"),description:"space-x + rtl:space-x-reverse",needsReview:!0},{pattern:new RegExp(`\\b${G$}divide-x(?:-(\\d+(?:\\.\\d+)?|\\[\\S+\\]))?(?!\\s+(?:sm:|md:|lg:|xl:|2xl:)?rtl:divide-x-reverse)`,"g"),replace:($)=>b$($,"divide-x-reverse"),description:"divide-x + rtl:divide-x-reverse",needsReview:!0},{pattern:new RegExp(`(?<!rtl:)\\b${G$}bg-linear-to-r\\b(?! (?:sm:|md:|lg:|xl:|2xl:)?rtl:bg-linear-to-l)`,"g"),replace:($)=>b$($,"bg-linear-to-l"),description:"bg-linear-to-r + rtl:bg-linear-to-l",needsReview:!0},{pattern:new RegExp(`(?<!rtl:)\\b${G$}bg-linear-to-l\\b(?! (?:sm:|md:|lg:|xl:|2xl:)?rtl:bg-linear-to-r)`,"g"),replace:($)=>b$($,"bg-linear-to-r"),description:"bg-linear-to-l + rtl:bg-linear-to-r",needsReview:!0},{pattern:new RegExp(`(?<!rtl:)\\b${G$}bg-gradient-to-r\\b(?! (?:sm:|md:|lg:|xl:|2xl:)?rtl:bg-gradient-to-l)`,"g"),replace:($)=>b$($,"bg-gradient-to-l"),description:"bg-gradient-to-r + rtl:bg-gradient-to-l",needsReview:!0},{pattern:new RegExp(`(?<!rtl:)\\b${G$}bg-gradient-to-l\\b(?! (?:sm:|md:|lg:|xl:|2xl:)?rtl:bg-gradient-to-r)`,"g"),replace:($)=>b$($,"bg-gradient-to-r"),description:"bg-gradient-to-l + rtl:bg-gradient-to-r",needsReview:!0}],_3=/\bleft-1\/2\b.*-translate-x-1\/2|-translate-x-1\/2.*\bleft-1\/2\b/,X1=/\b(ml-|mr-|pl-|pr-|left-|right-|rounded-[lr]-|rounded-t[lr]-|rounded-b[lr]-|border-[lr]|text-left|text-right|float-left|float-right|scroll-m[lr]-|scroll-p[lr]-|translate-x-|space-x-|divide-x|bg-linear-to-[lr]|bg-gradient-to-[lr]|slide-in-from-(?:left|right)|slide-out-to-(?:left|right))/;function B1($,z){let Q=$;for(let U of z)Q=Q.replace(U.pattern,U.replace);return Q}function A3($,z,Q){let U={file:$,changes:[]},Z=z.split(`
|
|
90
|
+
`);for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if(/^\s*(import\b|export\b.*from\b)/.test(X)||/\brequire\s*\(/.test(X))continue;if(_3.test(X))continue;let H=X,B=!1;if(H=H.replace(/"([^"]*)"|'([^']*)'|`([^`$]*)`|`([^`$]*)\$\{/g,(J,j,_,L,b)=>{let W=j??_??L??b;if(W==null||!X1.test(W))return J;let y=B1(W,Q);if(y!==W)return B=!0,J.replace(W,y);return J}),B&&H!==X)Z[Y]=H,U.changes.push({line:Y+1,before:X.trim(),after:H.trim()})}return U}function D3($){let z=0,Q=$;for(let[U,Z]of Object.entries(j3)){let Y=new RegExp(`\\b${U}\\b`,"g"),X=Q;if(Q=Q.replace(Y,Z),Q!==X)z+=(X.match(Y)||[]).length}return{content:Q,swaps:z}}async function I3($){let z=C$.resolve($);return W1(["**/*.tsx","**/*.ts"],{cwd:z,absolute:!0,ignore:["**/node_modules/**","**/*.story.tsx","**/*.demo.tsx","**/*.test.tsx"]})}var H1="[data-rtl-flip]:dir(rtl) { transform: scaleX(-1); }";function U1($){let z=["global.css","globals.css","styles/global.css","styles/globals.css","src/global.css","src/globals.css","src/styles/global.css","src/styles/globals.css","app/global.css","app/globals.css"];for(let U of z){let Z=C$.resolve($,U);if(_$.existsSync(Z))return Z}let Q=W1.sync(["**/*.css"],{cwd:$,absolute:!0,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/.next/**"]});for(let U of Q){let Z=_$.readFileSync(U,"utf-8");if(Z.includes("@import")&&Z.includes("tailwindcss"))return U}return Q[0]||null}function E3($,z){let Q=_$.readFileSync($,"utf-8");if(Q.includes("data-rtl-flip"))return!1;let U=Q.trimEnd()+`
|
|
91
|
+
|
|
92
|
+
`+H1+`
|
|
93
|
+
`;if(!z)_$.writeFileSync($,U);return!0}var K1=new L3().name("migrate").description("migrate components for RTL support").argument("[path]","path to migrate (defaults to current directory)").option("--dry-run","preview changes without writing files",!1).option("--skip-icons","skip directional icon swapping",!1).option("-y, --yes","skip prompts and use defaults",!1).action(async($,z)=>{console.log(P.bold(`
|
|
94
94
|
Migrate to RTL
|
|
95
|
-
`));let
|
|
95
|
+
`));let Q=C$.resolve($||".");if(!_$.existsSync(Q))console.log(P.red(` Path not found: ${Q}`)),process.exit(1);let U=!z.skipIcons,Z=!0,Y=!1;if(!z.yes){let V=await V3([{type:z.skipIcons?null:"confirm",name:"swapIcons",message:"Swap directional icons for RTL-aware versions? (e.g. ArrowRight → ArrowNext)",initial:!0},{type:"confirm",name:"includeVariants",message:"Add rtl: variants for animations, gradients, translate, and space-x?",initial:!0},{type:z.dryRun?null:"confirm",name:"confirm",message:`Apply changes to ${P.cyan(Q)}?`,initial:!0}]);if(V.confirm===!1){console.log(P.yellow(`
|
|
96
96
|
Cancelled.
|
|
97
|
-
`));return}
|
|
98
|
-
`).map((
|
|
99
|
-
`)[
|
|
100
|
-
`);let
|
|
101
|
-
`),
|
|
102
|
-
`);for(let
|
|
103
|
-
`),
|
|
97
|
+
`));return}U=!z.skipIcons&&V.swapIcons!==!1,Z=V.includeVariants!==!1,Y=U}else Y=U;let X=Y1(" Scanning files...").start(),H=await I3(Q);X.succeed(` Found ${P.bold(H.length)} files`);let B=[...N3,...Z?b3:[]],J=0,j=0,_=0,L=[],b=Y1(" Transforming...").start();for(let V of H){let w=_$.readFileSync(V,"utf-8"),T=C$.relative(Q,V),E=w,C=!1,d=A3(T,E,B);if(d.changes.length>0){E=w.split(`
|
|
98
|
+
`).map((q,K)=>{return d.changes.find((A)=>A.line===K+1)?E.split(`
|
|
99
|
+
`)[K]:q}).join(`
|
|
100
|
+
`);let F=E.split(`
|
|
101
|
+
`),R=w.split(`
|
|
102
|
+
`);for(let q of d.changes){let K=q.line-1,M=R[K];M=M.replace(/"([^"]*)"|'([^']*)'|`([^`$]*)`|`([^`$]*)\$\{/g,(A,x,k,n,e)=>{let $$=x??k??n??e;if($$==null||!X1.test($$))return A;let t=B1($$,B);return t!==$$?A.replace($$,t):A}),F[K]=M}E=F.join(`
|
|
103
|
+
`),J+=d.changes.length,C=!0,L.push(d)}if(U){let F=D3(E);if(F.swaps>0)E=F.content,j+=F.swaps,C=!0}if(C){if(_++,!z.dryRun)_$.writeFileSync(V,E)}}b.succeed(` Processed ${P.bold(H.length)} files`);let W=!1,y="";if(Y&&j>0){let V=U1(Q);if(V)y=C$.relative(Q,V),W=E3(V,z.dryRun)}if(console.log(P.bold(`
|
|
104
104
|
Summary
|
|
105
|
-
`)),console.log(` Files modified: ${P.cyan(
|
|
105
|
+
`)),console.log(` Files modified: ${P.cyan(_)}`),console.log(` Class changes: ${P.cyan(J)}`),U)console.log(` Icon swaps: ${P.cyan(j)}`);if(W)console.log(` RTL flip rule: ${P.cyan("added")} → ${P.dim(y)}`);else if(Y&&j>0&&!W)if(!U1(Q))console.log(P.yellow(`
|
|
106
106
|
Could not find a global CSS file to inject the RTL flip rule.`)),console.log(P.yellow(` Add this manually to your global stylesheet:
|
|
107
|
-
`)),console.log(P.dim(` ${
|
|
108
|
-
`));else console.log(` RTL flip rule: ${P.dim("already present")}`);if(
|
|
109
|
-
Dry run — no files were modified.`)),
|
|
107
|
+
`)),console.log(P.dim(` ${H1}
|
|
108
|
+
`));else console.log(` RTL flip rule: ${P.dim("already present")}`);if(z.dryRun){if(console.log(P.yellow(`
|
|
109
|
+
Dry run — no files were modified.`)),L.length>0){console.log(P.bold(`
|
|
110
110
|
Changes preview:
|
|
111
|
-
`));for(let
|
|
112
|
-
... and ${
|
|
113
|
-
Done! ${
|
|
114
|
-
No results found for "${
|
|
115
|
-
`));return}if(
|
|
116
|
-
Components (${
|
|
117
|
-
`)),
|
|
118
|
-
`))}}if(
|
|
119
|
-
Templates (${
|
|
120
|
-
`)),
|
|
121
|
-
`))}}if(
|
|
122
|
-
Icons (${
|
|
123
|
-
`)),
|
|
124
|
-
`,"utf-8");return{updated:
|
|
125
|
-
`);for(let Y=0;Y<
|
|
126
|
-
`),
|
|
127
|
-
`),changes:
|
|
128
|
-
`);for(let
|
|
129
|
-
`),changes:
|
|
130
|
-
`);for(let{pattern:Y,instruction:
|
|
131
|
-
`);for(let Y=0;Y<
|
|
132
|
-
`,"utf-8")}async function
|
|
111
|
+
`));for(let V of L.slice(0,10)){console.log(P.dim(` ${V.file}`));for(let w of V.changes.slice(0,3))console.log(P.red(` - ${w.before.substring(0,100)}`)),console.log(P.green(` + ${w.after.substring(0,100)}`));if(V.changes.length>3)console.log(P.dim(` ... and ${V.changes.length-3} more`))}if(L.length>10)console.log(P.dim(`
|
|
112
|
+
... and ${L.length-10} more files`))}}else console.log(P.green(`
|
|
113
|
+
Done! ${_} files updated.`));console.log()});import g from"chalk";import{Command as T3}from"commander";import j0 from"node-fetch";import x3 from"ora";var N0="https://www.untitledui.com/react/api/mcp/tools";async function R3($,z,Q=10,U){return(await(await j0(`${N0}/search-components`,{method:"POST",headers:{"Content-Type":"application/json",...z&&{Authorization:`Bearer ${z}`}},body:JSON.stringify({query:$,limit:Q,version:U})})).json()).results||[]}async function S3($,z,Q=10,U){return(await(await j0(`${N0}/get-page-templates`,{method:"POST",headers:{"Content-Type":"application/json",...z&&{Authorization:`Bearer ${z}`}},body:JSON.stringify({query:$,limit:Q,version:U})})).json()).templates||[]}async function w3($,z=10){return(await(await j0(`${N0}/search-icons`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:$,limit:z})})).json()).results||[]}function v3($,z){let Q=$.access==="pro"?g.magenta(" PRO"):g.green(" FREE");if(console.log(` ${g.bold(`${z+1}. ${$.name}`)}${Q} ${g.dim(`(${$.category})`)}`),console.log(` ${g.dim($.description)}`),$.key_features?.length)console.log(` ${$.key_features.map((U)=>g.cyan(U)).join(" ")}`);console.log()}function C3($,z){if(console.log(` ${g.bold(`${z+1}. ${$.name}`)} ${g.dim(`(${$.type} · ${$.layout})`)}`),console.log(` ${g.dim($.description)}`),$.sections?.length)console.log(` ${g.dim("Sections:")} ${$.sections.map((Q)=>g.cyan(Q)).join(" ")}`);if($.hero_style)console.log(` ${g.dim("Hero:")} ${g.yellow($.hero_style)}`);console.log()}function F3($,z){if(console.log(` ${g.bold(`${z+1}. ${$.importName}`)} ${g.dim(`(${$.category})`)}`),console.log(` ${g.dim(`import { ${$.importName} } from "@untitledui/icons"`)}`),$.tags?.length)console.log(` ${$.tags.slice(0,6).map((Q)=>g.dim(Q)).join(" ")}`);console.log()}var q1=new T3().name("search").description("search for components, templates, and icons using natural language").argument("<query...>","search query (e.g., 'login with reviews', 'dark pricing table')").option("-t, --type <type>","filter by type: components, templates, icons, all","all").option("-l, --limit <number>","max results per category","5").option("-k, --key <key>","API key for PRO access").option("--lib-version <version>","component library version (7 or 8)").action(async($,z)=>{let Q=$.join(" "),U=parseInt(z.limit,10),Z=z.key||q$()||void 0,Y=z.type.toLowerCase(),X=z.libVersion,H=x3(`Searching for "${Q}"...`).start();try{let B=Y==="all"||Y==="components",J=Y==="all"||Y==="templates",j=Y==="all"||Y==="icons",[_,L,b]=await Promise.all([B?R3(Q,Z,U,X):Promise.resolve([]),J?S3(Q,Z,U,X):Promise.resolve([]),j?w3(Q,U):Promise.resolve([])]);if(H.stop(),_.length+L.length+b.length===0){console.log(g.yellow(`
|
|
114
|
+
No results found for "${Q}"
|
|
115
|
+
`));return}if(_.length>0){if(console.log(g.bold.underline(`
|
|
116
|
+
Components (${_.length})
|
|
117
|
+
`)),_.forEach(v3),_.length>0){let y=_[0].name;console.log(g.dim(` Install: npx untitledui@latest add ${y} --yes
|
|
118
|
+
`))}}if(L.length>0){if(console.log(g.bold.underline(`
|
|
119
|
+
Templates (${L.length})
|
|
120
|
+
`)),L.forEach(C3),L.length>0){let y=L[0].name;console.log(g.dim(` Install: npx untitledui@latest example ${y} --yes
|
|
121
|
+
`))}}if(b.length>0)console.log(g.bold.underline(`
|
|
122
|
+
Icons (${b.length})
|
|
123
|
+
`)),b.forEach(F3)}catch(B){H.fail("Search failed"),console.error(g.red(B instanceof Error?B.message:"Unknown error")),process.exit(1)}});import D from"chalk";import{Command as f3}from"commander";import{execa as _0}from"execa";import A0 from"fast-glob";import l from"fs";import i from"ora";import p from"path";import A1 from"prompts";var J1={fromVersion:"7",toVersion:"8",classTransforms:[{pattern:/\bshadow-xs-skeumorphic\b/g,replace:"shadow-xs-skeuomorphic",description:"shadow-xs-skeumorphic → shadow-xs-skeuomorphic (typo fix)"},{pattern:/\bshadow-skeumorphic\b/g,replace:"shadow-skeuomorphic",description:"shadow-skeumorphic → shadow-skeuomorphic (typo fix)"},{pattern:/\butility-gray-blue-/g,replace:"utility-slate-",description:"utility-gray-blue- → utility-slate-"},{pattern:/\butility-blue-light-/g,replace:"utility-sky-",description:"utility-blue-light- → utility-sky-"},{pattern:/\butility-gray-/g,replace:"utility-neutral-",description:"utility-gray- → utility-neutral-"},{pattern:/\butility-error-/g,replace:"utility-red-",description:"utility-error- → utility-red-"},{pattern:/\butility-warning-/g,replace:"utility-yellow-",description:"utility-warning- → utility-yellow-"},{pattern:/\butility-success-/g,replace:"utility-green-",description:"utility-success- → utility-green-"},{pattern:/\boutline-none\b/g,replace:"outline-hidden",description:"outline-none → outline-hidden"},{pattern:/\bbg-disabled_subtle\b/g,replace:"opacity-50",description:"bg-disabled_subtle → opacity-50",needsReview:!0},{pattern:/\bbg-disabled\b/g,replace:"opacity-50",description:"bg-disabled → opacity-50",needsReview:!0},{pattern:/\btext-disabled\b/g,replace:"",description:"text-disabled → removed",needsReview:!0},{pattern:/\bring-disabled_subtle\b/g,replace:"",description:"ring-disabled_subtle → removed",needsReview:!0},{pattern:/\bring-disabled\b/g,replace:"",description:"ring-disabled → removed",needsReview:!0},{pattern:/\bborder-disabled_subtle\b/g,replace:"",description:"border-disabled_subtle → removed",needsReview:!0},{pattern:/\bborder-disabled\b/g,replace:"",description:"border-disabled → removed",needsReview:!0},{pattern:/\btext-fg-disabled_subtle\b/g,replace:"",description:"text-fg-disabled_subtle → removed",needsReview:!0},{pattern:/\btext-fg-disabled\b/g,replace:"",description:"text-fg-disabled → removed",needsReview:!0},{pattern:/\btext-placeholder_subtle\b/g,replace:"",description:"text-placeholder_subtle → removed",needsReview:!0},{pattern:/\btext-button-primary-icon_hover\b/g,replace:"text-white/70",description:"text-button-primary-icon_hover → text-white/70"},{pattern:/\btext-button-primary-icon\b/g,replace:"text-white/60",description:"text-button-primary-icon → text-white/60"},{pattern:/\btext-button-destructive-primary-icon_hover\b/g,replace:"text-white/70",description:"text-button-destructive-primary-icon_hover → text-white/70"},{pattern:/\btext-button-destructive-primary-icon\b/g,replace:"text-white/60",description:"text-button-destructive-primary-icon → text-white/60"},{pattern:/\bbg-avatar-bg\b/g,replace:"bg-tertiary",description:"bg-avatar-bg → bg-tertiary"},{pattern:/\bring-bg-brand-solid\b/g,replace:"ring-brand-solid",description:"ring-bg-brand-solid → ring-brand-solid"},{pattern:/\bbg-active\b/g,replace:"bg-primary_hover",description:"bg-active → bg-primary_hover",needsReview:!0},{pattern:/\bbg-toggle-button-fg_disabled\b/g,replace:"",description:"bg-toggle-button-fg_disabled → removed",needsReview:!0}],importTransforms:[{from:"pin-input/pin-input",to:"input/pin-input",description:"pin-input moved into input directory"},{from:"nav-item-button",to:"nav-button",description:"nav-item-button renamed to nav-button"},{from:"select/multi-select",to:"select/tag-select",description:"multi-select renamed to tag-select (new multi-select is a different component)",symbolRenames:[{from:"MultiSelect",to:"TagSelect"}]}],propTransforms:[{from:'color="gray-blue"',to:'color="slate"',description:'color="gray-blue" renamed to color="slate"'},{from:'color="blue-light"',to:'color="sky"',description:'color="blue-light" renamed to color="sky"'}],structuralPatterns:[],orphanedTokens:["bg-disabled_subtle","text-disabled","ring-disabled","border-disabled","text-fg-disabled","bg-avatar-bg","text-button-primary-icon","text-button-destructive-primary-icon","bg-toggle-button-fg_disabled","utility-gray-","utility-error-","utility-warning-","utility-success-","utility-gray-blue-","utility-blue-light-","skeumorphic"],dependencyChanges:{update:{next:"16.2.0",react:"^19.2.4","react-dom":"^19.2.4","react-aria-components":"^1.16.0","react-aria":"^3.47.0",tailwindcss:"^4.2.2",motion:"^12.38.0",recharts:"^3.8.0"},add:{},devUpdate:{storybook:"^10.3.0",vite:"^8.0.0","@vitejs/plugin-react":"^6.0.1",eslint:"^10.0.3",typescript:"^5.9.3"},devAdd:{"@storybook/test-runner":"^0.24.3"},remove:[]},configChanges:{tsconfig:[{description:"Update JSX transform to react-jsx",find:'"jsx": "preserve"',replace:'"jsx": "react-jsx"'}]},notes:["The v7 MultiSelect (tag-chip style) has been renamed to TagSelect. The new MultiSelect is a different component with autocomplete. Update your imports accordingly.","Default size for Select, ComboBox, and Input changed from 'sm' to 'md'. Review component usage.","Avatar size 'xxs' removed. Use 'xs' instead.","Dropdown no longer defaults to selectionMode='single'. Set explicitly if needed."]};import*as R$ from"fs";import*as b0 from"path";function y1($){let{tsconfigPath:z,changes:Q,dryRun:U}=$,Z=b0.resolve(z),Y=[],X=[],H;try{H=R$.readFileSync(Z,"utf-8")}catch{return{applied:Y,skipped:Q.map((J)=>J.description)}}let B=H;for(let J of Q)if(B.includes(J.find))B=B.replace(J.find,J.replace),Y.push(J.description);else X.push(J.description);if(!U&&Y.length>0)R$.writeFileSync(Z,B,"utf-8");return{applied:Y,skipped:X}}function G1($){let{packageJsonPath:z,update:Q,add:U,devUpdate:Z,devAdd:Y,remove:X,dryRun:H}=$,B=b0.resolve(z),J=[],j=[],_=[],L;try{let b=R$.readFileSync(B,"utf-8");L=JSON.parse(b)}catch{return{updated:J,added:j,removed:_}}if(!L.dependencies)L.dependencies={};if(!L.devDependencies)L.devDependencies={};for(let[b,W]of Object.entries(Q))if(L.dependencies[b])L.dependencies[b]=W,J.push(b);for(let[b,W]of Object.entries(U))if(!L.dependencies[b])L.dependencies[b]=W,j.push(b);for(let[b,W]of Object.entries(Z))if(L.devDependencies[b])L.devDependencies[b]=W,J.push(b);for(let[b,W]of Object.entries(Y))if(!L.devDependencies[b])L.devDependencies[b]=W,j.push(b);for(let b of X){if(L.dependencies[b])delete L.dependencies[b],_.push(b);if(L.devDependencies[b]){if(delete L.devDependencies[b],!_.includes(b))_.push(b)}}if(!H&&(J.length>0||j.length>0||_.length>0))R$.writeFileSync(B,JSON.stringify(L,null,2)+`
|
|
124
|
+
`,"utf-8");return{updated:J,added:j,removed:_}}import*as S$ from"fs";import*as M1 from"path";function O3($){let z=/--color-brand-(\d+):\s*([^;]+);/g,Q={},U;while((U=z.exec($))!==null)if(U[1]&&U[2])Q[`--color-brand-${U[1]}`]=U[2].trim();return Q}function k3($,z){let Q=$;for(let[U,Z]of Object.entries(z)){let Y=new RegExp(`(${U.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}):\\s*[^;]+;`,"g");Q=Q.replace(Y,`${U}: ${Z};`)}return Q}async function L1($){let{themePath:z,newThemeContent:Q,dryRun:U}=$,Z=M1.resolve(z),Y;try{Y=S$.readFileSync(Z,"utf-8")}catch{return{brandColors:{},success:!1,message:`Theme file not found at ${Z}`}}let X=O3(Y);if(U)return{brandColors:X,success:!0,message:`Dry run: found ${Object.keys(X).length} brand color variables`};try{if(S$.writeFileSync(Z,Q,"utf-8"),Object.keys(X).length>0){let H=S$.readFileSync(Z,"utf-8"),B=k3(H,X);S$.writeFileSync(Z,B,"utf-8")}return{brandColors:X,success:!0,message:`Theme upgraded successfully. Preserved ${Object.keys(X).length} brand color variables.`}}catch(H){let B=H instanceof Error?H.message:String(H);return{brandColors:X,success:!1,message:`Failed to write theme file: ${B}`}}}var u3=/\bleft-1\/2\b.*-translate-x-1\/2|-translate-x-1\/2.*\bleft-1\/2\b/;function P3($,z){return z.some((Q)=>Q.pattern.test($))}function g3($,z){let Q=$;for(let U of z)U.pattern.lastIndex=0,Q=Q.replace(U.pattern,U.replace);return Q}function d3($,z,Q){let U=[];for(let Z of Q){if(Z.pattern.lastIndex=0,Z.pattern.test($))U.push(Z.description);Z.pattern.lastIndex=0}return U.join("; ")}function V1($,z,Q){let U={file:$,changes:[]},Z=z.split(`
|
|
125
|
+
`);for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if(/^\s*(import\b|require\s*\(|export\b.*from\b)/.test(X))continue;if(u3.test(X))continue;let H=X,B=!1;if(H=H.replace(/"([^"]*)"|'([^']*)'|`([^`$]*)`|`([^`$]*)\$\{/g,(J,j,_,L,b)=>{let W=j??_??L??b;if(W==null)return J;for(let V of Q)V.pattern.lastIndex=0;if(!P3(W,Q))return J;for(let V of Q)V.pattern.lastIndex=0;let y=g3(W,Q);if(y!==W)return B=!0,J.replace(W,y);return J}),B&&H!==X){let J=d3(X,H,Q);Z[Y]=H,U.changes.push({line:Y+1,before:X.trim(),after:H.trim(),description:J})}}return U}function j1($,z){let Q=[],U=$.split(`
|
|
126
|
+
`),Z=[];for(let Y=0;Y<U.length;Y++){let X=U[Y];if(!/^\s*(import\b|require\s*\(|export\b.*from\b)/.test(X))continue;let H=X;for(let B of z)if(H.includes(B.from)){if(H=H.replace(B.from,B.to),B.symbolRenames)Z.push(...B.symbolRenames)}if(H!==X){U[Y]=H;let B=z.find((J)=>X.includes(J.from));Q.push({line:Y+1,before:X.trim(),after:H.trim(),description:B?.description??"Import path update"})}}if(Z.length>0)for(let Y=0;Y<U.length;Y++){let X=U[Y],H=X;for(let B of Z){let J=new RegExp(`\\b${B.from}\\b`,"g");H=H.replace(J,B.to)}if(H!==X){if(U[Y]=H,!Q.some((J)=>J.line===Y+1))Q.push({line:Y+1,before:X.trim(),after:H.trim(),description:`Renamed ${Z.map((J)=>`${J.from} → ${J.to}`).join(", ")}`})}}return{content:U.join(`
|
|
127
|
+
`),changes:Q}}function N1($,z){let Q=[],U=$.split(`
|
|
128
|
+
`);for(let Z=0;Z<U.length;Z++){let Y=U[Z];if(/^\s*(import\b|require\s*\(|export\b.*from\b)/.test(Y))continue;let X=Y;for(let H of z)if(X.includes(H.from))X=X.split(H.from).join(H.to);if(X!==Y){U[Z]=X;let H=z.find((B)=>Y.includes(B.from));Q.push({line:Z+1,before:Y.trim(),after:X.trim(),description:H?.description??"Prop update"})}}return{content:U.join(`
|
|
129
|
+
`),changes:Q}}function b1($,z,Q){let U=[],Z=z.split(`
|
|
130
|
+
`);for(let{pattern:Y,instruction:X}of Q)for(let H=0;H<Z.length;H++){if(/^\s*(import\b|export\b.*from\b)/.test(Z[H])||/\brequire\s*\(/.test(Z[H]))continue;if(Z[H].includes(Y))U.push({file:$,line:H+1,pattern:Y,instruction:X})}return U}function _1($,z,Q){let U=[],Z=z.split(`
|
|
131
|
+
`);for(let Y=0;Y<Z.length;Y++)for(let X of Q)if(Z[Y].includes(X))U.push({file:$,line:Y+1,token:X});return U}function h3($){return{fromVersion:$.fromVersion,toVersion:$.toVersion,classTransforms:$.classRenames.map((z)=>({pattern:new RegExp(`\\b${I1(z.from)}\\b`,"g"),replace:z.to,description:z.description,needsReview:z.needsReview})),importTransforms:$.importRenames,propTransforms:$.propRenames,structuralPatterns:$.structuralPatterns,orphanedTokens:$.orphanedTokens,dependencyChanges:$.dependencyChanges,configChanges:$.configChanges,notes:$.notes}}function I1($){return $.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function m3($){let z=p.join($,"components.json");try{return JSON.parse(l.readFileSync(z,"utf-8"))}catch{return null}}function c3($,z){let Q=p.join($,"components.json");l.writeFileSync(Q,JSON.stringify(z,null,2)+`
|
|
132
|
+
`,"utf-8")}async function D1($){let z=p.resolve($);return A0(["**/*.{tsx,ts}"],{cwd:z,absolute:!0,ignore:["**/node_modules/**","**/*.story.tsx","**/*.demo.tsx","**/.next/**","**/dist/**","**/build/**"]})}async function l3($){return(await A0(["**/theme.css"],{cwd:$,absolute:!0,deep:5,ignore:["**/node_modules/**","**/.next/**","**/dist/**"]}))[0]}function p3($){let z=p.join($,"package.json");return l.existsSync(z)?z:void 0}function a3($){let z=p.join($,"tsconfig.json");return l.existsSync(z)?z:void 0}function s3($){let z=0;for(let Q=0;Q<$.length;Q++){let U=$.charCodeAt(Q);z=(z<<5)-z+U|0}return z.toString(36)}var E1=new f3().name("upgrade").description("upgrade your project to the latest version of Untitled UI").option("--dry-run","preview changes without writing files",!1).option("--skip-theme","skip theme.css replacement",!1).option("--skip-deps","skip dependency updates",!1).option("--skip-config","skip config file updates",!1).option("--path <dir>","directory to scan for source files").option("-y, --yes","skip prompts and use defaults",!1).action(async($)=>{console.log(D.bold(`
|
|
133
133
|
Upgrade Untitled UI
|
|
134
|
-
`));let
|
|
134
|
+
`));let z=p.resolve($.path||".");try{let{stdout:q}=await _0("git",["status","--porcelain"],{cwd:z});if(q.trim().length>0){if(console.log(D.yellow(" You have uncommitted changes. We recommend committing first so you can\n revert with `git checkout .` if needed.")),!$.yes){let{proceed:K}=await A1({type:"confirm",name:"proceed",message:"Continue with uncommitted changes?",initial:!0});if(!K){console.log(D.yellow(`
|
|
135
135
|
Cancelled.
|
|
136
|
-
`));return}}console.log()}}catch{}let
|
|
137
|
-
`),
|
|
138
|
-
`));return}let
|
|
139
|
-
`);for(let t of k.changes){let
|
|
140
|
-
`),
|
|
141
|
-
`).filter((
|
|
142
|
-
`,"utf-8")}catch{}if(W.length>0||
|
|
136
|
+
`));return}}console.log()}}catch{}let Q=m3(z),U=Q?.version??"7";if(console.log(` Detected version: ${D.cyan(U)}
|
|
137
|
+
`),U==="8"){console.log(D.green(` Already on version 8. Nothing to upgrade.
|
|
138
|
+
`));return}let Z,Y,X=i(" Fetching migration rules...").start();try{let q=await fetch("https://www.untitledui.com/react/api/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fromVersion:U,toVersion:"8"})});if(!q.ok)throw Error(`Server returned ${q.status}`);let K=await q.json();Z=h3(K),Y="server",X.succeed(" Migration rules fetched from server")}catch{Z=J1,Y="built-in",X.warn(" Could not reach server. Using built-in migration rules")}let H=i(" Scanning files...").start(),B=await D1(z);H.succeed(` Found ${D.bold(B.length)} source files`);let J=0,j=0,_=0,L=0,b=[],W=[],y=[],V=[];if(!$.skipTheme){let q=i(" Upgrading theme.css...").start(),K=await l3(z);if(K)try{let M=p.resolve(import.meta.dirname,"../config/styles/theme.css"),A=l.readFileSync(M,"utf-8"),x=await L1({themePath:K,newThemeContent:A,dryRun:$.dryRun});if(x.success){let k=Object.keys(x.brandColors);if(k.length>0)q.succeed(` Theme upgraded. Brand colors preserved: ${D.cyan(k.join(", "))}`);else q.succeed(" Theme upgraded (no custom brand colors found)")}else q.warn(` Theme upgrade issue: ${x.message}`)}catch(M){let A=M instanceof Error?M.message:String(M);q.warn(` Theme upgrade skipped: ${A}`)}else q.warn(" No theme.css found — skipping theme upgrade")}if(!$.skipConfig){let q=i(" Updating config files...").start(),K=a3(z);if(K&&Z.configChanges.tsconfig.length>0){let{applied:M,skipped:A}=y1({tsconfigPath:K,changes:Z.configChanges.tsconfig,dryRun:$.dryRun});if(M.length>0)q.succeed(` Config updated: ${M.map((x)=>D.cyan(x)).join(", ")}`);else q.info(" No config changes needed");if(A.length>0)for(let x of A)console.log(D.dim(` Skipped: ${x}`))}else q.info(" No config changes to apply")}if(!$.skipDeps){let q=i(" Updating dependencies...").start(),K=p3(z);if(K){let M=G1({packageJsonPath:K,update:Z.dependencyChanges.update,add:Z.dependencyChanges.add,devUpdate:Z.dependencyChanges.devUpdate,devAdd:Z.dependencyChanges.devAdd,remove:Z.dependencyChanges.remove,dryRun:$.dryRun});if(M.updated.length+M.added.length+M.removed.length>0){if(q.succeed(" Dependencies updated in package.json"),M.updated.length>0)console.log(D.dim(` Updated: ${M.updated.join(", ")}`));if(M.added.length>0)console.log(D.dim(` Added: ${M.added.join(", ")}`));if(M.removed.length>0)console.log(D.dim(` Removed: ${M.removed.join(", ")}`));if(!$.dryRun){let x=i(" Installing dependencies...").start();try{let k=X$();await _0(k==="bunx"?"bun":k==="pnpx"?"pnpm":k==="yarn"?"yarn":"npm",["install"],{cwd:z}),x.succeed(" Dependencies installed")}catch(k){let n=k instanceof Error?k.message:String(k);x.warn(` Could not auto-install dependencies: ${n.substring(0,100)}`),console.log(D.dim(" Run your package manager's install command manually."))}}}else q.info(" No dependency changes needed")}else q.warn(" No package.json found — skipping dependency updates")}let w=i(" Renaming files...").start(),T=new Set;for(let q of Z.importTransforms){let K=q.from.split("/").pop(),M=q.to.split("/").pop();if(K===M)continue;let A=A0.sync([`**/${K}.tsx`,`**/${K}.ts`],{cwd:z,absolute:!0,ignore:["**/node_modules/**"]});for(let x of A){let k=x.replace(new RegExp(`${I1(K)}(\\.tsx?)$`),`${M}$1`);if(!$.dryRun)try{l.renameSync(x,k),T.add(q.from)}catch{}else T.add(q.from)}}let E=Z.importTransforms.filter((q)=>{let K=q.from.split("/").pop(),M=q.to.split("/").pop();if(K===M)return!0;return T.has(q.from)});if(T.size>0)w.succeed(` Renamed ${D.bold(T.size)} files`),B.length=0,B.push(...await D1(z));else w.info(" No file renames needed");let C=i(" Applying source transforms...").start();for(let q of B){let K;try{K=l.readFileSync(q,"utf-8")}catch{continue}let M=p.relative(z,q),A=K,x=!1,k=V1(M,A,Z.classTransforms);if(k.changes.length>0){let $$=A.split(`
|
|
139
|
+
`);for(let t of k.changes){let F$=t.line-1,z$=$$[F$];z$=z$.replace(/"([^"]*)"|'([^']*)'|`([^`$]*)`|`([^`$]*)\$\{/g,(o$,T1,x1,R1,S1)=>{let O$=T1??x1??R1??S1;if(O$==null)return o$;let k$=O$;for(let t$ of Z.classTransforms)t$.pattern.lastIndex=0,k$=k$.replace(t$.pattern,t$.replace);return k$!==O$?o$.replace(O$,k$):o$}),$$[F$]=z$}A=$$.join(`
|
|
140
|
+
`),J+=k.changes.length,x=!0,b.push(k);for(let t of k.changes){let F$=Z.classTransforms.find((z$)=>{return z$.pattern.lastIndex=0,z$.needsReview&&z$.pattern.test(t.before)});for(let z$ of Z.classTransforms)z$.pattern.lastIndex=0;if(F$)W.push({file:M,line:t.line,description:t.description,before:t.before,after:t.after})}}let n=N1(A,Z.propTransforms);if(n.changes.length>0)A=n.content,j+=n.changes.length,x=!0;let e=j1(A,E);if(e.changes.length>0)A=e.content,_+=e.changes.length,x=!0;if(x){if(L++,!$.dryRun)l.writeFileSync(q,A)}}C.succeed(` Processed ${D.bold(B.length)} files`);let d=i(" Detecting structural patterns...").start();for(let q of B){let K;try{K=l.readFileSync(q,"utf-8")}catch{continue}let M=p.relative(z,q),A=b1(M,K,Z.structuralPatterns);V.push(...A)}if(V.length>0)d.warn(` Found ${D.bold(V.length)} structural patterns requiring manual review`);else d.succeed(" No structural patterns found");if(Q?.components&&Array.isArray(Q.components)&&Q.components.some((q)=>q.contentHash)){let q=i(" Checking stock components...").start(),K=[];for(let M of Q.components){if(!M.contentHash||!M.filePath)continue;let A=p.resolve(z,M.filePath);try{let x=l.readFileSync(A,"utf-8");if(s3(x)===M.contentHash)K.push({name:M.name,path:M.filePath})}catch{}}if(K.length>0){q.info(` ${D.bold(K.length)} stock components can be auto-refreshed`);let M=$.yes;if(!M){let{confirm:A}=await A1({type:"confirm",name:"confirm",message:`Refresh ${K.length} unmodified stock components to v8.0?`,initial:!0});M=A}if(M&&!$.dryRun){let A=i(" Fetching v8.0 components...").start();try{let x=await fetch("https://www.untitledui.com/react/api/components",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({components:K.map((k)=>k.name),version:"8"})});if(x.ok){let k=await x.json(),n=0;for(let e of K)if(k[e.name])l.writeFileSync(p.resolve(z,e.path),k[e.name]),n++;A.succeed(` Refreshed ${D.bold(n)} stock components`)}else A.warn(" Could not fetch v8.0 components from server")}catch{A.warn(" Could not reach server for component refresh")}}}else q.info(" No unmodified stock components to refresh")}let F=i(" Scanning for orphaned tokens...").start();for(let q of B){let K;try{K=l.readFileSync(q,"utf-8")}catch{continue}let M=p.relative(z,q),A=_1(M,K,Z.orphanedTokens);y.push(...A)}if(y.length>0)F.warn(` Found ${D.bold(y.length)} orphaned v7.0 tokens remaining`);else F.succeed(" No orphaned tokens found");let R=[];if(!$.dryRun){let q=i(" Running type check...").start();try{let K=X$();await _0(K,["tsc","--noEmit"],{cwd:z}),q.succeed(" Type check passed")}catch(K){let A=(K?.stderr||K?.stdout||"").split(`
|
|
141
|
+
`).filter((x)=>x.includes("error TS")).slice(0,20);R.push(...A),q.warn(` Type check found ${D.bold(A.length)} error(s)`)}}if(!$.dryRun){let q={version:"8",status:W.length>0||y.length>0?"partial":"success",filesScanned:B.length,filesModified:L,classChanges:J,propChanges:j,importChanges:_,manualReview:W,orphanedTokens:y,typeErrors:R,structuralPatterns:V,notes:Z.notes};try{l.writeFileSync(p.join(z,"upgrade-report.json"),JSON.stringify(q,null,2)+`
|
|
142
|
+
`,"utf-8")}catch{}if(W.length>0||V.length>0)try{let K=`# Untitled UI v7.0 to v8.0 Upgrade Instructions
|
|
143
143
|
|
|
144
|
-
`;if(
|
|
144
|
+
`;if(K+="This file was generated by `untitledui upgrade`. It is meant to guide\n",K+=`manual review of changes that could not be fully automated.
|
|
145
145
|
|
|
146
|
-
`,
|
|
147
|
-
`,
|
|
146
|
+
`,K+=`**Important**: Ignore pre-existing type errors and linting issues.
|
|
147
|
+
`,K+=`Focus only on migration-related changes listed below.
|
|
148
148
|
|
|
149
|
-
`,
|
|
149
|
+
`,K+=`Delete this file after review is complete.
|
|
150
150
|
|
|
151
|
-
`,
|
|
151
|
+
`,V.length>0){K+=`## Structural changes
|
|
152
152
|
|
|
153
|
-
`,
|
|
153
|
+
`,K+=`These patterns require manual refactoring:
|
|
154
154
|
|
|
155
|
-
`;for(let
|
|
156
|
-
`,
|
|
155
|
+
`;for(let M of V)K+=`- **${M.file}:${M.line}** — \`${M.pattern}\`
|
|
156
|
+
`,K+=` ${M.instruction}
|
|
157
157
|
|
|
158
|
-
`}if(W.length>0){
|
|
158
|
+
`}if(W.length>0){K+=`## Manual review items
|
|
159
159
|
|
|
160
|
-
`,
|
|
160
|
+
`,K+=`These class replacements may need manual verification:
|
|
161
161
|
|
|
162
|
-
`;for(let
|
|
162
|
+
`;for(let M of W)K+=`### ${M.file}:${M.line}
|
|
163
163
|
|
|
164
|
-
`,
|
|
164
|
+
`,K+=`${M.description}
|
|
165
165
|
|
|
166
|
-
`,
|
|
167
|
-
`,
|
|
168
|
-
`,
|
|
166
|
+
`,K+="```diff\n",K+=`- ${M.before}
|
|
167
|
+
`,K+=`+ ${M.after}
|
|
168
|
+
`,K+="```\n\n"}if(Z.notes.length>0){K+=`## Additional notes
|
|
169
169
|
|
|
170
|
-
`;for(let
|
|
171
|
-
`;
|
|
172
|
-
`}
|
|
170
|
+
`;for(let M of Z.notes)K+=`- ${M}
|
|
171
|
+
`;K+=`
|
|
172
|
+
`}l.writeFileSync(p.join(z,"UPGRADE-INSTRUCTIONS.md"),K,"utf-8")}catch{}}if(!$.dryRun&&Q)Q.version="8",c3(z,Q);if(console.log(D.bold(`
|
|
173
173
|
Summary
|
|
174
|
-
`)),console.log(` Migration source: ${
|
|
175
|
-
Dry run — no files were modified.`)),
|
|
174
|
+
`)),console.log(` Migration source: ${D.cyan(Y)}`),console.log(` Files scanned: ${D.cyan(B.length)}`),console.log(` Files modified: ${D.cyan(L)}`),console.log(` Class changes: ${D.cyan(J)}`),console.log(` Prop changes: ${D.cyan(j)}`),console.log(` Import changes: ${D.cyan(_)}`),V.length>0){console.log(` Structural patterns: ${D.yellow(V.length)}`);for(let q of V.slice(0,5))console.log(D.dim(` ${q.file}:${q.line} — ${q.pattern}`));if(V.length>5)console.log(D.dim(` ... and ${V.length-5} more (see UPGRADE-INSTRUCTIONS.md)`))}if(W.length>0){console.log(` Manual review items: ${D.yellow(W.length)}`);for(let q of W.slice(0,5))console.log(D.dim(` ${q.file}:${q.line} — ${q.description}`));if(W.length>5)console.log(D.dim(` ... and ${W.length-5} more (see UPGRADE-INSTRUCTIONS.md)`))}if(y.length>0){console.log(` Orphaned tokens: ${D.yellow(y.length)}`);let q=[...new Set(y.map((K)=>K.token))];for(let K of q.slice(0,5))console.log(D.dim(` ${K}`));if(q.length>5)console.log(D.dim(` ... and ${q.length-5} more`))}if(R.length>0)console.log(` Type errors: ${D.yellow(R.length)}`);if($.dryRun){if(console.log(D.yellow(`
|
|
175
|
+
Dry run — no files were modified.`)),b.length>0){console.log(D.bold(`
|
|
176
176
|
Changes preview:
|
|
177
|
-
`));for(let
|
|
178
|
-
... and ${
|
|
177
|
+
`));for(let q of b.slice(0,10)){console.log(D.dim(` ${q.file}`));for(let K of q.changes.slice(0,3))console.log(D.red(` - ${K.before.substring(0,100)}`)),console.log(D.green(` + ${K.after.substring(0,100)}`));if(q.changes.length>3)console.log(D.dim(` ... and ${q.changes.length-3} more`))}if(b.length>10)console.log(D.dim(`
|
|
178
|
+
... and ${b.length-10} more files`))}console.log(D.dim(`
|
|
179
179
|
Run without --dry-run to apply changes.
|
|
180
|
-
`))}else console.log(
|
|
180
|
+
`))}else console.log(D.green("\n Done! Run `bun run build` to verify.")),console.log(D.dim(" If something went wrong, run `git checkout .` to revert.\n"))});var D0={name:"untitledui",version:"0.1.60",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:"bun test __tests__/",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",repository:{type:"git",url:"https://github.com/untitleduico/react.git",directory:"cli"},engines:{node:">=18"},keywords:["untitledui","untitled-ui","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.6.2",commander:"^13.1.0",execa:"^7.2.0","fast-glob":"^3.3.3","node-fetch":"^3.3.2",open:"^10.2.0",ora:"^8.2.0",prettier:"^3.7.4",prompts:"^2.4.2",tar:"^7.5.2","ts-morph":"^25.0.1","tsconfig-paths":"^4.2.0","update-check":"^1.5.4"},devDependencies:{"@types/async-retry":"^1.4.9","@types/bun":"^1.3.10","@types/prompts":"^2.4.9","@types/tar":"^6.1.13","type-fest":"^4.41.0",typescript:"^5.9.3"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function n3(){let $=new i3().name(D0.name).version(D0.version);$.addCommand(Q1).addCommand(s0).addCommand(Z1).addCommand(q1).addCommand(n0).addCommand(K1).addCommand(E1),$.parse()}n3();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "untitledui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
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",
|