untitledui 0.1.56-beta.0 → 0.1.56
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/config/migrations/7-to-8.ts +12 -10
- package/dist/index.mjs +104 -104
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ export interface MigrationDefinition {
|
|
|
4
4
|
fromVersion: string;
|
|
5
5
|
toVersion: string;
|
|
6
6
|
classTransforms: TransformRule[];
|
|
7
|
-
importTransforms: { from: string; to: string; description: string }[];
|
|
7
|
+
importTransforms: { from: string; to: string; description: string; symbolRenames?: { from: string; to: string }[] }[];
|
|
8
8
|
propTransforms: { from: string; to: string; description: string }[];
|
|
9
9
|
structuralPatterns: { pattern: string; instruction: string }[];
|
|
10
10
|
orphanedTokens: string[];
|
|
@@ -26,11 +26,11 @@ export const migration: MigrationDefinition = {
|
|
|
26
26
|
toVersion: "8",
|
|
27
27
|
|
|
28
28
|
classTransforms: [
|
|
29
|
-
// Typo fix
|
|
29
|
+
// Typo fix: skeumorphic → skeuomorphic (handle all orderings)
|
|
30
30
|
{
|
|
31
|
-
pattern: /\bshadow-skeumorphic
|
|
32
|
-
replace: "shadow-skeuomorphic
|
|
33
|
-
description: "shadow-skeumorphic
|
|
31
|
+
pattern: /\bshadow-xs-skeumorphic\b/g,
|
|
32
|
+
replace: "shadow-xs-skeuomorphic",
|
|
33
|
+
description: "shadow-xs-skeumorphic → shadow-xs-skeuomorphic (typo fix)",
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
pattern: /\bshadow-skeumorphic\b/g,
|
|
@@ -197,14 +197,15 @@ export const migration: MigrationDefinition = {
|
|
|
197
197
|
to: "nav-button",
|
|
198
198
|
description: "nav-item-button renamed to nav-button",
|
|
199
199
|
},
|
|
200
|
+
{
|
|
201
|
+
from: "select/multi-select",
|
|
202
|
+
to: "select/tag-select",
|
|
203
|
+
description: "multi-select renamed to tag-select (new multi-select is a different component)",
|
|
204
|
+
symbolRenames: [{ from: "MultiSelect", to: "TagSelect" }],
|
|
205
|
+
},
|
|
200
206
|
],
|
|
201
207
|
|
|
202
208
|
propTransforms: [
|
|
203
|
-
{
|
|
204
|
-
from: "placeholderIcon=",
|
|
205
|
-
to: "icon=",
|
|
206
|
-
description: "placeholderIcon prop renamed to icon",
|
|
207
|
-
},
|
|
208
209
|
{
|
|
209
210
|
from: 'color="gray-blue"',
|
|
210
211
|
to: 'color="slate"',
|
|
@@ -280,6 +281,7 @@ export const migration: MigrationDefinition = {
|
|
|
280
281
|
},
|
|
281
282
|
|
|
282
283
|
notes: [
|
|
284
|
+
"The v7 MultiSelect (tag-chip style) has been renamed to TagSelect. The new MultiSelect is a different component with autocomplete. Update your imports accordingly.",
|
|
283
285
|
"Default size for Select, ComboBox, and Input changed from 'sm' to 'md'. Review component usage.",
|
|
284
286
|
"Avatar size 'xxs' removed. Use 'xs' instead.",
|
|
285
287
|
"Dropdown no longer defaults to selectionMode='single'. Set explicitly if needed.",
|
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
|
-
`)),z.forEach(([
|
|
2
|
+
import{Command as r1}from"commander";import C from"chalk";import{Command as s0}from"commander";import*as i from"fs";import vy from"ora";import*as h from"path";import Jy from"prompts";import{Project as r0}from"ts-morph";import*as jy from"fs";import*as py from"path";import I0 from"os";var N$=py.join(I0.homedir(),".untitledui"),ny=py.join(N$,"config.json");function w$(y=ny){if(!jy.existsSync(y))return{};try{return JSON.parse(jy.readFileSync(y,"utf-8"))}catch{return{}}}function My(y=ny){return w$(y).license||""}function Oy(y,$=N$,j=ny){if(!jy.existsSync($))jy.mkdirSync($,{recursive:!0});let z=w$(j);if(z.license!==y)z.license=y,jy.writeFileSync(j,JSON.stringify(z,null,2),"utf-8")}import T0 from"node-fetch";var A$={invalid_key:"Invalid key provided",no_components_found:"No components found",no_components_provided:"No components provided"};async function ky(y,$,j){let Y=$.map((W)=>{if(W.includes("modals/"))if(W.includes("-modal"))return W;else return W+"-modal";return W});try{let W=await T0("http://localhost:3000/react/api/components",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({type:y,components:Y,key:j})});if(!W.ok)console.log(A$?.[W.statusText]||A$.no_components_found),process.exit(1);return await W.json()}catch(W){return null}}import ty from"node-fetch";var Ny={invalid_key:"Invalid key provided",no_components_found:"No components found",no_components_provided:"No components provided"};async function E$(y,$=""){let j=`http://localhost:3000/react/api/components/list?key=${$}&type=${y}`;try{let z=await ty(j),Y=await z.json();if(!z.ok)console.log(Ny?.[z.statusText]||Ny.no_components_found),process.exit(1);if(!Y?.components?.length)return null;return Y}catch(z){return console.error(z),null}}async function x$(y,$="",j){let z=`http://localhost:3000/react/api/components/list?key=${$}&type=${y}&subfolders=${j.join(",")}`;try{let Y=await ty(z);if(!Y.ok)console.log(Ny?.[Y.statusText]||Ny.no_components_found),process.exit(1);let W=await Y.json();if(!W?.components?.length)return null;return W}catch(Y){return console.error(Y),null}}async function I$(y=""){let $=`http://localhost:3000/react/api/components/list?key=${y}`;try{let j=await ty($);if(!j.ok)console.log(Ny?.[j.statusText]||Ny.no_components_found),process.exit(1);let z=await j.json();if(!z?.types?.length)return null;return z}catch(j){return console.error(j),null}}import y$ from"fast-glob";import*as dy from"fs";import*as Wy from"path";import{Project as O0}from"ts-morph";import{loadConfig as k$}from"tsconfig-paths";import v0 from"prettier";async function T$(y,$="typescript"){try{return await v0.format(y,{parser:$,printWidth:160,tabWidth:4})}catch(j){return console.error("Error formatting with Prettier:",j),y}}import zy from"chalk";import Vy from"fast-glob";import*as Qy from"fs";import*as Yy from"path";import{loadConfig as gy}from"tsconfig-paths";import v$ from"fs";import S0 from"path";function S$(y=""){let $=S0.join(y,"package.json");if(!v$.existsSync($))return null;else return JSON.parse(v$.readFileSync($,"utf-8"))}import ey from"fs";import F$ from"path";import{createMatchPath as R$}from"tsconfig-paths";function C$(y,$){let j=F$.posix.join(y,"index"),z=(W)=>{try{return ey.existsSync(W)}catch{return!0}},Y=R$($.absoluteBaseUrl,$.paths)(j,void 0,z,[".ts",".tsx",".jsx",".js",".css"]);if(!Y)Y=R$($.absoluteBaseUrl,$.paths)(j,void 0,()=>!0,[".ts",".tsx",".jsx",".js",".css"]);if(Y){let W=Y.split("/").slice(0,-1).join("/");try{if(ey.existsSync(W)&&ey.statSync(W).isFile())return F$.dirname(W)}catch{}return W}else return}var l=["**/node_modules/**",".next","public","dist","build"],Py=!1,u$={"next-app":"Next.js (App)","next-pages":"Next.js (Pages)",vite:"Vite",other:"Other"};async function By(y){let $=Qy.existsSync(Yy.resolve(y,"src")),j=Qy.existsSync(Yy.resolve(y,`${$?"src/":""}app`)),[z,Y,W,Z,X]=await Promise.all([Vy.glob("**/{next,vite,astro}.config.*|gatsby-config.*",{cwd:y,deep:2,ignore:l}),F0(y),C0(y),u0(y),S$(y)]),U=Qy.existsSync(Yy.resolve(y,"components.json")),V=null;if(U)V=JSON.parse(Qy.readFileSync(Yy.resolve(y,"components.json"),"utf-8"));let B=Vy.sync(["**/**/theme.css"],{cwd:y,absolute:!0,onlyFiles:!0,ignore:l}),b=B?.[0]&&Qy.readFileSync(B[0],"utf-8").match(/(--color-brand+-\d{1,3}):\s*(rgb\([^)]+\))/g)?.[1]||void 0,q={tailwind:{config:W||void 0,brandColor:b?.replace(/--color-([^-]+(?:-[^-]+)?)-\d+:.*/,"$1")||void 0},examples:V?.examples||void 0,aliases:V?.aliases||Z||{},paths:await R0(V?.aliases||{})||{},isTsx:Y,isSrcDir:$,isAppDir:j,isComponentsJson:!!U,framework:"other"};if(z.find((Q)=>Q.startsWith("next.config."))?.length)return q.framework=j?"next-app":"next-pages",q;else if(z.find((Q)=>Q.startsWith("vite.config."))?.length)return q.framework="vite",q;else if(Object.keys(X?.dependencies||{}).includes("react"))return q.framework="next-pages",q;else if(z?.length||Qy.existsSync(Yy.resolve(y,"package.json")))return q.framework="other",q;return null}async function F0(y){return(await Vy.glob("tsconfig.*",{cwd:y,deep:2,ignore:l})).length>0}async function R0(y){let $={},j=[],z=Object.entries(y).filter(([,U])=>U);if(z.length===0)return null;let Y=process.cwd(),Z=gy(Y).resultType==="success",X=await O$(Y);if(!X){if(!Py){if(Py=!0,process.stdout.write("\r\x1B[K"),Z)console.log(zy.yellow(`
|
|
3
|
+
⚠ Could not resolve path aliases from components.json - no paths configured in tsconfig.json.`));else console.log(zy.yellow(`
|
|
4
|
+
⚠ Could not resolve path aliases from components.json - tsconfig.json not found.`));console.log(zy.dim(` The following aliases will be used for imports but files will be placed in default locations:
|
|
5
|
+
`)),z.forEach(([U,V])=>{console.log(zy.dim(` ${U}: ${V}`))}),console.log(zy.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:`)),j.forEach((
|
|
9
|
-
These aliases will be used for imports but files will be placed in default locations.`)),console.log(
|
|
10
|
-
`));return $}async function
|
|
11
|
-
"paths": ${JSON.stringify(z.paths)},`);else Z=W.replace(X,`"paths": ${JSON.stringify(z.paths)}`);let V=new
|
|
12
|
-
`),process.exit(1)};function
|
|
13
|
-
|
|
14
|
-
`,""):I
|
|
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.`),X.forEach((
|
|
18
|
-
Use ${
|
|
7
|
+
`))}return null}for(let[U,V]of Object.entries(y))if(V){let B=await C$(V.replace(/\/\*$/,""),X);if(B)$[U]=Yy.relative(process.cwd(),B);else j.push(`${U}: ${V}`)}if(j.length>0&&!Py)Py=!0,process.stdout.write("\r\x1B[K"),console.log(zy.yellow(`
|
|
8
|
+
⚠ Could not resolve the following path aliases from tsconfig.json:`)),j.forEach((U)=>{console.log(zy.dim(` ${U}`))}),console.log(zy.dim(`
|
|
9
|
+
These aliases will be used for imports but files will be placed in default locations.`)),console.log(zy.dim(` To fix this, add matching paths to your tsconfig.json.
|
|
10
|
+
`));return $}async function O$(y){let[$,j]=await Promise.all([Vy.glob("next.config.*",{cwd:y,deep:1,ignore:l}),Vy.glob("vite.config.*",{cwd:y,deep:1,ignore:l})]),z=$.length>0,Y=j.length>0,W=null;if(z)W=gy(y);else if(Y){if(W=gy(y),W?.resultType==="failed"||!Object.keys(W.paths||{}).length){let Z=await Vy.glob(["tsconfig.app.*","*/tsconfig.app.*"],{cwd:y,deep:1,onlyFiles:!0,absolute:!0,ignore:l}),[X]=Z;if(X)try{let V=function(q){return q.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"").replace(/,(\s*[}\]])/g,"$1")},U=Qy.readFileSync(X,"utf-8"),B=V(U),b=JSON.parse(B);if(b.compilerOptions?.paths)W={resultType:"success",paths:b?.compilerOptions?.paths,baseUrl:b.compilerOptions.baseUrl||".",configFileAbsolutePath:X,absoluteBaseUrl:Yy.resolve(y,b.compilerOptions.baseUrl||".")}}catch{}}}else W=gy(y);if(!W||W?.resultType==="failed"||!Object.keys(W.paths).length)return null;return W}async function C0(y){let $=await Vy.glob("tailwind.config.*",{cwd:y,deep:2,ignore:l});if(!$.length)return null;return $[0]}async function u0(y){let $=await O$(y);if(!$)return null;let j={},z={app:/\/?app\/\*$/,components:/\/?components\/\*$/,utils:/\/?utils\/\*$/,styles:/\/?styles\/\*$/,hooks:/\/?hooks\/\*$/,src:/^(\.\/src\/\*|\.\/\*|\/src\/\*|src\/\*|\/\*|\*)$/};for(let[Y,W]of Object.entries($.paths)){let Z=Y.replace(/\/\*$/,"/");for(let[X,U]of Object.entries(z))if(W.some((V)=>U.test(V))){j[X]=Z;break}}return j||null}function wy(y,$){let j=k$(y),z=y$.sync(["tailwind.config.*","**/globals.css","package.json"],{cwd:y,deep:4,absolute:!0,onlyFiles:!0,ignore:l}),Y=y$.sync("**/{layout,_app,main}.tsx",{cwd:$?Wy.posix.join(y,$):y,deep:4,absolute:!0,onlyFiles:!0,ignore:l});return{tailwindFile:z.find((Z)=>Z.includes("tailwind.config.")),cssFile:z.find((Z)=>Z.includes("globals.css")),packageJson:z.find((Z)=>Z.includes("package.json")),tsConfig:j?.resultType==="success"?j?.configFileAbsolutePath:void 0,layoutFile:Y.find((Z)=>Z.includes("layout")),appFile:Y.find((Z)=>Z.includes("_app")),mainFile:Y.find((Z)=>Z.includes("main"))}}function Ay(y,$,j={}){if(y.startsWith("@/components/")){if(j?.components)return y.replace(/^@\/components\//,Wy.posix.join(j.components,"/"));if($)return y.replace(/^@\/components\//,Wy.posix.join("@",$,"/"))}if(y.startsWith("@/app/")&&j?.app)return y.replace(/^@\/app\//,Wy.posix.join(j.app,"/"));if(y.startsWith("@/utils/")&&j?.utils)return y.replace(/^@\/utils\//,Wy.posix.join(j.utils,"/"));if(y.startsWith("@/hooks/")&&j?.hooks)return y.replace(/^@\/hooks\//,Wy.posix.join(j.hooks,"/"));if(y.startsWith("@/styles/")&&j?.styles)return y.replace(/^@\/styles\//,Wy.posix.join(j.styles,"/"));if(y.startsWith("@/")&&j?.src)return y.replace(/^@\//,Wy.posix.join(j.src,"/"));return y}async function P$(y,$,j="@/*"){let z=await k$(y);if(z?.resultType==="failed")return null;let Y={};if(!Object.keys(z.paths).length){z.paths={[j]:[`./${$?"src/":""}*`]},Y.src=j.replace(/\/\*$/,"");let W=await dy.promises.readFile(z.configFileAbsolutePath,"utf-8"),Z,X=/(?:\/\/\s*)?"paths":\s*\{(?:[^{}]|\{[^}]*\})*\}/;if(!X.test(W))Z=W.replace(/"compilerOptions":\s*{/,`"compilerOptions": {
|
|
11
|
+
"paths": ${JSON.stringify(z.paths)},`);else Z=W.replace(X,`"paths": ${JSON.stringify(z.paths)}`);let V=new O0,B=await T$(Z,"json");return V.createSourceFile(z.configFileAbsolutePath,B,{overwrite:!0}),await V.save(),Y}return Y||null}function g$(y){let $=y$.sync(["vite.config.*"],{cwd:y,absolute:!0,onlyFiles:!0,ignore:l})?.[0];if(!$)return!1;try{let j=dy.readFileSync($,"utf-8");return k0(j)}catch{return!1}}function k0(y){let $=y.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"");if(!["tailwindcss","@tailwindcss/vite","tailwind("].some((W)=>$.includes(W)))return!1;return["plugins:","postcss:","css:"].some((W)=>$.includes(W))}var P0=["npm","config","user","agent"].join("_");function qy(y){if(y===void 0)y=process.env[P0]||"";if(y.startsWith("yarn"))return"yarn";if(y.startsWith("pnpm"))return"pnpm";if(y.startsWith("bun"))return"bun";return"npm"}function Zy(){switch(qy()){case"yarn":return"yarn";case"pnpm":return"pnpx";case"bun":return"bunx";default:return"npx"}}function d$(){switch(qy()){case"yarn":return"yarn dev";case"pnpm":return"pnpm dev";case"bun":return"bun dev";default:return"npm run dev"}}import g0 from"async-retry";import{execa as f$}from"execa";async function Uy(y,$){let j=Array.isArray(y)?y:Array.from(y);if(!j.length)return;let{cwd:z,dev:Y=!1,spinner:W,label:Z=Y?"devDependencies":"dependencies"}=$,X=qy(),V=[X==="npm"?"install":"add",...Y?["-D"]:[],...j];W.start(`Installing ${Z}`),await g0(()=>f$(X,V,{cwd:z}).catch(async(B)=>{if(B.message.includes("peer"))W.warn(`${Z} conflict detected. Retrying with --legacy-peer-deps...`),W.start(`Installing ${Z} with --legacy-peer-deps flag`),await f$(X,[...V,"--legacy-peer-deps"],{cwd:z});else throw B}),{retries:1}),W.succeed(`${Z} installed`)}var f=(y)=>{if(y.aborted)process.stdout.write("\x1B[?25h"),process.stdout.write(`
|
|
12
|
+
`),process.exit(1)};function fy(y){return y.replace(/^[ \t]*\/\/\s*(TODO:|collapse-(start|end)).*\r?\n?|[ \t]*{\s*\/\*\s*(TODO:|collapse-(start|end)).*?\*\/\s*}\r?\n?/gm,"")}import Xy from"path";function cy(y,$,j){let z=y.replace(/^(components|utils|hooks|styles)\//,"");if(y.includes("components")&&$?.components)return Xy.relative(process.cwd(),Xy.posix.join($.components,z));if(y.includes("utils")&&$?.utils)return Xy.relative(process.cwd(),Xy.posix.join($.utils,z));if(y.includes("hooks")&&$?.hooks)return Xy.relative(process.cwd(),Xy.posix.join($.hooks,z));if(y.includes("styles")&&$?.styles)return Xy.relative(process.cwd(),Xy.posix.join($.styles,z));return Xy.posix.join(j?"src":"",y)}import c$ from"node-fetch";import{Readable as d0,pipeline as f0}from"stream";import{x as c0}from"tar";import{promisify as h0}from"util";var m0=h0(f0);async function h$(y,$){try{let j=await l0($);await m0(j,c0({cwd:y,strip:1}))}catch(j){throw Error(`Failed to download or extract repository from API: ${j instanceof Error?j.message:j}`)}}async function l0(y){let $=`http://localhost:3000/react/api/download-repo?template=${y.template}`;try{let j=await c$($,{method:"GET",headers:{"Content-Type":"application/json",Accept:"application/octet-stream"}});if(j.status===403||j.status===404)throw Error("Repository not found");if(!j.ok)throw Error(`Failed to download from API. Status: ${j.status} ${j.statusText}`);if(!j.body)throw Error("Response body is empty");return d0.from(j.body)}catch(j){throw Error(`Error downloading tarball: ${j instanceof Error?j.message:j}`)}}async function m$(y){let $=`http://localhost:3000/react/api/validate-key?key=${y}`;try{return(await c$($)).status===200}catch{return!1}}async function hy(y,$){if(!await m$(y))$.fail("Invalid license key"),process.exit(1);Oy(y)}var G={components:[],path:"",type:void 0,license:My()},l$=new s0().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).action(async(y,$)=>{if(y)G.components=y;if($){if(G.all=$.all,G.dir=$.dir,G.path=$.path,G.overwrite=$.overwrite,G.includeAllComponents=$.includeAllComponents,G.license=$.license||G.license,G.yes=$.yes,$.yes)G.includeAllComponents=!0,G.overwrite=!0}try{await $$(G)}catch(j){console.error(C.red(j))}});async function $$(y){if(y)G={...G,...y};let $=vy().start(),j=h.posix.join(process.cwd(),G.dir||"");if(!i.existsSync(h.resolve(j,"package.json")))$.warn("This command should be run in a project directory."),process.exit(1);let Y=await By(j);if(G.license)await hy(G.license,$);$.stop();let W=[];if(G.components.length){let Q=await ky(G.type,G.components,G.license);if(Q&&Q.pro&&Q.pro.length>0){if(console.log(),Q.pro.length===1){let L=Q.pro[0]?.split("/")[1]||Q.pro[0];console.log(C.yellow(`\uD83D\uDD12 The ${C.cyan(L)} component requires PRO access.`))}else console.log(C.yellow("\uD83D\uDD12 The following components require PRO access:")),Q.pro.forEach((L)=>{let D=L?.split("/")[1]||L;console.log(` • ${C.cyan(D)}`)});console.log(),console.log("To access PRO components:"),console.log(` ${C.green("→")} If you've already purchased: ${C.cyan(`${Zy()} untitledui@latest login`)}`),console.log(` ${C.green("→")} To purchase PRO components: ${C.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(!Q?.components.length)console.log("No components found"),process.exit(1);W.push(...Q.components)}if(!G?.type&&!G?.components.length){if(G.yes)console.log(C.red("Error: In non-interactive mode (--yes), you must specify components as arguments.")),process.exit(1);let Q=await I$(G.license);if(!Q)console.log("No component types found"),process.exit(1);let L=await Jy({type:"select",name:"type",onState:f,message:`What type of ${C.cyan("component")} are you adding?`,choices:Q?.types.map((D)=>({title:D,value:D}))});G.type=L.type}if(!G?.path&&!Y?.paths?.components)if(G.yes)G.path="components";else{let Q=await Jy({type:"text",name:"path",onState:f,message:`Where would you like to add the ${C.cyan("components")}?`,initial:"components"});G.path=Q.path}if(G?.path&&Y&&Y.paths)Y.paths.components=h.posix.join(Y?.isSrcDir?"src":"",G.path);if(Y&&!Object.keys(Y?.aliases).length){let Q="@/*";if(!G.yes){let L=/^[^*"]+\/\*\s*$/;Q=(await Jy({type:"text",name:"aliasPrefix",onState:f,initial:"@/*",message:`What is the ${C.cyan("import alias")} for your project?`,validate:(_)=>L.test(_)?!0:"Import alias must follow the pattern <prefix>/*"}))?.aliasPrefix}Y.aliases=await P$(j,Y?.isSrcDir,Q)}if(!G?.components.length){if(G.yes)console.log(C.red("Error: In non-interactive mode (--yes), you must specify components as arguments.")),process.exit(1);let Q=await E$(G?.type,G.license);if(!Q)console.log("No components found"),process.exit(1);let L=await Jy({type:"multiselect",name:"components",onState:f,message:`Which ${C.cyan("components")} would you like to add?`,choices:Q?.components?.map((x)=>({title:x?.name+(x?.count?` (${x?.count} variants)`:"")||"example",value:x||"example",selected:G.components.includes(x.name)})),instructions:!1,hint:"- Space to select. Return to submit"});if(!L.components||!L.components.length)console.log("No option selected. Exiting..."),process.exit(1);let D=L.components.filter((x)=>x?.type==="file").map((x)=>x.name),_=L.components.filter((x)=>x?.type==="dir").map((x)=>x.name),E=[];if(_.length){let x=await x$(G?.type,G.license,_);if(x&&x.components.length)for(let v of x.components){let[F,I]=Object.entries(v)[0]||[],T=await Jy({type:"select",name:"component",onState:f,message:`Which ${C.cyan("variant")} from ${C.cyan(F)} would you like to add?`,choices:I?.map((R)=>({title:R?.name.replace(/-modal/g,"")||"example",value:R?.name||"example",selected:G.components.includes(R.name)})),instructions:!1,hint:"- Space to select. Return to submit"});if(!T.component)console.log("No variant selected for "+C.cyan(F));E.push(F+"/"+T.component)}else console.log("No variants found")}G.components=[...E,...D]}if(!G.components?.length)$.warn("No components selected. Exiting."),process.exit(1);let Z=wy(j),X=new Set,U=new Set,V=new Set,B=new r0({tsConfigFilePath:Z?.tsConfig});if($.start(),G.type&&G.components.length){let Q=await ky(G.type,G.components,G.license);if(!Q?.components.length)console.log("No components found"),process.exit(1);W.push(...Q.components)}let b=new Set;if(W.forEach((Q)=>{Q?.components?.forEach((L)=>{b.add({name:L.name,path:L.path})})}),$.stop(),b.size){let Q=Array.from(b).filter((L)=>!i.existsSync(h.posix.join(j,`${Y?.isSrcDir?"src":""}`,L?.path?.replace(/components\//,G.path+"/"))));if(Q?.length)if(G.includeAllComponents)G.baseComponents=Q.map((L)=>L.name);else{let L=await Jy({type:"multiselect",name:"baseComponents",onState:f,message:"Select which base components you want to add",choices:Q.map((D)=>({title:D?.name,value:D?.name,selected:!0})),instructions:!1,hint:"- Space to select. Return to submit"});if(G.baseComponents=L.baseComponents,!Q.length&&!L.baseComponents?.length)$.warn("No components selected")}}if($.start(),G?.baseComponents?.length){let Q=await ky("",G.baseComponents,G.license);if(!Q||!Q?.components.length)console.log("No base components found");else W.push(...Q.components)}$.stop();let q=new Set;for(let Q of W){let L=vy(`Adding ${Q.name}...`).start(),D=Q.files;Q?.dependencies?.forEach((E)=>U.add(E)),Q?.devDependencies?.forEach((E)=>V.add(E));let _=!1;try{for(let{path:E,code:x}of D||[]){let v=h.posix.join(j,cy(E,Y?.paths,Y?.isSrcDir)),F=Y?.framework==="vite"?x.replace(`"use client";
|
|
13
|
+
|
|
14
|
+
`,""):x,I=fy(F),T=h.dirname(v);if(i.existsSync(v)&&!G.overwrite&&!q.has(v)){if(i.readFileSync(v,"utf-8")!==I)X.add({code:I,path:v}),_=!0}else if(!q.has(v)){let R=T.split(h.sep),M="";for(let J of R)if(M=M?h.join(M,J):J,M&&i.existsSync(M)&&i.statSync(M).isFile())throw Error(`Cannot create directory '${T}' because '${M}' is an existing file.
|
|
15
|
+
Please check your path aliases in components.json and tsconfig.json.`);i.mkdirSync(T,{recursive:!0}),i.writeFileSync(v,I),q.add(v);let H=B.getSourceFile(h.resolve(v));if(H)H.replaceWithText(I);else H=B.addSourceFileAtPath(h.resolve(v));H.getImportDeclarations().forEach((J)=>{let A=J.getModuleSpecifierValue();J.setModuleSpecifier(Ay(A,G.path,Y?.aliases))}),await H.save()}}if(_)L.warn(`Some files of ${C.yellow(Q.name)} already exist`);else L.succeed(`${C.green(Q.name)} is added successfully`)}catch(E){L.fail(`
|
|
16
|
+
Failed to add the component ${C.red(Q.name)}`),console.error(C.red(E)),process.exit(1)}}if(X.size&&!G?.overwrite){console.log(`
|
|
17
|
+
Following files already exist in the directory.`),X.forEach((L)=>{console.log(C.green(`- ${h.relative(j,L.path)}`))});let Q=!1;if(G.yes)Q=!0;else{let L=await Jy({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0});if(L.overwrite===void 0)console.log(`
|
|
18
|
+
Use ${C.cyan("--overwrite")} or ${C.cyan("-o")} flag to overwrite existing files, or run with ${C.cyan("node")} instead of ${C.cyan("bun")}.`),process.exit(1);Q=L.overwrite}if(Q){let L=vy("Overwriting files").start();X.forEach((D)=>{let _=B.addSourceFileAtPath(h.resolve(D.path));_.replaceWithText(D.code),_.getImportDeclarations().forEach((E)=>{let x=E.getModuleSpecifierValue();E.setModuleSpecifier(Ay(x,G.path,Y?.aliases))}),_.saveSync()}),L.succeed("Files are overwritten")}}if(U.size){let Q=vy().start();await Uy(U,{cwd:j,spinner:Q,label:"component dependencies"})}if(V.size){let Q=vy().start();await Uy(V,{cwd:j,dev:!0,spinner:Q,label:"component devDependencies"})}if(G.message!==void 0){if(G.message)console.log(G.message);return}process.exit(0)}import Y$ from"chalk";import{Command as p0}from"commander";import*as Ly from"fs";import n0 from"http";import t0 from"open";import e0 from"ora";import y1 from"os";import*as W$ from"path";import{URL as $1}from"url";import*as my from"fs";import*as Gy from"path";import{fileURLToPath as i0}from"url";var o0=i0(import.meta.url),j$=Gy.dirname(o0);function a0(){let y=[Gy.join(j$,"..","templates","auth-template.html"),Gy.join(j$,"templates","auth-template.html"),Gy.join(process.cwd(),"node_modules","untitledui","templates","auth-template.html"),Gy.join(j$,"..","..","templates","auth-template.html")];for(let $ of y)if(my.existsSync($))return $;throw Error("Auth template file not found. Please ensure the CLI package is properly installed.")}function s$(){try{let y=a0();return my.readFileSync(y,"utf-8")}catch(y){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 ${R.cyan("--overwrite")} or ${R.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($){y.fail(`Authentication failed: ${$ instanceof Error?$.message:$}`),process.exit(1)}});async function
|
|
66
|
-
Failed to open browser automatically: ${X.message}`)),console.log(
|
|
67
|
-
`))}),y.text="Waiting for authentication in browser..."}),setTimeout(()=>{z.close(),j(Error("Authentication timeout. Please try again."))},300000)})}function
|
|
68
|
-
Creating a new project in ${
|
|
64
|
+
</html>`}}function r$(){return s$().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 ly(y){return s$().replace("{{TITLE}}","Authentication failed").replace("{{HEADING}}","Authentication failed").replace("{{DESCRIPTION}}",y).replace("{{AUTO_CLOSE_SCRIPT}}","")}var Q$=W$.join(y1.homedir(),".untitledui"),z$=W$.join(Q$,"config.json"),i$=new p0().name("login").description("authenticate with Untitled UI to access PRO components").action(async()=>{let y=e0("Starting authentication...").start();try{await j1(y),y.succeed("Authentication completed successfully!"),console.log(Y$.green(`
|
|
65
|
+
✨ You can now access PRO components with the CLI!`)),process.exit(0)}catch($){y.fail(`Authentication failed: ${$ instanceof Error?$.message:$}`),process.exit(1)}});async function j1(y){return new Promise(($,j)=>{let z=n0.createServer((Y,W)=>{let Z=new $1(Y.url,"http://localhost");if(Z.pathname==="/callback"){let X=Z.searchParams.get("apiKey"),U=Z.searchParams.get("error");if(U){W.writeHead(400,{"Content-Type":"text/html"}),W.end(ly(decodeURIComponent(U))),z.close(),j(Error(decodeURIComponent(U)));return}if(!X){W.writeHead(400,{"Content-Type":"text/html"}),W.end(ly("No Access Token received")),z.close(),j(Error("No Access Token received"));return}try{z1(X),W.writeHead(200,{"Content-Type":"text/html"}),W.end(r$()),z.close(),$()}catch(V){W.writeHead(500,{"Content-Type":"text/html"}),W.end(ly("Failed to save authentication data")),z.close(),j(V)}}else W.writeHead(404),W.end("Not found")});z.listen(0,"localhost",()=>{let Z=`http://localhost:3000/react/api/cli-auth?port=${z.address().port}`;y.text="Opening browser for authentication...",t0(Z).catch((X)=>{console.log(Y$.yellow(`
|
|
66
|
+
Failed to open browser automatically: ${X.message}`)),console.log(Y$.cyan(`Please manually open: ${Z}
|
|
67
|
+
`))}),y.text="Waiting for authentication in browser..."}),setTimeout(()=>{z.close(),j(Error("Authentication timeout. Please try again."))},300000)})}function z1(y){if(!Ly.existsSync(Q$))Ly.mkdirSync(Q$,{recursive:!0});let $={};if(Ly.existsSync(z$))try{$=JSON.parse(Ly.readFileSync(z$,"utf-8"))}catch{$={}}$.license=y,Ly.writeFileSync(z$,JSON.stringify($,null,2),"utf-8")}import X1 from"async-retry";import w from"chalk";import{Command as L1}from"commander";import*as m from"fs";import Sy from"ora";import*as S from"path";import by from"prompts";import{Project as M1}from"ts-morph";import Y1 from"node-fetch";async function Ey(y,$){try{let z=await Y1("http://localhost:3000/react/api/components/example",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({example:y,key:$})});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 M$ from"async-retry";import c from"chalk";import{Command as Q1}from"commander";import{execa as V$}from"execa";import H$ from"fast-glob";import o from"fs";import xy from"ora";import*as P from"path";import iy from"prompts";import{Project as W1}from"ts-morph";import{fileURLToPath as Z1}from"url";import*as sy from"fs";import*as o$ from"path";function Z$(y,$){let j=o$.join(y,"package.json");if(!sy.existsSync(j))return $;let z=JSON.parse(sy.readFileSync(j,"utf-8")),Y={...z.dependencies,...z.devDependencies},W=[];for(let Z of $){let X=Y[Z];if(!X){W.push(Z);continue}if(Z==="tailwindcss"){let U=X.match(/\d+/);if((U?parseInt(U[0],10):0)<4)W.push(Z)}}return W}import U$ from"chalk";import*as Hy from"fs";import*as ry from"path";function X$(y){if(!Hy.existsSync(ry.resolve(y)))console.log(U$.red(`Error: CSS file not found at ${y}`)),process.exit(1);let $=Hy.readFileSync(ry.resolve(y),"utf-8"),j=/(--color-[a-zA-Z-]+-\d{1,3}):\s*(rgb\([^)]+\))/g,z={},Y;while((Y=j.exec($))!==null)if(Y[1]&&Y[2])z[Y[1]]=Y[2];return z}function L$(y,$,j){let z=ry.resolve(j);if(!Hy.existsSync(z)){console.log(U$.red(`Error: CSS file not found at ${z}`));return}let Y=Hy.readFileSync(z,"utf-8"),W=X$(j),Z={},X={};for(let[V,B]of Object.entries(W))if(V.startsWith(`--color-${y}-`)){let b=V.replace(`--color-${y}-`,"");Z[b]=V}else if(V.startsWith(`--color-${$}-`)){let b=V.replace(`--color-${$}-`,"");X[b]=B}let U=!1;for(let[V,B]of Object.entries(Z))if(X[V]){let b=X[V],q=new RegExp(`(${B}):\\s*rgb\\([^)]*\\);?`,"g");if(q.test(Y))Y=Y.replace(q,`$1: ${b};`),U=!0;else console.log(U$.yellow(`No match found for ${B}`))}if(U)Hy.writeFileSync(z,Y,"utf-8")}var U1=Z1(import.meta.url),a$=P.dirname(U1),n$="vite",t$="nextjs",p$={[t$]:"Next.js",[n$]:"Vite"},n="",O={color:"",template:"",framework:void 0,license:My()},e$=new Q1().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(y,$)=>{if(y)n=y;if($){if(O.color=$.color,O.template=$.template,O.overwrite=$.overwrite,O.colorsList=$.colorsList,O.license=$.license||O.license,O.vite=$.vite,O.nextjs=$.nextjs,$.vite)O.framework=n$;if($.nextjs)O.framework=t$}try{await K$($),process.exit(0)}catch(j){console.error(c.red(j)),process.exit(1)}});async function K$(y,$=null){let j=process.cwd(),z=o.existsSync(P.resolve(j,"package.json")),Y=P.resolve(P.join(a$,"../config/styles","theme.css")),W=X$(Y??""),Z=Array.from(new Set(Object.keys(W).map((B)=>B?.split("--color-")?.[1]?.replace(/-\d{1,3}/,"")))),X=xy().start(),U=await By(j);if(O.license)Oy(O.license);if(!z){if(X.stop(),!n){let b=await iy({onState:f,type:"text",name:"path",message:"What is your project named?",initial:"untitled-ui"});if(typeof b.path==="string")n=b.path.trim()}if($)$.projectPath=n;let B=o.existsSync(P.resolve(P.posix.join(j,n,"package.json")));if(o.existsSync(P.resolve(P.posix.join(j,n)))&&B)X.fail(c.red("Directory already exists!")),process.exit(1);if(O.vite&&O.nextjs||!O.framework){let b=await iy({type:"select",name:"framework",onState:f,message:`Which ${c.cyan("framework")} would you like to use?`,choices:Object.entries(p$).map(([q,Q])=>({title:Q,value:q}))});O.framework=b.framework}X.succeed("Framework is selected: "+c.green(p$[O.framework]))}else if(U?.framework==="other")X.fail("Unsupported project framework"),console.log(`Please refer to the documentation ${c.cyan("https://www.untitledui.com/docs")} for supported frameworks or proceed with manual installation.`),process.exit(1);else if(U?.framework.startsWith("next")||U?.framework.startsWith("vite"))if(!$&&!U.tailwind.brandColor)X.succeed(c.yellow(`Detected ${u$[U.framework]} project, proceeding with the setup...`));else X.stop();if(O.colorsList||!O.color&&!U?.tailwind.brandColor){let B=await iy({type:"select",name:"color",onState:f,initial:y.color??"",message:`Which ${c.cyan("color")} would you like to use as the ${c.cyanBright("brand")} color?`,choices:Z.map((b)=>({title:b,value:b}))});if(O.color=B.color,O.colorsList&&U)U.tailwind.brandColor=B.color}let V=P.posix.join(j,n||"");if(n&&!z){let B=P.resolve(n);console.log(`
|
|
68
|
+
Creating a new project in ${c.blue(n)}`);let b=xy("Downloading and extracting the repository...").start();try{o.mkdirSync(B,{recursive:!0}),await M$(()=>h$(B,{template:O.framework}),{retries:2}),b.succeed("Files are downloaded and extracted successfully!");let q=xy({text:"Installing dependencies..."}).start(),Q=H$.sync(["**/styles/theme.css"],{cwd:B,absolute:!0,onlyFiles:!0})[0];if(L$("brand",O.color||"",Q??""),await M$(()=>V$(qy(),["install"],{cwd:V}).catch(async(L)=>{if(L.message.includes("peer"))q.warn("Dependency conflict detected. Retrying with --legacy-peer-deps..."),q.start("Installing dependencies with --legacy-peer-deps flag"),await V$(qy(),["install","--legacy-peer-deps"],{cwd:V})}),{retries:1}),await M$(()=>V$("git",["init"],{cwd:V}),{retries:1}),q.succeed("Dependencies are installed"),!$)console.log(`
|
|
69
69
|
Your project is ready, to get started run the following commands:
|
|
70
70
|
|
|
71
|
-
cd ${
|
|
72
|
-
${
|
|
73
|
-
Failed to download and extract the repository`)),
|
|
74
|
-
`);
|
|
75
|
-
`),
|
|
71
|
+
cd ${c.cyan(n)}
|
|
72
|
+
${c.cyan(d$())}`)}catch(q){if(b.fail(c.red(`
|
|
73
|
+
Failed to download and extract the repository`)),q instanceof Error)console.error(q.message);else console.error(`
|
|
74
|
+
`);o.rmdirSync(B,{recursive:!0}),process.exit(1)}}else{let B=xy(),b=new Set,q=U?.examples||"",Q=wy(j,q),L=P.resolve(P.join(a$,"../config")),D=H$.sync(["**"],{cwd:L,onlyFiles:!0,ignore:l}),_=Z$(j,["tailwindcss","tailwindcss-animate","@tailwindcss/typography","tailwindcss-react-aria-components"]),E=Z$(j,["@tailwindcss/postcss","postcss"]);if(!$&&!U?.tailwind.brandColor)B.start("Copying files to the project directory");if(D.forEach((F)=>{let I=F.includes("postcss.config"),T=P.posix.join(P.posix.join(L),F),R=P.posix.join(j,I?F:cy(F,U?.paths,U?.isSrcDir));if(o.existsSync(R)){if(O?.overwrite)o.copyFileSync(T,R);else{let M=o.readFileSync(R,"utf-8"),H=o.readFileSync(T,"utf-8");if(M!==H){if(F.endsWith("theme.css")&&U?.tailwind.brandColor)return;b.add({targetFile:R,sourceFile:T})}}return}o.mkdirSync(P.dirname(R),{recursive:!0}),o.writeFileSync(R,""),o.copyFileSync(T,R)}),B.stop(),b.size&&!O?.overwrite){if(console.log(`
|
|
75
|
+
`),B.fail("Following files already exist in the directory."),b.forEach((I)=>{console.log(`- ${c.green(I.targetFile)}`)}),(await iy({type:"confirm",name:"overwrite",message:"Do you want to overwrite the existing files?",initial:!0})).overwrite){let I=xy("Overwriting files").start();b.forEach((T)=>{o.copyFileSync(T.sourceFile,T.targetFile)}),I.succeed("Files are overwritten")}}if(Q?.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
|
-
${
|
|
78
|
-
`);if(
|
|
79
|
-
Tailwind CSS is not configured in your Vite project. Please refer to the documentation ${
|
|
80
|
-
`)}let
|
|
81
|
-
Ensure that the ${
|
|
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 W=0;W<Y.length;W++){let Z=Y[W];if(/^\s*(import\b|export\b.*from\b)/.test(Z)||/\brequire\s*\(/.test(Z))continue;if(
|
|
91
|
-
|
|
92
|
-
`+
|
|
93
|
-
`;if(!$)
|
|
77
|
+
${c.cyan(`@config "../${U?.isSrcDir?"../":""}${P.relative(j,Q.tailwindFile)}";`)}
|
|
78
|
+
`);if(U?.framework==="vite"){if(!g$(j))console.log(`
|
|
79
|
+
Tailwind CSS is not configured in your Vite project. Please refer to the documentation ${c.cyan("https://www.untitledui.com/react/integrations/vite")} for manual installation.
|
|
80
|
+
`)}let x=Q?.layoutFile||Q?.appFile||U?.framework==="vite"&&Q?.mainFile||"";if(x){let I=new W1({tsConfigFilePath:P.resolve(Q?.tsConfig||"")}).addSourceFileAtPath(P.resolve(x)),T="styles/globals.css";if(!I.getImportDeclarations().some((M)=>{let H=M.getModuleSpecifierValue();return/(?:styles\/)?globals\.css$/.test(H)})){let M=U?.aliases?.styles||U?.aliases?.src||"",H=U?.aliases?.styles?`${M}globals.css`:`${M}styles/globals.css`;I.addImportDeclaration({moduleSpecifier:H})}I.saveSync()}let v=H$.sync(["**/theme.css"],{cwd:j,absolute:!0,onlyFiles:!0,ignore:l});if(!v?.length)return B.fail(`Failed to copy ${c.cyan("theme.css")} file.
|
|
81
|
+
Ensure that the ${c.cyan("theme.css")} file exists in the project directory under your ${c.yellow("styles")} folder.`);if((O.color||!U?.tailwind.brandColor)&&L$("brand",O.color||"brand",v[0]??""),_.length||E.length){let F=xy().start("Installing dependencies");if(_.length)await Uy(_,{cwd:V,spinner:F,label:"dependencies"});if(E.length)await Uy(E,{cwd:V,dev:!0,spinner:F,label:"devDependencies"});F.succeed("Dependencies are installed")}if(!$&&!U?.tailwind.brandColor)B.succeed(c.green("Project setup is completed!"));if($&&z){X.stop(),B.stop();return}else console.log(`
|
|
82
|
+
Your project is ready, you can now start adding components.`)}}var K={path:"",example:"",license:My(),components:[]},B$={},y0=new L1().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).action(async(y,$)=>{if(y)K.example=y;if($){if(K.path=$.path,K.overwrite=$.overwrite,K.examplePath=$.examplePath,K.includeAllComponents=$.includeAllComponents,K.yes=$.yes,K.license=$.license||K.license,$.yes)K.includeAllComponents=!0,K.overwrite=!0}try{await K$($,B$),await V1()}catch(j){console.error(w.red(j))}});async function V1(){let y=Sy().start(),$=S.posix.join(process.cwd(),B$?.projectPath||"");if(!m.existsSync(S.posix.join(S.resolve($,"package.json"))))y.warn("This command should be run in a project directory."),process.exit(1);let z=await By($);if(K.license)await hy(K.license,y);if(y.stop(),!K.example){if(K.yes)console.error(w.red("Error: Example name is required in non-interactive mode.")),console.log(`Usage: ${w.cyan("npx untitledui example <example-name> --yes")}`),console.log(`Example: ${w.cyan("npx untitledui example dashboards-01/01 --yes")}`),process.exit(1);let Q=await by({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"}]});K.example=Q.example}let Y=null;if(K.example){let Q=await Ey(K.example,K.license);if(Q?.type==="error"&&(Q.status===401||Q.status===403))console.log(),console.log(w.yellow(`\uD83D\uDD12 The ${w.cyan(K.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${w.green("→")} If you've already purchased: ${w.cyan(`${Zy()} untitledui@latest login`)}`),console.log(` ${w.green("→")} To purchase PRO examples: ${w.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1);if(Q?.type==="directory"){if(K.yes)if(Q.results.length>0)K.example=Q.results[0]||"",console.log(w.yellow(`Auto-selecting: ${K.example}`)),Q=await Ey(K.example,K.license);else console.error(w.red("Error: No examples found in directory.")),process.exit(1);else{let L=await by({type:"select",name:"example",onState:f,message:`Select a folder or file in "${K.example}"`,choices:Q.results.map((D)=>({title:D,value:D}))});if(!L.example)return;K.example=L.example,Q=await Ey(L.example,K.license)}if(Q?.type==="error"&&(Q.status===401||Q.status===403))console.log(),console.log(w.yellow(`\uD83D\uDD12 The ${w.cyan(K.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${w.green("→")} If you've already purchased: ${w.cyan(`${Zy()} untitledui@latest login`)}`),console.log(` ${w.green("→")} To purchase PRO examples: ${w.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(Q?.type==="json-files"){if(K.yes)if(Q.results.length>0)K.example=`${K.example}/${Q.results[0]}`,console.log(w.yellow(`Auto-selecting: ${K.example}`)),Q=await Ey(K.example,K.license);else console.error(w.red("Error: No example files found.")),process.exit(1);else{let L=await by({type:"select",name:"example",onState:f,message:`Select which example you want to add from "${K.example}"`,choices:Q.results.map((D)=>({title:D,value:`${K.example}/${D}`}))});if(!L.example)return;K.example=L.example,Q=await Ey(L.example,K.license)}if(Q?.type==="error"&&(Q.status===401||Q.status===403))console.log(),console.log(w.yellow(`\uD83D\uDD12 The ${w.cyan(K.example)} example requires PRO access.`)),console.log(),console.log("To access PRO examples:"),console.log(` ${w.green("→")} If you've already purchased: ${w.cyan(`${Zy()} untitledui@latest login`)}`),console.log(` ${w.green("→")} To purchase PRO examples: ${w.cyan("https://www.untitledui.com/buy/react")}`),console.log(),process.exit(1)}if(Q?.type==="json-file")Y=Q.content}if(!Y)y.fail("No example found"),process.exit(1);let W=z?.examples||"";if(W){let Q=await By(S.posix.join($,W));if(Q)z={...Q,aliases:z?.aliases||{}};K.examplePath=W}if(!K?.examplePath){let Q=z?.isAppDir?"app":"pages",L=z?.isSrcDir?S.posix.join("src",Q):Q;if(K.yes)K.examplePath=L,console.log(w.yellow(`Using default example path: ${L}`));else{let D=await by({type:"text",name:"examplePath",onState:f,message:`Where would you like to add the ${w.cyan(K?.example)} example?`,initial:L});K.examplePath=D.examplePath}}if(K.examplePath&&!m.existsSync(S.posix.join($,K.examplePath)))m.mkdirSync(S.posix.join($,K.examplePath),{recursive:!0}),console.log(w.green(`Created directory ${K.examplePath}`));if(!K?.path&&!z?.paths?.components)if(K.yes)K.path="components",console.log(w.yellow("Using default components path: components"));else{let Q=await by({type:"text",name:"path",onState:f,message:`Where would you like to add the ${w.cyan("components")}?`,initial:"components"});K.path=Q.path}if(K?.path&&z?.paths&&!z.paths.components)z.paths.components=S.posix.join(z?.isSrcDir?"src":"",K.path);if(!K?.path&&z?.paths?.components)K.path=z.paths.components.replace(/^src\//,"");let Z=Y.components.filter((Q)=>!m.existsSync(S.posix.join($,`${z?.isSrcDir?"src":""}`,Q?.path?.replace(/components\//,K.path+"/"))));if(Z?.length)if(K.includeAllComponents)K.components=Z.map((Q)=>Q.name);else{let Q=await by({type:"multiselect",name:"components",onState:f,message:`Select which components you want to add from ${w.cyan(Y.name)} example`,choices:Z.map((L)=>({title:L?.name,value:L?.name,selected:!0})),instructions:!1,hint:"- Space to select. Return to submit"});if(K.components=Q.components,!Z.length&&!Q.components?.length)y.warn("No components selected")}let X=wy($),U=new Set,V=new M1({tsConfigFilePath:X?.tsConfig}),B=Sy(`Adding ${K?.example}...`).start(),b="",q=new Set(Y.components.filter((Q)=>K.components?.includes(Q.name)).map((Q)=>S.dirname(Q.path)));try{for(let{path:Q,code:L}of Y.files||[]){let D=S.dirname(Q);if(Array.from(q).some((I)=>D===I||D.startsWith(I+"/")))continue;let E=S.posix.join($,`${z?.isSrcDir?"src":""}`,Q.replace(/components\//,K.path+"/")),x=z?.framework==="vite"?L.replace(`"use client";
|
|
83
|
+
|
|
84
|
+
`,""):L,v=fy(x);if(Q.includes("examples")){let I=S.basename(Q);E=S.posix.join($,K?.examplePath??"",I),b=S.posix.join(K?.examplePath??"",I)}let F=S.dirname(E);if(m.existsSync(E)&&!K.overwrite){if(m.readFileSync(E,"utf-8")!==v)U.add({code:v,path:E})}else{let I=F.split(S.sep),T="";for(let M of I)if(T=T?S.join(T,M):M,T&&m.existsSync(T)&&m.statSync(T).isFile())throw Error(`Cannot create directory '${F}' because '${T}' is an existing file.
|
|
85
|
+
Please check your path aliases in components.json and tsconfig.json.`);m.mkdirSync(F,{recursive:!0}),m.writeFileSync(E,v);let R=V.getSourceFile(S.resolve(E));if(R)R.replaceWithText(v);else R=V.addSourceFileAtPath(S.resolve(E));R.getImportDeclarations().forEach((M)=>{let H=M.getModuleSpecifierValue();M.setModuleSpecifier(Ay(H,K.path,z?.aliases))}),await R.save()}}if(U.size)B.warn(`Some files of ${w.yellow(K?.example)} already exist`);else B.succeed(`${w.green(K?.example)} is added successfully`)}catch(Q){B.fail(`
|
|
86
|
+
Failed to add the component ${w.red(K?.example)}`),console.error(w.red(Q)),process.exit(1)}if(U.size&&!K?.overwrite){console.log(`
|
|
87
|
+
Following files already exist in the directory.`),U.forEach((L)=>{console.log(w.green(`- ${S.relative($,L.path)}`))});let Q=!1;if(K.yes)Q=!0,console.log(w.yellow("Auto-overwriting existing files (--yes mode)"));else{let L=await by({type:"confirm",name:"overwrite",onState:f,message:"Do you want to overwrite the existing files?",initial:!0});if(L.overwrite===void 0)console.log(`
|
|
88
|
+
Use ${w.cyan("--overwrite")} or ${w.cyan("-o")} flag to overwrite existing files, or run with ${w.cyan("node")} instead of ${w.cyan("bun")}.`),process.exit(1);Q=L.overwrite}if(Q){let L=Sy("Overwriting files").start();U.forEach((D)=>{let _=V.addSourceFileAtPath(S.resolve(D.path));_.replaceWithText(D.code),_.getImportDeclarations().forEach((E)=>{let x=E.getModuleSpecifierValue();E.setModuleSpecifier(Ay(x,K.path,z?.aliases))}),_.saveSync()}),L.succeed("Files are overwritten")}}if(Y?.dependencies?.length){let Q=Sy().start();await Uy(Y.dependencies,{cwd:$,spinner:Q,label:"example dependencies"})}if(Y?.devDependencies?.length){let Q=Sy().start();await Uy(Y.devDependencies,{cwd:$,dev:!0,spinner:Q,label:"example devDependencies"})}if(K?.components?.length)await X1(()=>$$({components:K.components,dir:B$?.projectPath||"",path:K.path,message:""}),{retries:1});console.log(`
|
|
89
|
+
\uD83C\uDF89 Example ${w.green(K.example)} has been added to ${w.green(b)}`),process.exit(0)}import g from"chalk";import{Command as H1}from"commander";import z0 from"fast-glob";import Dy from"fs";import $0 from"ora";import Fy from"path";import K1 from"prompts";var B1={ArrowRight:"ArrowNext",ArrowLeft:"ArrowPrevious",ChevronRight:"ChevronNext",ChevronLeft:"ChevronPrevious",ChevronRightDouble:"ChevronNextDouble",ChevronLeftDouble:"ChevronPreviousDouble"},q1=[{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-"}],Ky="(?:(sm|md|lg|xl|2xl):)?";function _y(y,$){let j=y.match(/^(sm|md|lg|xl|2xl):/);return j?`${y} ${j[1]}:rtl:${$}`:`${y} rtl:${$}`}var J1=[{pattern:/(?<!placement-\w+:|in-placement-\w+:|rtl:)\bslide-in-from-right(?:-([\d.]+|\[\S+\]))?\b(?!\s+rtl:slide-in-from-left)/g,replace:(y)=>`${y} rtl:slide-in-from-left${y.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:(y)=>`${y} rtl:slide-in-from-right${y.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:(y)=>`${y} rtl:slide-out-to-left${y.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:(y)=>`${y} rtl:slide-out-to-right${y.replace("slide-out-to-left","")}`,description:"slide-out-to-left + rtl:slide-out-to-right",needsReview:!0},{pattern:new RegExp(`(?<![-:])${Ky}translate-x-([\\d./]+(?=\\s|$|")|full|px|\\[\\S+\\])(?!\\s+rtl:)`,"g"),replace:(y)=>_y(y,`-${y.replace(/^(sm|md|lg|xl|2xl):/,"")}`),description:"translate-x + rtl:-translate-x",needsReview:!0},{pattern:new RegExp(`(?<=^|\\s|")${Ky}-translate-x-([\\d./]+(?=\\s|$|")|full|px|\\[\\S+\\])(?!\\s+rtl:)`,"g"),replace:(y)=>{let $=y.match(/^(sm|md|lg|xl|2xl):/),j=y.slice(y.indexOf("-translate-x-")+13);return $?`${y} ${$[1]}:rtl:translate-x-${j}`:`${y} rtl:translate-x-${j}`},description:"-translate-x + rtl:translate-x",needsReview:!0},{pattern:new RegExp(`\\b${Ky}space-x-(\\d+(?:\\.\\d+)?|\\[\\S+\\])(?!\\s+(?:sm:|md:|lg:|xl:|2xl:)?rtl:space-x-reverse)`,"g"),replace:(y)=>_y(y,"space-x-reverse"),description:"space-x + rtl:space-x-reverse",needsReview:!0},{pattern:new RegExp(`\\b${Ky}divide-x(?:-(\\d+(?:\\.\\d+)?|\\[\\S+\\]))?(?!\\s+(?:sm:|md:|lg:|xl:|2xl:)?rtl:divide-x-reverse)`,"g"),replace:(y)=>_y(y,"divide-x-reverse"),description:"divide-x + rtl:divide-x-reverse",needsReview:!0},{pattern:new RegExp(`(?<!rtl:)\\b${Ky}bg-linear-to-r\\b(?! (?:sm:|md:|lg:|xl:|2xl:)?rtl:bg-linear-to-l)`,"g"),replace:(y)=>_y(y,"bg-linear-to-l"),description:"bg-linear-to-r + rtl:bg-linear-to-l",needsReview:!0},{pattern:new RegExp(`(?<!rtl:)\\b${Ky}bg-linear-to-l\\b(?! (?:sm:|md:|lg:|xl:|2xl:)?rtl:bg-linear-to-r)`,"g"),replace:(y)=>_y(y,"bg-linear-to-r"),description:"bg-linear-to-l + rtl:bg-linear-to-r",needsReview:!0},{pattern:new RegExp(`(?<!rtl:)\\b${Ky}bg-gradient-to-r\\b(?! (?:sm:|md:|lg:|xl:|2xl:)?rtl:bg-gradient-to-l)`,"g"),replace:(y)=>_y(y,"bg-gradient-to-l"),description:"bg-gradient-to-r + rtl:bg-gradient-to-l",needsReview:!0},{pattern:new RegExp(`(?<!rtl:)\\b${Ky}bg-gradient-to-l\\b(?! (?:sm:|md:|lg:|xl:|2xl:)?rtl:bg-gradient-to-r)`,"g"),replace:(y)=>_y(y,"bg-gradient-to-r"),description:"bg-gradient-to-l + rtl:bg-gradient-to-r",needsReview:!0}],G1=/\bleft-1\/2\b.*-translate-x-1\/2|-translate-x-1\/2.*\bleft-1\/2\b/,Y0=/\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 Q0(y,$){let j=y;for(let z of $)j=j.replace(z.pattern,z.replace);return j}function b1(y,$,j){let z={file:y,changes:[]},Y=$.split(`
|
|
90
|
+
`);for(let W=0;W<Y.length;W++){let Z=Y[W];if(/^\s*(import\b|export\b.*from\b)/.test(Z)||/\brequire\s*\(/.test(Z))continue;if(G1.test(Z))continue;let X=Z,U=!1;if(X=X.replace(/"([^"]*)"|'([^']*)'|`([^`$]*)`|`([^`$]*)\$\{/g,(V,B,b,q,Q)=>{let L=B??b??q??Q;if(L==null||!Y0.test(L))return V;let D=Q0(L,j);if(D!==L)return U=!0,V.replace(L,D);return V}),U&&X!==Z)Y[W]=X,z.changes.push({line:W+1,before:Z.trim(),after:X.trim()})}return z}function _1(y){let $=0,j=y;for(let[z,Y]of Object.entries(B1)){let W=new RegExp(`\\b${z}\\b`,"g"),Z=j;if(j=j.replace(W,Y),j!==Z)$+=(Z.match(W)||[]).length}return{content:j,swaps:$}}async function D1(y){let $=Fy.resolve(y);return z0(["**/*.tsx","**/*.ts"],{cwd:$,absolute:!0,ignore:["**/node_modules/**","**/*.story.tsx","**/*.demo.tsx","**/*.test.tsx"]})}var W0="[data-rtl-flip]:dir(rtl) { transform: scaleX(-1); }";function j0(y){let $=["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 z of $){let Y=Fy.resolve(y,z);if(Dy.existsSync(Y))return Y}let j=z0.sync(["**/*.css"],{cwd:y,absolute:!0,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/.next/**"]});for(let z of j){let Y=Dy.readFileSync(z,"utf-8");if(Y.includes("@import")&&Y.includes("tailwindcss"))return z}return j[0]||null}function N1(y,$){let j=Dy.readFileSync(y,"utf-8");if(j.includes("data-rtl-flip"))return!1;let z=j.trimEnd()+`
|
|
91
|
+
|
|
92
|
+
`+W0+`
|
|
93
|
+
`;if(!$)Dy.writeFileSync(y,z);return!0}var Z0=new H1().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(y,$)=>{console.log(g.bold(`
|
|
94
94
|
Migrate to RTL
|
|
95
|
-
`));let j=
|
|
95
|
+
`));let j=Fy.resolve(y||".");if(!Dy.existsSync(j))console.log(g.red(` Path not found: ${j}`)),process.exit(1);let z=!$.skipIcons,Y=!0,W=!1;if(!$.yes){let _=await K1([{type:$.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:$.dryRun?null:"confirm",name:"confirm",message:`Apply changes to ${g.cyan(j)}?`,initial:!0}]);if(_.confirm===!1){console.log(g.yellow(`
|
|
96
96
|
Cancelled.
|
|
97
|
-
`));return}z=!$.skipIcons&&
|
|
98
|
-
`).map((
|
|
99
|
-
`)[
|
|
100
|
-
`);let
|
|
101
|
-
`),
|
|
102
|
-
`);for(let
|
|
103
|
-
`),V+=
|
|
97
|
+
`));return}z=!$.skipIcons&&_.swapIcons!==!1,Y=_.includeVariants!==!1,W=z}else W=z;let Z=$0(" Scanning files...").start(),X=await D1(j);Z.succeed(` Found ${g.bold(X.length)} files`);let U=[...q1,...Y?J1:[]],V=0,B=0,b=0,q=[],Q=$0(" Transforming...").start();for(let _ of X){let E=Dy.readFileSync(_,"utf-8"),x=Fy.relative(j,_),v=E,F=!1,I=b1(x,v,U);if(I.changes.length>0){v=E.split(`
|
|
98
|
+
`).map((M,H)=>{return I.changes.find((A)=>A.line===H+1)?v.split(`
|
|
99
|
+
`)[H]:M}).join(`
|
|
100
|
+
`);let T=v.split(`
|
|
101
|
+
`),R=E.split(`
|
|
102
|
+
`);for(let M of I.changes){let H=M.line-1,J=R[H];J=J.replace(/"([^"]*)"|'([^']*)'|`([^`$]*)`|`([^`$]*)\$\{/g,(A,u,k,p,e)=>{let yy=u??k??p??e;if(yy==null||!Y0.test(yy))return A;let t=Q0(yy,U);return t!==yy?A.replace(yy,t):A}),T[H]=J}v=T.join(`
|
|
103
|
+
`),V+=I.changes.length,F=!0,q.push(I)}if(z){let T=_1(v);if(T.swaps>0)v=T.content,B+=T.swaps,F=!0}if(F){if(b++,!$.dryRun)Dy.writeFileSync(_,v)}}Q.succeed(` Processed ${g.bold(X.length)} files`);let L=!1,D="";if(W&&B>0){let _=j0(j);if(_)D=Fy.relative(j,_),L=N1(_,$.dryRun)}if(console.log(g.bold(`
|
|
104
104
|
Summary
|
|
105
|
-
`)),console.log(` Files modified: ${
|
|
106
|
-
Could not find a global CSS file to inject the RTL flip rule.`)),console.log(
|
|
107
|
-
`)),console.log(
|
|
108
|
-
`));else console.log(` RTL flip rule: ${
|
|
109
|
-
Dry run — no files were modified.`)),
|
|
105
|
+
`)),console.log(` Files modified: ${g.cyan(b)}`),console.log(` Class changes: ${g.cyan(V)}`),z)console.log(` Icon swaps: ${g.cyan(B)}`);if(L)console.log(` RTL flip rule: ${g.cyan("added")} → ${g.dim(D)}`);else if(W&&B>0&&!L)if(!j0(j))console.log(g.yellow(`
|
|
106
|
+
Could not find a global CSS file to inject the RTL flip rule.`)),console.log(g.yellow(` Add this manually to your global stylesheet:
|
|
107
|
+
`)),console.log(g.dim(` ${W0}
|
|
108
|
+
`));else console.log(` RTL flip rule: ${g.dim("already present")}`);if($.dryRun){if(console.log(g.yellow(`
|
|
109
|
+
Dry run — no files were modified.`)),q.length>0){console.log(g.bold(`
|
|
110
110
|
Changes preview:
|
|
111
|
-
`));for(let
|
|
112
|
-
... and ${
|
|
113
|
-
Done! ${b} files updated.`));console.log()});import
|
|
111
|
+
`));for(let _ of q.slice(0,10)){console.log(g.dim(` ${_.file}`));for(let E of _.changes.slice(0,3))console.log(g.red(` - ${E.before.substring(0,100)}`)),console.log(g.green(` + ${E.after.substring(0,100)}`));if(_.changes.length>3)console.log(g.dim(` ... and ${_.changes.length-3} more`))}if(q.length>10)console.log(g.dim(`
|
|
112
|
+
... and ${q.length-10} more files`))}}else console.log(g.green(`
|
|
113
|
+
Done! ${b} files updated.`));console.log()});import d from"chalk";import{Command as w1}from"commander";import q$ from"node-fetch";import A1 from"ora";var J$="http://localhost:3000/react/api/mcp/tools";async function E1(y,$,j=10){return(await(await q$(`${J$}/search-components`,{method:"POST",headers:{"Content-Type":"application/json",...$&&{Authorization:`Bearer ${$}`}},body:JSON.stringify({query:y,limit:j})})).json()).results||[]}async function x1(y,$,j=10){return(await(await q$(`${J$}/get-page-templates`,{method:"POST",headers:{"Content-Type":"application/json",...$&&{Authorization:`Bearer ${$}`}},body:JSON.stringify({query:y,limit:j})})).json()).templates||[]}async function I1(y,$=10){return(await(await q$(`${J$}/search-icons`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:y,limit:$})})).json()).results||[]}function T1(y,$){let j=y.access==="pro"?d.magenta(" PRO"):d.green(" FREE");if(console.log(` ${d.bold(`${$+1}. ${y.name}`)}${j} ${d.dim(`(${y.category})`)}`),console.log(` ${d.dim(y.description)}`),y.key_features?.length)console.log(` ${y.key_features.map((z)=>d.cyan(z)).join(" ")}`);console.log()}function v1(y,$){if(console.log(` ${d.bold(`${$+1}. ${y.name}`)} ${d.dim(`(${y.type} · ${y.layout})`)}`),console.log(` ${d.dim(y.description)}`),y.sections?.length)console.log(` ${d.dim("Sections:")} ${y.sections.map((j)=>d.cyan(j)).join(" ")}`);if(y.hero_style)console.log(` ${d.dim("Hero:")} ${d.yellow(y.hero_style)}`);console.log()}function S1(y,$){if(console.log(` ${d.bold(`${$+1}. ${y.importName}`)} ${d.dim(`(${y.category})`)}`),console.log(` ${d.dim(`import { ${y.importName} } from "@untitledui/icons"`)}`),y.tags?.length)console.log(` ${y.tags.slice(0,6).map((j)=>d.dim(j)).join(" ")}`);console.log()}var U0=new w1().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").action(async(y,$)=>{let j=y.join(" "),z=parseInt($.limit,10),Y=$.key||My()||void 0,W=$.type.toLowerCase(),Z=A1(`Searching for "${j}"...`).start();try{let X=W==="all"||W==="components",U=W==="all"||W==="templates",V=W==="all"||W==="icons",[B,b,q]=await Promise.all([X?E1(j,Y,z):Promise.resolve([]),U?x1(j,Y,z):Promise.resolve([]),V?I1(j,z):Promise.resolve([])]);if(Z.stop(),B.length+b.length+q.length===0){console.log(d.yellow(`
|
|
114
114
|
No results found for "${j}"
|
|
115
|
-
`));return}if(
|
|
116
|
-
Components (${
|
|
117
|
-
`)),
|
|
118
|
-
`))}}if(b.length>0){if(console.log(
|
|
115
|
+
`));return}if(B.length>0){if(console.log(d.bold.underline(`
|
|
116
|
+
Components (${B.length})
|
|
117
|
+
`)),B.forEach(T1),B.length>0){let L=B[0].name;console.log(d.dim(` Install: npx untitledui@latest add ${L} --yes
|
|
118
|
+
`))}}if(b.length>0){if(console.log(d.bold.underline(`
|
|
119
119
|
Templates (${b.length})
|
|
120
|
-
`)),b.forEach(
|
|
121
|
-
`))}}if(
|
|
122
|
-
Icons (${
|
|
123
|
-
`)),
|
|
124
|
-
`,"utf-8");return{updated:V,added:
|
|
125
|
-
`);for(let W=0;W<Y.length;W++){let Z=Y[W];if(/^\s*(import\b|require\s*\(|export\b.*from\b)/.test(Z))continue;if(
|
|
126
|
-
`);for(let
|
|
127
|
-
`),changes:j}}function
|
|
128
|
-
`);for(let Y=0;Y<z.length;Y++){let W=z[Y];if(/^\s*(import\b|require\s*\(|export\b.*from\b)/.test(W))continue;let Z=W;for(let X of $)if(Z.includes(X.from))Z=Z.split(X.from).join(X.to);if(Z!==W){z[Y]=Z;let X=$.find((
|
|
129
|
-
`),changes:j}}function
|
|
130
|
-
`);for(let{pattern:W,instruction:Z}of j)for(let X=0;X<Y.length;X++){if(/^\s*(import\b|export\b.*from\b)/.test(Y[X])||/\brequire\s*\(/.test(Y[X]))continue;if(Y[X].includes(W))z.push({file:y,line:X+1,pattern:W,instruction:Z})}return z}function
|
|
131
|
-
`);for(let W=0;W<Y.length;W++)for(let Z of j)if(Y[W].includes(Z))z.push({file:y,line:W+1,token:Z});return z}function
|
|
132
|
-
`,"utf-8")}async function
|
|
120
|
+
`)),b.forEach(v1),b.length>0){let L=b[0].name;console.log(d.dim(` Install: npx untitledui@latest example ${L} --yes
|
|
121
|
+
`))}}if(q.length>0)console.log(d.bold.underline(`
|
|
122
|
+
Icons (${q.length})
|
|
123
|
+
`)),q.forEach(S1)}catch(X){Z.fail("Search failed"),console.error(d.red(X instanceof Error?X.message:"Unknown error")),process.exit(1)}});import N from"chalk";import{Command as P1}from"commander";import{execa as b$}from"execa";import _$ from"fast-glob";import s from"fs";import a from"ora";import r from"path";import b0 from"prompts";var X0={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 Iy from"fs";import*as G$ from"path";function L0(y){let{tsconfigPath:$,changes:j,dryRun:z}=y,Y=G$.resolve($),W=[],Z=[],X;try{X=Iy.readFileSync(Y,"utf-8")}catch{return{applied:W,skipped:j.map((V)=>V.description)}}let U=X;for(let V of j)if(U.includes(V.find))U=U.replace(V.find,V.replace),W.push(V.description);else Z.push(V.description);if(!z&&W.length>0)Iy.writeFileSync(Y,U,"utf-8");return{applied:W,skipped:Z}}function M0(y){let{packageJsonPath:$,update:j,add:z,devUpdate:Y,devAdd:W,remove:Z,dryRun:X}=y,U=G$.resolve($),V=[],B=[],b=[],q;try{let Q=Iy.readFileSync(U,"utf-8");q=JSON.parse(Q)}catch{return{updated:V,added:B,removed:b}}if(!q.dependencies)q.dependencies={};if(!q.devDependencies)q.devDependencies={};for(let[Q,L]of Object.entries(j))if(q.dependencies[Q])q.dependencies[Q]=L,V.push(Q);for(let[Q,L]of Object.entries(z))if(!q.dependencies[Q])q.dependencies[Q]=L,B.push(Q);for(let[Q,L]of Object.entries(Y))if(q.devDependencies[Q])q.devDependencies[Q]=L,V.push(Q);for(let[Q,L]of Object.entries(W))if(!q.devDependencies[Q])q.devDependencies[Q]=L,B.push(Q);for(let Q of Z){if(q.dependencies[Q])delete q.dependencies[Q],b.push(Q);if(q.devDependencies[Q]){if(delete q.devDependencies[Q],!b.includes(Q))b.push(Q)}}if(!X&&(V.length>0||B.length>0||b.length>0))Iy.writeFileSync(U,JSON.stringify(q,null,2)+`
|
|
124
|
+
`,"utf-8");return{updated:V,added:B,removed:b}}import*as Ty from"fs";import*as V0 from"path";function F1(y){let $=/--color-brand-(\d+):\s*([^;]+);/g,j={},z;while((z=$.exec(y))!==null)if(z[1]&&z[2])j[`--color-brand-${z[1]}`]=z[2].trim();return j}function R1(y,$){let j=y;for(let[z,Y]of Object.entries($)){let W=new RegExp(`(${z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}):\\s*[^;]+;`,"g");j=j.replace(W,`${z}: ${Y};`)}return j}async function H0(y){let{themePath:$,newThemeContent:j,dryRun:z}=y,Y=V0.resolve($),W;try{W=Ty.readFileSync(Y,"utf-8")}catch{return{brandColors:{},success:!1,message:`Theme file not found at ${Y}`}}let Z=F1(W);if(z)return{brandColors:Z,success:!0,message:`Dry run: found ${Object.keys(Z).length} brand color variables`};try{if(Ty.writeFileSync(Y,j,"utf-8"),Object.keys(Z).length>0){let X=Ty.readFileSync(Y,"utf-8"),U=R1(X,Z);Ty.writeFileSync(Y,U,"utf-8")}return{brandColors:Z,success:!0,message:`Theme upgraded successfully. Preserved ${Object.keys(Z).length} brand color variables.`}}catch(X){let U=X instanceof Error?X.message:String(X);return{brandColors:Z,success:!1,message:`Failed to write theme file: ${U}`}}}var C1=/\bleft-1\/2\b.*-translate-x-1\/2|-translate-x-1\/2.*\bleft-1\/2\b/;function u1(y,$){return $.some((j)=>j.pattern.test(y))}function O1(y,$){let j=y;for(let z of $)z.pattern.lastIndex=0,j=j.replace(z.pattern,z.replace);return j}function k1(y,$,j){let z=[];for(let Y of j){if(Y.pattern.lastIndex=0,Y.pattern.test(y))z.push(Y.description);Y.pattern.lastIndex=0}return z.join("; ")}function K0(y,$,j){let z={file:y,changes:[]},Y=$.split(`
|
|
125
|
+
`);for(let W=0;W<Y.length;W++){let Z=Y[W];if(/^\s*(import\b|require\s*\(|export\b.*from\b)/.test(Z))continue;if(C1.test(Z))continue;let X=Z,U=!1;if(X=X.replace(/"([^"]*)"|'([^']*)'|`([^`$]*)`|`([^`$]*)\$\{/g,(V,B,b,q,Q)=>{let L=B??b??q??Q;if(L==null)return V;for(let _ of j)_.pattern.lastIndex=0;if(!u1(L,j))return V;for(let _ of j)_.pattern.lastIndex=0;let D=O1(L,j);if(D!==L)return U=!0,V.replace(L,D);return V}),U&&X!==Z){let V=k1(Z,X,j);Y[W]=X,z.changes.push({line:W+1,before:Z.trim(),after:X.trim(),description:V})}}return z}function B0(y,$){let j=[],z=y.split(`
|
|
126
|
+
`),Y=[];for(let W=0;W<z.length;W++){let Z=z[W];if(!/^\s*(import\b|require\s*\(|export\b.*from\b)/.test(Z))continue;let X=Z;for(let U of $)if(X.includes(U.from)){if(X=X.replace(U.from,U.to),U.symbolRenames)Y.push(...U.symbolRenames)}if(X!==Z){z[W]=X;let U=$.find((V)=>Z.includes(V.from));j.push({line:W+1,before:Z.trim(),after:X.trim(),description:U?.description??"Import path update"})}}if(Y.length>0)for(let W=0;W<z.length;W++){let Z=z[W],X=Z;for(let U of Y){let V=new RegExp(`\\b${U.from}\\b`,"g");X=X.replace(V,U.to)}if(X!==Z){if(z[W]=X,!j.some((V)=>V.line===W+1))j.push({line:W+1,before:Z.trim(),after:X.trim(),description:`Renamed ${Y.map((V)=>`${V.from} → ${V.to}`).join(", ")}`})}}return{content:z.join(`
|
|
127
|
+
`),changes:j}}function q0(y,$){let j=[],z=y.split(`
|
|
128
|
+
`);for(let Y=0;Y<z.length;Y++){let W=z[Y];if(/^\s*(import\b|require\s*\(|export\b.*from\b)/.test(W))continue;let Z=W;for(let X of $)if(Z.includes(X.from))Z=Z.split(X.from).join(X.to);if(Z!==W){z[Y]=Z;let X=$.find((U)=>W.includes(U.from));j.push({line:Y+1,before:W.trim(),after:Z.trim(),description:X?.description??"Prop update"})}}return{content:z.join(`
|
|
129
|
+
`),changes:j}}function J0(y,$,j){let z=[],Y=$.split(`
|
|
130
|
+
`);for(let{pattern:W,instruction:Z}of j)for(let X=0;X<Y.length;X++){if(/^\s*(import\b|export\b.*from\b)/.test(Y[X])||/\brequire\s*\(/.test(Y[X]))continue;if(Y[X].includes(W))z.push({file:y,line:X+1,pattern:W,instruction:Z})}return z}function G0(y,$,j){let z=[],Y=$.split(`
|
|
131
|
+
`);for(let W=0;W<Y.length;W++)for(let Z of j)if(Y[W].includes(Z))z.push({file:y,line:W+1,token:Z});return z}function g1(y){return{fromVersion:y.fromVersion,toVersion:y.toVersion,classTransforms:y.classRenames.map(($)=>({pattern:new RegExp(`\\b${D0($.from)}\\b`,"g"),replace:$.to,description:$.description,needsReview:$.needsReview})),importTransforms:y.importRenames,propTransforms:y.propRenames,structuralPatterns:y.structuralPatterns,orphanedTokens:y.orphanedTokens,dependencyChanges:y.dependencyChanges,configChanges:y.configChanges,notes:y.notes}}function D0(y){return y.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function d1(y){let $=r.join(y,"components.json");try{return JSON.parse(s.readFileSync($,"utf-8"))}catch{return null}}function f1(y,$){let j=r.join(y,"components.json");s.writeFileSync(j,JSON.stringify($,null,2)+`
|
|
132
|
+
`,"utf-8")}async function _0(y){let $=r.resolve(y);return _$(["**/*.{tsx,ts}"],{cwd:$,absolute:!0,ignore:["**/node_modules/**","**/*.story.tsx","**/*.demo.tsx","**/.next/**","**/dist/**","**/build/**"]})}async function c1(y){return(await _$(["**/theme.css"],{cwd:y,absolute:!0,deep:5,ignore:["**/node_modules/**","**/.next/**","**/dist/**"]}))[0]}function h1(y){let $=r.join(y,"package.json");return s.existsSync($)?$:void 0}function m1(y){let $=r.join(y,"tsconfig.json");return s.existsSync($)?$:void 0}function l1(y){let $=0;for(let j=0;j<y.length;j++){let z=y.charCodeAt(j);$=($<<5)-$+z|0}return $.toString(36)}var N0=new P1().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(y)=>{console.log(N.bold(`
|
|
133
133
|
Upgrade Untitled UI
|
|
134
|
-
`));let $=
|
|
134
|
+
`));let $=r.resolve(y.path||".");try{let{stdout:M}=await b$("git",["status","--porcelain"],{cwd:$});if(M.trim().length>0){if(console.log(N.yellow(" You have uncommitted changes. We recommend committing first so you can\n revert with `git checkout .` if needed.")),!y.yes){let{proceed:H}=await b0({type:"confirm",name:"proceed",message:"Continue with uncommitted changes?",initial:!0});if(!H){console.log(N.yellow(`
|
|
135
135
|
Cancelled.
|
|
136
|
-
`));return}}console.log()}}catch{}let j=
|
|
136
|
+
`));return}}console.log()}}catch{}let j=d1($),z=j?.version??"7";if(console.log(` Detected version: ${N.cyan(z)}
|
|
137
137
|
`),z==="8"){console.log(N.green(` Already on version 8. Nothing to upgrade.
|
|
138
|
-
`));return}let Y,W,Z=a(" Fetching migration rules...").start();try{let M=await fetch("
|
|
139
|
-
`);for(let
|
|
140
|
-
`),V+=
|
|
141
|
-
`).filter((
|
|
142
|
-
`,"utf-8")}catch{}if(
|
|
138
|
+
`));return}let Y,W,Z=a(" Fetching migration rules...").start();try{let M=await fetch("http://localhost:3000/react/api/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fromVersion:z,toVersion:"8"})});if(!M.ok)throw Error(`Server returned ${M.status}`);let H=await M.json();Y=g1(H),W="server",Z.succeed(" Migration rules fetched from server")}catch{Y=X0,W="built-in",Z.warn(" Could not reach server. Using built-in migration rules")}let X=a(" Scanning files...").start(),U=await _0($);X.succeed(` Found ${N.bold(U.length)} source files`);let V=0,B=0,b=0,q=0,Q=[],L=[],D=[],_=[];if(!y.skipTheme){let M=a(" Upgrading theme.css...").start(),H=await c1($);if(H)try{let J=r.resolve(import.meta.dirname,"../config/styles/theme.css"),A=s.readFileSync(J,"utf-8"),u=await H0({themePath:H,newThemeContent:A,dryRun:y.dryRun});if(u.success){let k=Object.keys(u.brandColors);if(k.length>0)M.succeed(` Theme upgraded. Brand colors preserved: ${N.cyan(k.join(", "))}`);else M.succeed(" Theme upgraded (no custom brand colors found)")}else M.warn(` Theme upgrade issue: ${u.message}`)}catch(J){let A=J instanceof Error?J.message:String(J);M.warn(` Theme upgrade skipped: ${A}`)}else M.warn(" No theme.css found — skipping theme upgrade")}if(!y.skipConfig){let M=a(" Updating config files...").start(),H=m1($);if(H&&Y.configChanges.tsconfig.length>0){let{applied:J,skipped:A}=L0({tsconfigPath:H,changes:Y.configChanges.tsconfig,dryRun:y.dryRun});if(J.length>0)M.succeed(` Config updated: ${J.map((u)=>N.cyan(u)).join(", ")}`);else M.info(" No config changes needed");if(A.length>0)for(let u of A)console.log(N.dim(` Skipped: ${u}`))}else M.info(" No config changes to apply")}if(!y.skipDeps){let M=a(" Updating dependencies...").start(),H=h1($);if(H){let J=M0({packageJsonPath:H,update:Y.dependencyChanges.update,add:Y.dependencyChanges.add,devUpdate:Y.dependencyChanges.devUpdate,devAdd:Y.dependencyChanges.devAdd,remove:Y.dependencyChanges.remove,dryRun:y.dryRun});if(J.updated.length+J.added.length+J.removed.length>0){if(M.succeed(" Dependencies updated in package.json"),J.updated.length>0)console.log(N.dim(` Updated: ${J.updated.join(", ")}`));if(J.added.length>0)console.log(N.dim(` Added: ${J.added.join(", ")}`));if(J.removed.length>0)console.log(N.dim(` Removed: ${J.removed.join(", ")}`));if(!y.dryRun){let u=a(" Installing dependencies...").start();try{let k=Zy();await b$(k==="bunx"?"bun":k==="pnpx"?"pnpm":k==="yarn"?"yarn":"npm",["install"],{cwd:$}),u.succeed(" Dependencies installed")}catch(k){let p=k instanceof Error?k.message:String(k);u.warn(` Could not auto-install dependencies: ${p.substring(0,100)}`),console.log(N.dim(" Run your package manager's install command manually."))}}}else M.info(" No dependency changes needed")}else M.warn(" No package.json found — skipping dependency updates")}let E=a(" Renaming files...").start(),x=new Set;for(let M of Y.importTransforms){let H=M.from.split("/").pop(),J=M.to.split("/").pop();if(H===J)continue;let A=_$.sync([`**/${H}.tsx`,`**/${H}.ts`],{cwd:$,absolute:!0,ignore:["**/node_modules/**"]});for(let u of A){let k=u.replace(new RegExp(`${D0(H)}(\\.tsx?)$`),`${J}$1`);if(!y.dryRun)try{s.renameSync(u,k),x.add(M.from)}catch{}else x.add(M.from)}}let v=Y.importTransforms.filter((M)=>{let H=M.from.split("/").pop(),J=M.to.split("/").pop();if(H===J)return!0;return x.has(M.from)});if(x.size>0)E.succeed(` Renamed ${N.bold(x.size)} files`),U.length=0,U.push(...await _0($));else E.info(" No file renames needed");let F=a(" Applying source transforms...").start();for(let M of U){let H;try{H=s.readFileSync(M,"utf-8")}catch{continue}let J=r.relative($,M),A=H,u=!1,k=K0(J,A,Y.classTransforms);if(k.changes.length>0){let yy=A.split(`
|
|
139
|
+
`);for(let t of k.changes){let Ry=t.line-1,$y=yy[Ry];$y=$y.replace(/"([^"]*)"|'([^']*)'|`([^`$]*)`|`([^`$]*)\$\{/g,(oy,w0,A0,E0,x0)=>{let Cy=w0??A0??E0??x0;if(Cy==null)return oy;let uy=Cy;for(let ay of Y.classTransforms)ay.pattern.lastIndex=0,uy=uy.replace(ay.pattern,ay.replace);return uy!==Cy?oy.replace(Cy,uy):oy}),yy[Ry]=$y}A=yy.join(`
|
|
140
|
+
`),V+=k.changes.length,u=!0,Q.push(k);for(let t of k.changes){let Ry=Y.classTransforms.find(($y)=>{return $y.pattern.lastIndex=0,$y.needsReview&&$y.pattern.test(t.before)});for(let $y of Y.classTransforms)$y.pattern.lastIndex=0;if(Ry)L.push({file:J,line:t.line,description:t.description,before:t.before,after:t.after})}}let p=q0(A,Y.propTransforms);if(p.changes.length>0)A=p.content,B+=p.changes.length,u=!0;let e=B0(A,v);if(e.changes.length>0)A=e.content,b+=e.changes.length,u=!0;if(u){if(q++,!y.dryRun)s.writeFileSync(M,A)}}F.succeed(` Processed ${N.bold(U.length)} files`);let I=a(" Detecting structural patterns...").start();for(let M of U){let H;try{H=s.readFileSync(M,"utf-8")}catch{continue}let J=r.relative($,M),A=J0(J,H,Y.structuralPatterns);_.push(...A)}if(_.length>0)I.warn(` Found ${N.bold(_.length)} structural patterns requiring manual review`);else I.succeed(" No structural patterns found");if(j?.components&&Array.isArray(j.components)&&j.components.some((M)=>M.contentHash)){let M=a(" Checking stock components...").start(),H=[];for(let J of j.components){if(!J.contentHash||!J.filePath)continue;let A=r.resolve($,J.filePath);try{let u=s.readFileSync(A,"utf-8");if(l1(u)===J.contentHash)H.push({name:J.name,path:J.filePath})}catch{}}if(H.length>0){M.info(` ${N.bold(H.length)} stock components can be auto-refreshed`);let J=y.yes;if(!J){let{confirm:A}=await b0({type:"confirm",name:"confirm",message:`Refresh ${H.length} unmodified stock components to v8.0?`,initial:!0});J=A}if(J&&!y.dryRun){let A=a(" Fetching v8.0 components...").start();try{let u=await fetch("http://localhost:3000/react/api/components",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({components:H.map((k)=>k.name),version:"8"})});if(u.ok){let k=await u.json(),p=0;for(let e of H)if(k[e.name])s.writeFileSync(r.resolve($,e.path),k[e.name]),p++;A.succeed(` Refreshed ${N.bold(p)} stock components`)}else A.warn(" Could not fetch v8.0 components from server")}catch{A.warn(" Could not reach server for component refresh")}}}else M.info(" No unmodified stock components to refresh")}let T=a(" Scanning for orphaned tokens...").start();for(let M of U){let H;try{H=s.readFileSync(M,"utf-8")}catch{continue}let J=r.relative($,M),A=G0(J,H,Y.orphanedTokens);D.push(...A)}if(D.length>0)T.warn(` Found ${N.bold(D.length)} orphaned v7.0 tokens remaining`);else T.succeed(" No orphaned tokens found");let R=[];if(!y.dryRun){let M=a(" Running type check...").start();try{let H=Zy();await b$(H,["tsc","--noEmit"],{cwd:$}),M.succeed(" Type check passed")}catch(H){let A=(H?.stderr||H?.stdout||"").split(`
|
|
141
|
+
`).filter((u)=>u.includes("error TS")).slice(0,20);R.push(...A),M.warn(` Type check found ${N.bold(A.length)} error(s)`)}}if(!y.dryRun){let M={version:"8",status:L.length>0||D.length>0?"partial":"success",filesScanned:U.length,filesModified:q,classChanges:V,propChanges:B,importChanges:b,manualReview:L,orphanedTokens:D,typeErrors:R,structuralPatterns:_,notes:Y.notes};try{s.writeFileSync(r.join($,"upgrade-report.json"),JSON.stringify(M,null,2)+`
|
|
142
|
+
`,"utf-8")}catch{}if(L.length>0||_.length>0)try{let H=`# Untitled UI v7.0 to v8.0 Upgrade Instructions
|
|
143
143
|
|
|
144
|
-
`;if(
|
|
144
|
+
`;if(H+="This file was generated by `untitledui upgrade`. It is meant to guide\n",H+=`manual review of changes that could not be fully automated.
|
|
145
145
|
|
|
146
|
-
`,
|
|
147
|
-
`,
|
|
146
|
+
`,H+=`**Important**: Ignore pre-existing type errors and linting issues.
|
|
147
|
+
`,H+=`Focus only on migration-related changes listed below.
|
|
148
148
|
|
|
149
|
-
`,
|
|
149
|
+
`,H+=`Delete this file after review is complete.
|
|
150
150
|
|
|
151
|
-
`,
|
|
151
|
+
`,_.length>0){H+=`## Structural changes
|
|
152
152
|
|
|
153
|
-
`,
|
|
153
|
+
`,H+=`These patterns require manual refactoring:
|
|
154
154
|
|
|
155
|
-
`;for(let
|
|
156
|
-
`,
|
|
155
|
+
`;for(let J of _)H+=`- **${J.file}:${J.line}** — \`${J.pattern}\`
|
|
156
|
+
`,H+=` ${J.instruction}
|
|
157
157
|
|
|
158
|
-
`}if(
|
|
158
|
+
`}if(L.length>0){H+=`## Manual review items
|
|
159
159
|
|
|
160
|
-
`,
|
|
160
|
+
`,H+=`These class replacements may need manual verification:
|
|
161
161
|
|
|
162
|
-
`;for(let
|
|
162
|
+
`;for(let J of L)H+=`### ${J.file}:${J.line}
|
|
163
163
|
|
|
164
|
-
`,
|
|
164
|
+
`,H+=`${J.description}
|
|
165
165
|
|
|
166
|
-
`,
|
|
167
|
-
`,
|
|
168
|
-
`,
|
|
166
|
+
`,H+="```diff\n",H+=`- ${J.before}
|
|
167
|
+
`,H+=`+ ${J.after}
|
|
168
|
+
`,H+="```\n\n"}if(Y.notes.length>0){H+=`## Additional notes
|
|
169
169
|
|
|
170
|
-
`;for(let
|
|
171
|
-
`;
|
|
172
|
-
`}
|
|
170
|
+
`;for(let J of Y.notes)H+=`- ${J}
|
|
171
|
+
`;H+=`
|
|
172
|
+
`}s.writeFileSync(r.join($,"UPGRADE-INSTRUCTIONS.md"),H,"utf-8")}catch{}}if(!y.dryRun&&j)j.version="8",f1($,j);if(console.log(N.bold(`
|
|
173
173
|
Summary
|
|
174
|
-
`)),console.log(` Migration source: ${N.cyan(W)}`),console.log(` Files scanned: ${N.cyan(
|
|
174
|
+
`)),console.log(` Migration source: ${N.cyan(W)}`),console.log(` Files scanned: ${N.cyan(U.length)}`),console.log(` Files modified: ${N.cyan(q)}`),console.log(` Class changes: ${N.cyan(V)}`),console.log(` Prop changes: ${N.cyan(B)}`),console.log(` Import changes: ${N.cyan(b)}`),_.length>0){console.log(` Structural patterns: ${N.yellow(_.length)}`);for(let M of _.slice(0,5))console.log(N.dim(` ${M.file}:${M.line} — ${M.pattern}`));if(_.length>5)console.log(N.dim(` ... and ${_.length-5} more (see UPGRADE-INSTRUCTIONS.md)`))}if(L.length>0){console.log(` Manual review items: ${N.yellow(L.length)}`);for(let M of L.slice(0,5))console.log(N.dim(` ${M.file}:${M.line} — ${M.description}`));if(L.length>5)console.log(N.dim(` ... and ${L.length-5} more (see UPGRADE-INSTRUCTIONS.md)`))}if(D.length>0){console.log(` Orphaned tokens: ${N.yellow(D.length)}`);let M=[...new Set(D.map((H)=>H.token))];for(let H of M.slice(0,5))console.log(N.dim(` ${H}`));if(M.length>5)console.log(N.dim(` ... and ${M.length-5} more`))}if(R.length>0)console.log(` Type errors: ${N.yellow(R.length)}`);if(y.dryRun){if(console.log(N.yellow(`
|
|
175
175
|
Dry run — no files were modified.`)),Q.length>0){console.log(N.bold(`
|
|
176
176
|
Changes preview:
|
|
177
|
-
`));for(let M of Q.slice(0,10)){console.log(N.dim(` ${M.file}`));for(let
|
|
177
|
+
`));for(let M of Q.slice(0,10)){console.log(N.dim(` ${M.file}`));for(let H of M.changes.slice(0,3))console.log(N.red(` - ${H.before.substring(0,100)}`)),console.log(N.green(` + ${H.after.substring(0,100)}`));if(M.changes.length>3)console.log(N.dim(` ... and ${M.changes.length-3} more`))}if(Q.length>10)console.log(N.dim(`
|
|
178
178
|
... and ${Q.length-10} more files`))}console.log(N.dim(`
|
|
179
179
|
Run without --dry-run to apply changes.
|
|
180
|
-
`))}else console.log(N.green("\n Done! Run `bun run build` to verify.")),console.log(N.dim(" If something went wrong, run `git checkout .` to revert.\n"))});var
|
|
180
|
+
`))}else console.log(N.green("\n Done! Run `bun run build` to verify.")),console.log(N.dim(" If something went wrong, run `git checkout .` to revert.\n"))});var D$={name:"untitledui",version:"0.1.56",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 i1(){let y=new r1().name(D$.name).version(D$.version);y.addCommand(e$).addCommand(l$).addCommand(y0).addCommand(U0).addCommand(i$).addCommand(Z0).addCommand(N0),y.parse()}i1();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "untitledui",
|
|
3
|
-
"version": "0.1.56
|
|
3
|
+
"version": "0.1.56",
|
|
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",
|