xertica-ui 2.2.1 → 2.4.0

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.
Files changed (708) hide show
  1. package/CHANGELOG.md +564 -525
  2. package/README.md +417 -382
  3. package/bin/cli.ts +1244 -748
  4. package/bin/generate-tokens.ts +262 -262
  5. package/bin/language-config.ts +5 -8
  6. package/components/assets/xertica-orbe-animation.ts +1162 -1162
  7. package/components/assistant/code-block/CodeBlock.tsx +268 -268
  8. package/components/assistant/code-block/code-block.stories.tsx +57 -57
  9. package/components/assistant/code-block/code-block.test.tsx +44 -44
  10. package/components/assistant/code-block/index.ts +1 -1
  11. package/components/assistant/formatted-document/FormattedDocument.tsx +147 -147
  12. package/components/assistant/formatted-document/formatted-document.stories.tsx +51 -51
  13. package/components/assistant/formatted-document/formatted-document.test.tsx +42 -42
  14. package/components/assistant/formatted-document/index.ts +1 -1
  15. package/components/assistant/index.ts +6 -6
  16. package/components/assistant/markdown-message/MarkdownMessage.tsx +152 -152
  17. package/components/assistant/markdown-message/index.ts +1 -1
  18. package/components/assistant/markdown-message/markdown-message.stories.tsx +50 -50
  19. package/components/assistant/markdown-message/markdown-message.test.tsx +33 -33
  20. package/components/assistant/modern-chat-input/ModernChatInput.tsx +17 -7
  21. package/components/assistant/modern-chat-input/index.ts +1 -1
  22. package/components/assistant/modern-chat-input/modern-chat-input.stories.tsx +131 -131
  23. package/components/assistant/modern-chat-input/modern-chat-input.test.tsx +79 -79
  24. package/components/assistant/xertica-assistant/index.ts +3 -3
  25. package/components/assistant/xertica-assistant/parts/AssistantCollapsedView.tsx +99 -99
  26. package/components/assistant/xertica-assistant/parts/AssistantConversationList.tsx +104 -106
  27. package/components/assistant/xertica-assistant/parts/AssistantDocumentEditor.tsx +81 -81
  28. package/components/assistant/xertica-assistant/parts/AssistantFeedbackDialog.tsx +88 -78
  29. package/components/assistant/xertica-assistant/parts/AssistantHeader.tsx +75 -75
  30. package/components/assistant/xertica-assistant/parts/AssistantMessageBubble.tsx +564 -560
  31. package/components/assistant/xertica-assistant/parts/AssistantTabBar.tsx +67 -67
  32. package/components/assistant/xertica-assistant/parts/AssistantTypingIndicator.tsx +41 -41
  33. package/components/assistant/xertica-assistant/parts/AssistantWelcomeScreen.tsx +103 -103
  34. package/components/assistant/xertica-assistant/parts/index.ts +16 -16
  35. package/components/assistant/xertica-assistant/types.ts +134 -134
  36. package/components/assistant/xertica-assistant/use-assistant.ts +615 -615
  37. package/components/assistant/xertica-assistant/xertica-assistant.stories.tsx +407 -407
  38. package/components/assistant/xertica-assistant/xertica-assistant.test.tsx +65 -65
  39. package/components/assistant/xertica-assistant/xertica-assistant.tsx +611 -613
  40. package/components/blocks/card-patterns/ActivityCard.tsx +100 -100
  41. package/components/blocks/card-patterns/FeatureCard.tsx +109 -109
  42. package/components/blocks/card-patterns/FeatureCardSkeleton.tsx +1 -6
  43. package/components/blocks/card-patterns/NotificationCard.tsx +140 -140
  44. package/components/blocks/card-patterns/ProfileCard.tsx +112 -114
  45. package/components/blocks/card-patterns/ProjectCard.tsx +123 -123
  46. package/components/blocks/card-patterns/ProjectCardSkeleton.tsx +1 -6
  47. package/components/blocks/card-patterns/QuickActionCard.tsx +68 -68
  48. package/components/blocks/card-patterns/card-patterns.mdx +123 -123
  49. package/components/blocks/card-patterns/card-patterns.stories.tsx +594 -594
  50. package/components/blocks/card-patterns/index.ts +29 -29
  51. package/components/blocks/index.ts +1 -1
  52. package/components/brand/branding/branding.stories.tsx +57 -57
  53. package/components/brand/index.ts +6 -6
  54. package/components/brand/language-selector/index.ts +1 -1
  55. package/components/brand/language-selector/language-selector.mdx +126 -126
  56. package/components/brand/language-selector/language-selector.stories.tsx +1 -4
  57. package/components/brand/theme-toggle/ThemeToggle.tsx +74 -70
  58. package/components/brand/theme-toggle/index.ts +1 -1
  59. package/components/brand/theme-toggle/theme-toggle.stories.tsx +34 -34
  60. package/components/brand/theme-toggle/theme-toggle.test.tsx +34 -34
  61. package/components/brand/xertica-logo/XerticaLogo.stories.tsx +82 -82
  62. package/components/brand/xertica-logo/XerticaLogo.tsx +104 -104
  63. package/components/brand/xertica-logo/index.ts +1 -1
  64. package/components/brand/xertica-logo/xertica-logo.test.tsx +26 -26
  65. package/components/brand/xertica-orbe/XerticaOrbe.tsx +1927 -1927
  66. package/components/brand/xertica-orbe/index.ts +1 -1
  67. package/components/brand/xertica-orbe/xertica-orbe.stories.tsx +40 -40
  68. package/components/brand/xertica-orbe/xertica-orbe.test.tsx +19 -19
  69. package/components/brand/xertica-provider/XerticaProvider.tsx +1 -4
  70. package/components/brand/xertica-provider/index.ts +1 -1
  71. package/components/brand/xertica-provider/xertica-provider.test.tsx +74 -74
  72. package/components/brand/xertica-xlogo/XerticaXLogo.stories.tsx +79 -79
  73. package/components/brand/xertica-xlogo/XerticaXLogo.tsx +65 -65
  74. package/components/brand/xertica-xlogo/index.ts +1 -1
  75. package/components/brand/xertica-xlogo/xertica-xlogo.test.tsx +16 -16
  76. package/components/examples/ApiKeyMapExample.tsx +71 -71
  77. package/components/examples/DrawingMapExample.tsx +565 -565
  78. package/components/examples/FilterableMapExample.tsx +393 -393
  79. package/components/examples/LocationPickerExample.tsx +348 -348
  80. package/components/examples/MapExamples.tsx +268 -268
  81. package/components/examples/MapGmpExample.tsx +169 -169
  82. package/components/examples/MapShowcase.tsx +471 -471
  83. package/components/examples/RouteMapExamples.tsx +329 -329
  84. package/components/examples/SidebarLogoExample.tsx +65 -65
  85. package/components/examples/SimpleFilterableMap.tsx +219 -219
  86. package/components/examples/index.ts +45 -45
  87. package/components/figma/ImageWithFallback.tsx +27 -27
  88. package/components/hooks/index.ts +13 -13
  89. package/components/hooks/use-layout-shortcuts.ts +43 -43
  90. package/components/index.ts +86 -90
  91. package/components/layout/header/header.stories.tsx +204 -204
  92. package/components/layout/header/header.test.tsx +75 -75
  93. package/components/layout/header/header.tsx +349 -349
  94. package/components/layout/header/index.ts +1 -1
  95. package/components/layout/index.ts +2 -2
  96. package/components/layout/sidebar/index.ts +3 -3
  97. package/components/layout/sidebar/sidebar.stories.tsx +586 -586
  98. package/components/layout/sidebar/sidebar.test.tsx +76 -76
  99. package/components/layout/sidebar/sidebar.tsx +1079 -1073
  100. package/components/layout/sidebar/use-sidebar.ts +104 -104
  101. package/components/media/FloatingMediaWrapper.tsx +371 -371
  102. package/components/media/audio-player/AudioPlayer.stories.tsx +124 -124
  103. package/components/media/audio-player/AudioPlayer.test.tsx +106 -106
  104. package/components/media/audio-player/AudioPlayer.tsx +767 -765
  105. package/components/media/audio-player/index.ts +1 -1
  106. package/components/media/audio-player/use-audio-player.ts +312 -312
  107. package/components/media/index.ts +3 -3
  108. package/components/media/video-player/VideoPlayer.stories.tsx +98 -98
  109. package/components/media/video-player/VideoPlayer.test.tsx +73 -73
  110. package/components/media/video-player/VideoPlayer.tsx +310 -310
  111. package/components/media/video-player/index.ts +1 -1
  112. package/components/pages/forgot-password-page/ForgotPasswordPage.stories.tsx +24 -24
  113. package/components/pages/forgot-password-page/ForgotPasswordPage.tsx +188 -188
  114. package/components/pages/forgot-password-page/forgot-password-page.test.tsx +45 -45
  115. package/components/pages/forgot-password-page/index.ts +1 -1
  116. package/components/pages/home-content/HomeContent.stories.tsx +43 -43
  117. package/components/pages/home-content/HomeContent.tsx +120 -120
  118. package/components/pages/home-content/index.ts +1 -1
  119. package/components/pages/home-page/HomePage.stories.tsx +39 -39
  120. package/components/pages/home-page/HomePage.tsx +78 -74
  121. package/components/pages/home-page/home-page.test.tsx +53 -53
  122. package/components/pages/home-page/index.ts +1 -1
  123. package/components/pages/index.ts +8 -8
  124. package/components/pages/login-page/LoginPage.stories.tsx +39 -39
  125. package/components/pages/login-page/LoginPage.tsx +218 -216
  126. package/components/pages/login-page/index.ts +1 -1
  127. package/components/pages/login-page/login-page.test.tsx +63 -63
  128. package/components/pages/reset-password-page/ResetPasswordPage.stories.tsx +24 -24
  129. package/components/pages/reset-password-page/ResetPasswordPage.tsx +243 -239
  130. package/components/pages/reset-password-page/index.ts +1 -1
  131. package/components/pages/template-content/TemplateContent.stories.tsx +43 -43
  132. package/components/pages/template-content/TemplateContent.tsx +1354 -1235
  133. package/components/pages/template-content/index.ts +1 -1
  134. package/components/pages/template-page/TemplatePage.stories.tsx +39 -39
  135. package/components/pages/template-page/TemplatePage.tsx +62 -62
  136. package/components/pages/template-page/index.ts +1 -1
  137. package/components/pages/template-page/template-page.test.tsx +52 -52
  138. package/components/pages/verify-email-page/VerifyEmailPage.stories.tsx +41 -41
  139. package/components/pages/verify-email-page/VerifyEmailPage.tsx +206 -206
  140. package/components/pages/verify-email-page/index.ts +1 -1
  141. package/components/public-api-smoke.test.tsx +52 -52
  142. package/components/shared/CustomTooltipContent.tsx +48 -48
  143. package/components/shared/assistant-utils.test.ts +16 -16
  144. package/components/shared/assistant-utils.ts +225 -225
  145. package/components/shared/error-boundary.stories.tsx +114 -132
  146. package/components/shared/error-boundary.tsx +150 -154
  147. package/components/shared/error-fallbacks.tsx +222 -226
  148. package/components/shared/layout-constants.ts +8 -8
  149. package/components/shared/navigation.ts +35 -35
  150. package/components/shared/use-mobile.test.ts +16 -16
  151. package/components/shared/use-mobile.ts +36 -36
  152. package/components/shared/utils.test.ts +14 -14
  153. package/components/shared/utils.ts +6 -6
  154. package/components/ui/accordion/accordion.stories.tsx +105 -105
  155. package/components/ui/accordion/accordion.test.tsx +59 -59
  156. package/components/ui/accordion/accordion.tsx +77 -77
  157. package/components/ui/accordion/index.ts +1 -1
  158. package/components/ui/alert/alert.stories.tsx +86 -86
  159. package/components/ui/alert/alert.test.tsx +53 -53
  160. package/components/ui/alert/alert.tsx +93 -93
  161. package/components/ui/alert/index.ts +1 -1
  162. package/components/ui/alert-dialog/alert-dialog.stories.tsx +84 -84
  163. package/components/ui/alert-dialog/alert-dialog.test.tsx +70 -70
  164. package/components/ui/alert-dialog/alert-dialog.tsx +149 -149
  165. package/components/ui/alert-dialog/index.ts +1 -1
  166. package/components/ui/aspect-ratio/aspect-ratio.stories.tsx +46 -46
  167. package/components/ui/aspect-ratio/aspect-ratio.test.tsx +28 -28
  168. package/components/ui/aspect-ratio/aspect-ratio.tsx +20 -20
  169. package/components/ui/aspect-ratio/index.ts +1 -1
  170. package/components/ui/assistant-chart/AssistantChart.tsx +64 -64
  171. package/components/ui/assistant-chart/assistant-chart.stories.tsx +44 -44
  172. package/components/ui/assistant-chart/assistant-chart.test.tsx +46 -46
  173. package/components/ui/assistant-chart/index.ts +1 -1
  174. package/components/ui/avatar/avatar.stories.tsx +86 -86
  175. package/components/ui/avatar/avatar.test.tsx +55 -55
  176. package/components/ui/avatar/avatar.tsx +71 -71
  177. package/components/ui/avatar/index.ts +1 -1
  178. package/components/ui/badge/badge.stories.tsx +72 -72
  179. package/components/ui/badge/badge.test.tsx +40 -40
  180. package/components/ui/badge/badge.tsx +58 -58
  181. package/components/ui/badge/index.ts +1 -1
  182. package/components/ui/breadcrumb/breadcrumb.stories.tsx +123 -123
  183. package/components/ui/breadcrumb/breadcrumb.test.tsx +70 -70
  184. package/components/ui/breadcrumb/breadcrumb.tsx +114 -114
  185. package/components/ui/breadcrumb/index.ts +1 -1
  186. package/components/ui/button/button.stories.tsx +183 -183
  187. package/components/ui/button/button.test.tsx +64 -64
  188. package/components/ui/button/button.tsx +98 -98
  189. package/components/ui/button/index.ts +1 -1
  190. package/components/ui/calendar/calendar.stories.tsx +108 -108
  191. package/components/ui/calendar/calendar.test.tsx +53 -53
  192. package/components/ui/calendar/calendar.tsx +230 -230
  193. package/components/ui/calendar/index.ts +1 -1
  194. package/components/ui/card/card.stories.tsx +301 -301
  195. package/components/ui/card/card.test.tsx +55 -55
  196. package/components/ui/card/card.tsx +83 -83
  197. package/components/ui/card/index.ts +1 -1
  198. package/components/ui/carousel/carousel.stories.tsx +80 -80
  199. package/components/ui/carousel/carousel.test.tsx +75 -75
  200. package/components/ui/carousel/carousel.tsx +242 -242
  201. package/components/ui/carousel/index.ts +1 -1
  202. package/components/ui/chart/chart.stories.tsx +1328 -1328
  203. package/components/ui/chart/chart.test.tsx +178 -178
  204. package/components/ui/chart/chart.tsx +2232 -2232
  205. package/components/ui/chart/index.ts +1 -1
  206. package/components/ui/checkbox/checkbox.stories.tsx +109 -109
  207. package/components/ui/checkbox/checkbox.test.tsx +49 -49
  208. package/components/ui/checkbox/checkbox.tsx +68 -68
  209. package/components/ui/checkbox/index.ts +1 -1
  210. package/components/ui/collapsible/collapsible.stories.tsx +45 -45
  211. package/components/ui/collapsible/collapsible.test.tsx +51 -51
  212. package/components/ui/collapsible/collapsible.tsx +32 -32
  213. package/components/ui/collapsible/index.ts +1 -1
  214. package/components/ui/command/command.stories.tsx +134 -134
  215. package/components/ui/command/command.test.tsx +48 -48
  216. package/components/ui/command/command.tsx +163 -163
  217. package/components/ui/command/index.ts +1 -1
  218. package/components/ui/context-menu/context-menu.stories.tsx +76 -76
  219. package/components/ui/context-menu/context-menu.test.tsx +61 -61
  220. package/components/ui/context-menu/context-menu.tsx +236 -236
  221. package/components/ui/context-menu/index.ts +1 -1
  222. package/components/ui/dialog/dialog.stories.tsx +174 -174
  223. package/components/ui/dialog/dialog.test.tsx +78 -78
  224. package/components/ui/dialog/dialog.tsx +189 -189
  225. package/components/ui/dialog/index.ts +1 -1
  226. package/components/ui/drawer/drawer.stories.tsx +71 -71
  227. package/components/ui/drawer/drawer.test.tsx +67 -67
  228. package/components/ui/drawer/drawer.tsx +146 -146
  229. package/components/ui/drawer/index.ts +1 -1
  230. package/components/ui/dropdown-menu/dropdown-menu.stories.tsx +156 -156
  231. package/components/ui/dropdown-menu/dropdown-menu.test.tsx +62 -62
  232. package/components/ui/dropdown-menu/dropdown-menu.tsx +240 -240
  233. package/components/ui/dropdown-menu/index.ts +1 -1
  234. package/components/ui/empty/empty.stories.tsx +85 -85
  235. package/components/ui/empty/empty.test.tsx +31 -31
  236. package/components/ui/empty/empty.tsx +88 -88
  237. package/components/ui/empty/index.ts +1 -1
  238. package/components/ui/file-upload/file-upload.stories.tsx +144 -144
  239. package/components/ui/file-upload/file-upload.test.tsx +65 -65
  240. package/components/ui/file-upload/file-upload.tsx +142 -142
  241. package/components/ui/file-upload/index.ts +2 -2
  242. package/components/ui/file-upload/use-file-upload.ts +177 -177
  243. package/components/ui/form/form.stories.tsx +85 -85
  244. package/components/ui/form/form.test.tsx +75 -75
  245. package/components/ui/form/form.tsx +163 -163
  246. package/components/ui/form/index.ts +1 -1
  247. package/components/ui/google-maps-loader/google-maps-loader.test.tsx +35 -35
  248. package/components/ui/google-maps-loader/google-maps-loader.tsx +465 -465
  249. package/components/ui/google-maps-loader/index.ts +1 -1
  250. package/components/ui/hover-card/hover-card.stories.tsx +61 -61
  251. package/components/ui/hover-card/hover-card.test.tsx +48 -48
  252. package/components/ui/hover-card/hover-card.tsx +50 -50
  253. package/components/ui/hover-card/index.ts +1 -1
  254. package/components/ui/index.ts +400 -400
  255. package/components/ui/input/index.ts +1 -1
  256. package/components/ui/input/input.stories.tsx +153 -153
  257. package/components/ui/input/input.test.tsx +47 -47
  258. package/components/ui/input/input.tsx +57 -57
  259. package/components/ui/input-otp/index.ts +1 -1
  260. package/components/ui/input-otp/input-otp.stories.tsx +120 -120
  261. package/components/ui/input-otp/input-otp.test.tsx +74 -74
  262. package/components/ui/input-otp/input-otp.tsx +101 -101
  263. package/components/ui/label/index.ts +1 -1
  264. package/components/ui/label/label.stories.tsx +74 -74
  265. package/components/ui/label/label.test.tsx +45 -45
  266. package/components/ui/label/label.tsx +53 -53
  267. package/components/ui/map/index.ts +1 -1
  268. package/components/ui/map/map.stories.tsx +86 -86
  269. package/components/ui/map/map.test.tsx +82 -82
  270. package/components/ui/map/map.tsx +506 -506
  271. package/components/ui/map/mock.test.tsx +13 -13
  272. package/components/ui/map-config/index.ts +1 -1
  273. package/components/ui/map-config/map-config.ts +18 -18
  274. package/components/ui/map-layers/index.ts +1 -1
  275. package/components/ui/map-layers/map-layers.test.tsx +48 -48
  276. package/components/ui/map-layers/map-layers.tsx +126 -126
  277. package/components/ui/map.exports/index.ts +1 -1
  278. package/components/ui/map.exports/map.exports.ts +31 -31
  279. package/components/ui/menubar/index.ts +1 -1
  280. package/components/ui/menubar/menubar.stories.tsx +130 -130
  281. package/components/ui/menubar/menubar.test.tsx +53 -53
  282. package/components/ui/menubar/menubar.tsx +265 -265
  283. package/components/ui/navigation-menu/index.ts +1 -1
  284. package/components/ui/navigation-menu/navigation-menu.stories.tsx +126 -126
  285. package/components/ui/navigation-menu/navigation-menu.test.tsx +47 -47
  286. package/components/ui/navigation-menu/navigation-menu.tsx +165 -165
  287. package/components/ui/notification-badge/index.ts +1 -1
  288. package/components/ui/notification-badge/notification-badge.stories.tsx +66 -66
  289. package/components/ui/notification-badge/notification-badge.test.tsx +61 -61
  290. package/components/ui/notification-badge/notification-badge.tsx +91 -91
  291. package/components/ui/page-header/index.ts +1 -1
  292. package/components/ui/page-header/page-header.stories.tsx +69 -69
  293. package/components/ui/page-header/page-header.test.tsx +37 -37
  294. package/components/ui/page-header/page-header.tsx +124 -124
  295. package/components/ui/pagination/index.ts +3 -3
  296. package/components/ui/pagination/pagination.stories.tsx +210 -210
  297. package/components/ui/pagination/pagination.test.tsx +63 -63
  298. package/components/ui/pagination/pagination.tsx +140 -140
  299. package/components/ui/pagination/use-pagination.ts +173 -173
  300. package/components/ui/popover/index.ts +1 -1
  301. package/components/ui/popover/popover.stories.tsx +73 -73
  302. package/components/ui/popover/popover.test.tsx +48 -48
  303. package/components/ui/popover/popover.tsx +54 -54
  304. package/components/ui/progress/index.ts +1 -1
  305. package/components/ui/progress/progress.stories.tsx +55 -55
  306. package/components/ui/progress/progress.test.tsx +23 -23
  307. package/components/ui/progress/progress.tsx +68 -68
  308. package/components/ui/radio-group/index.ts +1 -1
  309. package/components/ui/radio-group/radio-group.stories.tsx +114 -114
  310. package/components/ui/radio-group/radio-group.test.tsx +78 -78
  311. package/components/ui/radio-group/radio-group.tsx +93 -93
  312. package/components/ui/rating/index.ts +1 -1
  313. package/components/ui/rating/rating.stories.tsx +50 -50
  314. package/components/ui/rating/rating.test.tsx +48 -48
  315. package/components/ui/rating/rating.tsx +145 -145
  316. package/components/ui/resizable/index.ts +1 -1
  317. package/components/ui/resizable/resizable.stories.tsx +88 -88
  318. package/components/ui/resizable/resizable.test.tsx +61 -61
  319. package/components/ui/resizable/resizable.tsx +452 -452
  320. package/components/ui/rich-text-editor/index.ts +7 -7
  321. package/components/ui/rich-text-editor/rich-text-editor.stories.tsx +290 -290
  322. package/components/ui/rich-text-editor/rich-text-editor.test.tsx +86 -86
  323. package/components/ui/rich-text-editor/rich-text-editor.tsx +634 -634
  324. package/components/ui/rich-text-editor/use-rich-text-editor.ts +453 -453
  325. package/components/ui/route-map/index.ts +1 -1
  326. package/components/ui/route-map/route-map.stories.tsx +48 -48
  327. package/components/ui/route-map/route-map.test.tsx +108 -108
  328. package/components/ui/route-map/route-map.tsx +349 -349
  329. package/components/ui/scroll-area/index.ts +1 -1
  330. package/components/ui/scroll-area/scroll-area.stories.tsx +31 -31
  331. package/components/ui/scroll-area/scroll-area.test.tsx +27 -27
  332. package/components/ui/scroll-area/scroll-area.tsx +70 -70
  333. package/components/ui/search/index.ts +1 -1
  334. package/components/ui/search/search.stories.tsx +107 -107
  335. package/components/ui/search/search.test.tsx +67 -67
  336. package/components/ui/search/search.tsx +141 -141
  337. package/components/ui/select/index.ts +1 -1
  338. package/components/ui/select/select.stories.tsx +163 -163
  339. package/components/ui/select/select.test.tsx +99 -99
  340. package/components/ui/select/select.tsx +195 -195
  341. package/components/ui/separator/index.ts +1 -1
  342. package/components/ui/separator/separator.stories.tsx +55 -55
  343. package/components/ui/separator/separator.test.tsx +23 -23
  344. package/components/ui/separator/separator.tsx +39 -39
  345. package/components/ui/sheet/index.ts +1 -1
  346. package/components/ui/sheet/sheet.stories.tsx +93 -93
  347. package/components/ui/sheet/sheet.test.tsx +62 -62
  348. package/components/ui/sheet/sheet.tsx +149 -149
  349. package/components/ui/simple-map/index.ts +1 -1
  350. package/components/ui/simple-map/simple-map.stories.tsx +44 -44
  351. package/components/ui/simple-map/simple-map.test.tsx +36 -36
  352. package/components/ui/simple-map/simple-map.tsx +92 -92
  353. package/components/ui/skeleton/index.ts +1 -1
  354. package/components/ui/skeleton/skeleton.stories.tsx +36 -36
  355. package/components/ui/skeleton/skeleton.test.tsx +19 -19
  356. package/components/ui/skeleton/skeleton.tsx +25 -25
  357. package/components/ui/slider/index.ts +1 -1
  358. package/components/ui/slider/slider.stories.tsx +44 -44
  359. package/components/ui/slider/slider.test.tsx +25 -25
  360. package/components/ui/slider/slider.tsx +66 -66
  361. package/components/ui/sonner/index.ts +1 -1
  362. package/components/ui/sonner/sonner.stories.tsx +41 -41
  363. package/components/ui/sonner/sonner.test.tsx +24 -24
  364. package/components/ui/sonner/sonner.tsx +74 -74
  365. package/components/ui/stats-card/index.ts +2 -2
  366. package/components/ui/stats-card/stats-card-skeleton.tsx +1 -3
  367. package/components/ui/stats-card/stats-card.stories.tsx +99 -99
  368. package/components/ui/stats-card/stats-card.test.tsx +34 -34
  369. package/components/ui/stats-card/stats-card.tsx +93 -93
  370. package/components/ui/stepper/index.ts +3 -3
  371. package/components/ui/stepper/stepper.stories.tsx +171 -171
  372. package/components/ui/stepper/stepper.test.tsx +47 -47
  373. package/components/ui/stepper/stepper.tsx +190 -190
  374. package/components/ui/stepper/use-stepper.ts +139 -139
  375. package/components/ui/switch/index.ts +1 -1
  376. package/components/ui/switch/switch.stories.tsx +93 -93
  377. package/components/ui/switch/switch.test.tsx +44 -44
  378. package/components/ui/switch/switch.tsx +70 -70
  379. package/components/ui/table/index.ts +1 -1
  380. package/components/ui/table/table.stories.tsx +114 -114
  381. package/components/ui/table/table.test.tsx +43 -43
  382. package/components/ui/table/table.tsx +104 -104
  383. package/components/ui/tabs/index.ts +1 -1
  384. package/components/ui/tabs/tabs.stories.tsx +140 -140
  385. package/components/ui/tabs/tabs.test.tsx +50 -50
  386. package/components/ui/tabs/tabs.tsx +66 -66
  387. package/components/ui/textarea/index.ts +1 -1
  388. package/components/ui/textarea/textarea.stories.tsx +69 -69
  389. package/components/ui/textarea/textarea.test.tsx +41 -41
  390. package/components/ui/textarea/textarea.tsx +61 -61
  391. package/components/ui/timeline/index.ts +1 -1
  392. package/components/ui/timeline/timeline.stories.tsx +97 -97
  393. package/components/ui/timeline/timeline.test.tsx +53 -53
  394. package/components/ui/timeline/timeline.tsx +124 -124
  395. package/components/ui/toggle/index.ts +1 -1
  396. package/components/ui/toggle/toggle.stories.tsx +56 -56
  397. package/components/ui/toggle/toggle.test.tsx +32 -32
  398. package/components/ui/toggle/toggle.tsx +55 -55
  399. package/components/ui/toggle-group/index.ts +1 -1
  400. package/components/ui/toggle-group/toggle-group.stories.tsx +66 -66
  401. package/components/ui/toggle-group/toggle-group.test.tsx +47 -47
  402. package/components/ui/toggle-group/toggle-group.tsx +79 -79
  403. package/components/ui/tooltip/index.ts +1 -1
  404. package/components/ui/tooltip/tooltip.stories.tsx +83 -83
  405. package/components/ui/tooltip/tooltip.test.tsx +39 -39
  406. package/components/ui/tooltip/tooltip.tsx +69 -69
  407. package/components/ui/tree-view/index.ts +4 -4
  408. package/components/ui/tree-view/tree-view.stories.tsx +154 -154
  409. package/components/ui/tree-view/tree-view.test.tsx +58 -58
  410. package/components/ui/tree-view/tree-view.tsx +171 -171
  411. package/components/ui/tree-view/use-tree-view.ts +237 -237
  412. package/components.json +892 -892
  413. package/contexts/ApiKeyContext.test.tsx +26 -26
  414. package/contexts/ApiKeyContext.tsx +196 -196
  415. package/contexts/AssistenteContext.test.tsx +17 -17
  416. package/contexts/AssistenteContext.tsx +113 -113
  417. package/contexts/AuthContext.tsx +121 -118
  418. package/contexts/BrandColorsContext.test.tsx +21 -21
  419. package/contexts/BrandColorsContext.tsx +251 -251
  420. package/contexts/LanguageContext.tsx +1 -2
  421. package/contexts/LayoutContext.test.tsx +29 -29
  422. package/contexts/LayoutContext.tsx +140 -140
  423. package/contexts/ThemeContext.test.tsx +38 -38
  424. package/contexts/ThemeContext.tsx +111 -111
  425. package/contexts/index.ts +8 -8
  426. package/contexts/theme-data.ts +340 -340
  427. package/dist/AssistantChart-COGiOV-g.cjs +3541 -0
  428. package/dist/AssistantChart-CWX1OWNM.js +3373 -0
  429. package/dist/AudioPlayer-9psiEucT.cjs +1282 -0
  430. package/dist/AudioPlayer-Dp2bD1Gk.js +1278 -0
  431. package/dist/BrandColorsContext-DZT7JjeD.js +659 -0
  432. package/dist/BrandColorsContext-awnBCmC4.cjs +666 -0
  433. package/dist/CodeBlock-DYkTfR0f.js +221 -0
  434. package/dist/CodeBlock-EOvp9cVu.cjs +223 -0
  435. package/dist/CustomTooltipContent-BhdIeBEg.cjs +54 -0
  436. package/dist/CustomTooltipContent-CNbVB2NS.js +33 -0
  437. package/dist/FeatureCard-BZ4CYxFf.cjs +497 -0
  438. package/dist/FeatureCard-DNycVGwT.js +485 -0
  439. package/dist/FeatureCardSkeleton-DZqc96mt.js +27 -0
  440. package/dist/FeatureCardSkeleton-pTa0YNKP.cjs +29 -0
  441. package/dist/LayoutContext-BEq_-n98.cjs +96 -0
  442. package/dist/LayoutContext-DNl1xSoX.js +92 -0
  443. package/dist/ThemeContext-CMD3z2Dz.cjs +1930 -0
  444. package/dist/ThemeContext-x_F2zsnv.js +1923 -0
  445. package/dist/VerifyEmailPage-BJjAMUTW.js +3223 -0
  446. package/dist/VerifyEmailPage-Bv8Ah_TK.cjs +3235 -0
  447. package/dist/VerifyEmailPage-CkBYfsNy.cjs +3232 -0
  448. package/dist/VerifyEmailPage-Cyl55sJb.js +3226 -0
  449. package/dist/VerifyEmailPage-X14vhdyl.js +3296 -0
  450. package/dist/VerifyEmailPage-u_Dn7t1U.cjs +3305 -0
  451. package/dist/XerticaOrbe-Uk2JML1-.cjs +1927 -0
  452. package/dist/XerticaOrbe-jA5T2iOk.js +1925 -0
  453. package/dist/XerticaProvider-BErr83Bg.js +42 -0
  454. package/dist/XerticaProvider-CwOkHxiT.cjs +44 -0
  455. package/dist/XerticaProvider-DUOJg9iX.js +49 -0
  456. package/dist/XerticaProvider-Dl_b72_l.cjs +51 -0
  457. package/dist/XerticaXLogo-BX3ueACh.js +255 -0
  458. package/dist/XerticaXLogo-mqjoBiLI.js +252 -0
  459. package/dist/XerticaXLogo-qBPhwK3g.cjs +260 -0
  460. package/dist/XerticaXLogo-uQgwns_E.cjs +257 -0
  461. package/dist/alert-dialog-DhwPioBa.cjs +885 -0
  462. package/dist/alert-dialog-DqlRW_An.js +831 -0
  463. package/dist/assistant.cjs.js +8 -4
  464. package/dist/assistant.es.js +5 -11
  465. package/dist/avatar-3kO2Anrp.js +54 -0
  466. package/dist/avatar-BCM7YQRC.cjs +77 -0
  467. package/dist/blocks.cjs.js +9 -4
  468. package/dist/blocks.es.js +2 -16
  469. package/dist/brand.cjs.js +10 -5
  470. package/dist/brand.es.js +3 -11
  471. package/dist/breadcrumb-BKtHF4gk.cjs +98 -0
  472. package/dist/breadcrumb-ifNsA7Zl.js +90 -0
  473. package/dist/button-0BlA47It.cjs +85 -0
  474. package/dist/button-DZHzN1Gd.js +62 -0
  475. package/dist/cli.js +471 -93
  476. package/dist/components/brand/theme-toggle/ThemeToggle.d.ts +1 -1
  477. package/dist/components/index.d.ts +1 -1
  478. package/dist/dropdown-menu-BMcykFDf.cjs +225 -0
  479. package/dist/dropdown-menu-Dn_eV2Xb.js +190 -0
  480. package/dist/google-maps-loader-BCe58h9D.js +308 -0
  481. package/dist/google-maps-loader-casMyxlo.cjs +316 -0
  482. package/dist/hooks.cjs.js +12 -8
  483. package/dist/hooks.es.js +10 -27
  484. package/dist/index-9GWd0qxq.cjs +12 -0
  485. package/dist/index-BabBx2pa.js +6 -0
  486. package/dist/index.cjs.js +37 -32
  487. package/dist/index.es.js +30 -363
  488. package/dist/input-C_UiS2Py.cjs +152 -0
  489. package/dist/input-cc-PTD4R.js +123 -0
  490. package/dist/layout.cjs.js +10 -6
  491. package/dist/layout.es.js +7 -9
  492. package/dist/media.cjs.js +8 -3
  493. package/dist/media.es.js +1 -6
  494. package/dist/pages.cjs.js +8 -3
  495. package/dist/pages.es.js +1 -11
  496. package/dist/progress-C7Lti5wo.js +80 -0
  497. package/dist/progress-Cqwxbqs1.cjs +103 -0
  498. package/dist/rich-text-editor-DqLICivI.js +2832 -0
  499. package/dist/rich-text-editor-DxO1Hz3a.cjs +2903 -0
  500. package/dist/select-CH6v_KcQ.cjs +161 -0
  501. package/dist/select-D-xvCZK2.js +130 -0
  502. package/dist/sidebar-3XyzjVBw.js +792 -0
  503. package/dist/sidebar-B4ZWaMrE.js +792 -0
  504. package/dist/sidebar-BS1p2V7t.cjs +795 -0
  505. package/dist/sidebar-DyYvgyBj.cjs +795 -0
  506. package/dist/skeleton-DjiHerJn.cjs +87 -0
  507. package/dist/skeleton-DtR5tkYe.js +78 -0
  508. package/dist/slider-B00b9SVK.cjs +78 -0
  509. package/dist/slider-DQCNUUMj.js +56 -0
  510. package/dist/sonner-B-jWlik1.cjs +68 -0
  511. package/dist/sonner-C9tiqj4f.js +47 -0
  512. package/dist/tooltip-D8n9UYoU.cjs +72 -0
  513. package/dist/tooltip-RtbSmPYJ.js +48 -0
  514. package/dist/ui.cjs.js +23 -18
  515. package/dist/ui.es.js +16 -303
  516. package/dist/use-audio-player-B78fd2ct.js +188 -0
  517. package/dist/use-audio-player-DGvhPrgR.cjs +190 -0
  518. package/dist/use-mobile-BdXTRb0Z.cjs +51 -0
  519. package/dist/use-mobile-Ce2cBAQe.js +29 -0
  520. package/dist/xertica-assistant-B1NaSFFj.js +2173 -0
  521. package/dist/xertica-assistant-B687qEPU.js +2165 -0
  522. package/dist/xertica-assistant-CIaUlbIt.cjs +2180 -0
  523. package/dist/xertica-assistant-sOHwTgIP.cjs +2172 -0
  524. package/dist/xertica-ui.css +1 -1
  525. package/docs/ai-usage.md +195 -195
  526. package/docs/architecture-improvements.md +456 -456
  527. package/docs/architecture.md +312 -306
  528. package/docs/components/accordion.md +109 -109
  529. package/docs/components/alert-dialog.md +127 -127
  530. package/docs/components/alert.md +106 -106
  531. package/docs/components/aspect-ratio.md +58 -58
  532. package/docs/components/assistant-chart.md +47 -47
  533. package/docs/components/assistant.md +428 -426
  534. package/docs/components/audio-player.md +167 -167
  535. package/docs/components/avatar.md +101 -101
  536. package/docs/components/badge.md +84 -84
  537. package/docs/components/branding.md +252 -252
  538. package/docs/components/breadcrumb.md +104 -104
  539. package/docs/components/button.md +156 -156
  540. package/docs/components/calendar.md +141 -141
  541. package/docs/components/card-patterns.md +447 -445
  542. package/docs/components/card.md +245 -245
  543. package/docs/components/carousel.md +100 -100
  544. package/docs/components/chart.md +638 -638
  545. package/docs/components/checkbox.md +88 -88
  546. package/docs/components/code-block.md +105 -105
  547. package/docs/components/collapsible.md +86 -86
  548. package/docs/components/command.md +113 -113
  549. package/docs/components/context-menu.md +81 -81
  550. package/docs/components/dialog.md +198 -198
  551. package/docs/components/drawer.md +105 -105
  552. package/docs/components/dropdown-menu.md +127 -127
  553. package/docs/components/empty.md +127 -127
  554. package/docs/components/error-boundary.md +201 -191
  555. package/docs/components/file-upload.md +189 -189
  556. package/docs/components/floating-media-wrapper.md +63 -63
  557. package/docs/components/form.md +177 -177
  558. package/docs/components/formatted-document.md +105 -105
  559. package/docs/components/google-maps-loader.md +44 -44
  560. package/docs/components/header.md +177 -177
  561. package/docs/components/hooks.md +432 -430
  562. package/docs/components/hover-card.md +86 -86
  563. package/docs/components/image-with-fallback.md +107 -107
  564. package/docs/components/input-otp.md +95 -95
  565. package/docs/components/input.md +130 -130
  566. package/docs/components/label.md +69 -69
  567. package/docs/components/language-selector.md +20 -16
  568. package/docs/components/map-layers.md +138 -138
  569. package/docs/components/map.md +84 -84
  570. package/docs/components/markdown-message.md +47 -47
  571. package/docs/components/menubar.md +89 -89
  572. package/docs/components/modern-chat-input.md +164 -164
  573. package/docs/components/navigation-menu.md +83 -83
  574. package/docs/components/notification-badge.md +78 -78
  575. package/docs/components/page-header.md +93 -93
  576. package/docs/components/pages.md +323 -309
  577. package/docs/components/pagination.md +334 -334
  578. package/docs/components/popover.md +116 -116
  579. package/docs/components/progress.md +103 -103
  580. package/docs/components/radio-group.md +133 -133
  581. package/docs/components/rating.md +77 -77
  582. package/docs/components/resizable.md +84 -84
  583. package/docs/components/rich-text-editor.md +255 -255
  584. package/docs/components/route-map.md +124 -124
  585. package/docs/components/scroll-area.md +58 -58
  586. package/docs/components/search.md +87 -87
  587. package/docs/components/select.md +144 -144
  588. package/docs/components/separator.md +58 -58
  589. package/docs/components/sheet.md +122 -122
  590. package/docs/components/sidebar.md +314 -314
  591. package/docs/components/simple-map.md +51 -51
  592. package/docs/components/skeleton.md +99 -99
  593. package/docs/components/slider.md +84 -84
  594. package/docs/components/sonner.md +115 -115
  595. package/docs/components/stats-card.md +120 -120
  596. package/docs/components/stepper.md +268 -268
  597. package/docs/components/switch.md +106 -106
  598. package/docs/components/table.md +138 -138
  599. package/docs/components/tabs.md +117 -117
  600. package/docs/components/textarea.md +86 -86
  601. package/docs/components/theme-toggle.md +73 -73
  602. package/docs/components/timeline.md +121 -121
  603. package/docs/components/toggle-group.md +68 -68
  604. package/docs/components/toggle.md +62 -62
  605. package/docs/components/tooltip.md +116 -116
  606. package/docs/components/tree-view.md +238 -238
  607. package/docs/components/use-mobile.md +96 -96
  608. package/docs/components/video-player.md +68 -68
  609. package/docs/components/xertica-logo.md +36 -36
  610. package/docs/components/xertica-orbe.md +35 -35
  611. package/docs/components/xertica-provider.md +65 -65
  612. package/docs/components/xertica-xlogo.md +35 -35
  613. package/docs/decision-tree.md +293 -293
  614. package/docs/doc-audit.md +244 -243
  615. package/docs/form-sizing.md +162 -162
  616. package/docs/getting-started.md +616 -591
  617. package/docs/guidelines.md +330 -328
  618. package/docs/i18n.md +61 -57
  619. package/docs/installation.md +268 -267
  620. package/docs/layout.md +143 -143
  621. package/docs/llms.md +295 -295
  622. package/docs/patterns/analytics.md +194 -194
  623. package/docs/patterns/crud.md +149 -149
  624. package/docs/patterns/dashboard.md +138 -138
  625. package/docs/patterns/detail-page.md +296 -296
  626. package/docs/patterns/form.md +241 -241
  627. package/docs/patterns/login.md +156 -156
  628. package/docs/patterns/settings.md +368 -368
  629. package/docs/patterns/wizard.md +213 -213
  630. package/docs/state-management.md +289 -289
  631. package/guidelines/Guidelines.md +409 -406
  632. package/hooks/useTheme.test.tsx +16 -16
  633. package/hooks/useTheme.ts +4 -4
  634. package/imports/Podcast.tsx +540 -540
  635. package/imports/XerticaAi.tsx +46 -46
  636. package/imports/XerticaX.tsx +15 -15
  637. package/imports/svg-aueiaqngck.ts +20 -20
  638. package/imports/svg-v9krss1ozd.ts +23 -23
  639. package/imports/svg-vhrdofe3qe.ts +6 -6
  640. package/llms-compact.txt +2 -1
  641. package/llms.txt +2 -1
  642. package/mcp/resources.json +22 -22
  643. package/mcp/tools.json +35 -35
  644. package/package.json +219 -213
  645. package/scripts/ai-validator.ts +91 -91
  646. package/scripts/cleanup-case-dupes.ts +62 -62
  647. package/scripts/generate-ai-manifests.ts +107 -107
  648. package/styles/globals.css +13 -13
  649. package/styles/xertica/app-overrides/chat.css +61 -61
  650. package/styles/xertica/app-overrides/scrollbar.css +33 -33
  651. package/styles/xertica/base.css +90 -71
  652. package/styles/xertica/integrations/google-maps.css +76 -76
  653. package/styles/xertica/integrations/sonner.css +73 -73
  654. package/styles/xertica/theme-map.css +102 -99
  655. package/styles/xertica/tokens.css +240 -236
  656. package/templates/CLAUDE.md +16 -1
  657. package/templates/eslint.config.js +26 -26
  658. package/templates/guidelines/Guidelines.md +577 -553
  659. package/templates/package.json +69 -69
  660. package/templates/postcss.config.js +6 -6
  661. package/templates/src/app/App.tsx +46 -46
  662. package/templates/src/app/components/AppLayout.tsx +55 -55
  663. package/templates/src/app/components/AuthGuard.tsx +131 -82
  664. package/templates/src/app/context/AuthContext.tsx +108 -108
  665. package/templates/src/features/assistant/index.ts +5 -5
  666. package/templates/src/features/auth/index.ts +4 -4
  667. package/templates/src/features/auth/ui/AuthPageShell.tsx +32 -32
  668. package/templates/src/features/auth/ui/ForgotPasswordContent.tsx +70 -72
  669. package/templates/src/features/auth/ui/LoginContent.tsx +92 -92
  670. package/templates/src/features/auth/ui/ResetPasswordContent.tsx +6 -2
  671. package/templates/src/features/auth/ui/SocialLoginButtons.tsx +78 -78
  672. package/templates/src/features/auth/ui/VerifyEmailContent.tsx +2 -6
  673. package/templates/src/features/home/data/mock.ts +41 -35
  674. package/templates/src/features/home/index.ts +11 -11
  675. package/templates/src/features/home/store/dashboardStore.ts +25 -25
  676. package/templates/src/features/home/ui/HomeContent.tsx +117 -119
  677. package/templates/src/features/template/index.ts +5 -5
  678. package/templates/src/features/template/ui/CrudTemplate.tsx +1 -4
  679. package/templates/src/features/template/ui/LoginTemplate.tsx +1 -1
  680. package/templates/src/features/template/ui/TemplateContent.tsx +29 -21
  681. package/templates/src/locales/en/pages/templates.json +17 -17
  682. package/templates/src/locales/es/pages/templates.json +17 -17
  683. package/templates/src/locales/pt-BR/pages/templates.json +17 -17
  684. package/templates/src/main.tsx +11 -11
  685. package/templates/src/pages/AssistantPage.tsx +26 -20
  686. package/templates/src/pages/ForgotPasswordPage.tsx +6 -6
  687. package/templates/src/pages/HomePage.tsx +53 -49
  688. package/templates/src/pages/LoginPage.tsx +10 -10
  689. package/templates/src/pages/ResetPasswordPage.tsx +6 -6
  690. package/templates/src/pages/TemplatePage.tsx +28 -28
  691. package/templates/src/pages/VerifyEmailPage.tsx +6 -6
  692. package/templates/src/shared/config/navigation.ts +19 -19
  693. package/templates/src/shared/error-boundary.tsx +150 -154
  694. package/templates/src/shared/error-fallbacks.tsx +222 -226
  695. package/templates/src/shared/lib/auth.ts +20 -20
  696. package/templates/src/shared/types/auth.ts +3 -3
  697. package/templates/src/styles/index.css +95 -95
  698. package/templates/src/styles/xertica/tokens.css +240 -236
  699. package/templates/tsconfig.json +25 -25
  700. package/templates/tsconfig.node.json +12 -12
  701. package/templates/vite-env.d.ts +1 -1
  702. package/templates/vite.config.js +20 -20
  703. package/templates/vite.config.ts +54 -51
  704. package/utils/color-utils.ts +72 -72
  705. package/utils/demo-responses.test.ts +10 -10
  706. package/utils/demo-responses.ts +151 -151
  707. package/utils/gemini.test.ts +25 -25
  708. package/utils/gemini.ts +155 -155
package/bin/cli.ts CHANGED
@@ -1,748 +1,1244 @@
1
- #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import prompts from 'prompts';
4
- import chalk from 'chalk';
5
- import ora from 'ora';
6
- import fs from 'fs-extra';
7
- import path from 'path';
8
- import { fileURLToPath } from 'url';
9
- import { execa } from 'execa';
10
- import { colorThemes } from '../contexts/theme-data';
11
- import { generateTokensCss } from './generate-tokens';
12
- import {
13
- SUPPORTED_LANGUAGES,
14
- DEFAULT_SELECTION,
15
- readLanguagesConfig,
16
- writeLanguagesConfig,
17
- syncLocaleFiles,
18
- generateI18nFile,
19
- generateAppTsx,
20
- } from './language-config';
21
-
22
- const __filename = fileURLToPath(import.meta.url);
23
- const __dirname = path.dirname(__filename);
24
-
25
- // Read CLI version from package.json so it always matches the published one,
26
- // instead of hardcoding a literal that drifts on every version bump.
27
- const pkgJson = JSON.parse(
28
- fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf-8')
29
- ) as { version: string };
30
-
31
- const program = new Command();
32
-
33
- program
34
- .name('xertica-ui')
35
- .description('CLI to initialize Xertica UI projects')
36
- .version(pkgJson.version);
37
-
38
- program
39
- .command('init')
40
- .description('Initialize a new Xertica UI project')
41
- .argument('[directory]', 'Directory to initialize in', '.')
42
- .action(async directory => {
43
- const targetDir = path.resolve(process.cwd(), directory);
44
- const templatesDir = path.resolve(__dirname, '../templates');
45
-
46
- console.log(chalk.blue('🚀 Welcome to Xertica UI CLI!'));
47
-
48
- const response = await prompts([
49
- {
50
- type: 'multiselect',
51
- name: 'pages',
52
- message: 'Which pages/templates to include?',
53
- choices: [
54
- {
55
- title: 'Login Page (+ Forgot / Verify / Reset Password)',
56
- value: 'login',
57
- selected: true,
58
- },
59
- { title: 'Home Page', value: 'home', selected: true },
60
- { title: 'Template Page (components showcase)', value: 'template', selected: true },
61
- ],
62
- },
63
- {
64
- type: 'multiselect',
65
- name: 'languages',
66
- message: 'Which languages should the app support?',
67
- instructions: false,
68
- hint: 'Select at least 1. Single-language apps auto-hide the LanguageSelector.',
69
- min: 1,
70
- choices: SUPPORTED_LANGUAGES.map(l => ({
71
- title: l.label,
72
- value: l.code,
73
- selected: true,
74
- })),
75
- },
76
- {
77
- type: 'select',
78
- name: 'theme',
79
- message: 'Select the default color theme for your project:',
80
- choices: colorThemes.map(t => ({
81
- title: t.name,
82
- description: t.description,
83
- value: t.id,
84
- })),
85
- initial: 0,
86
- },
87
- {
88
- type: 'confirm',
89
- name: 'install',
90
- message: 'Install dependencies automatically?',
91
- initial: true,
92
- },
93
- ]);
94
-
95
- // Abort if the user cancelled any prompt (prompts returns undefined on Ctrl+C)
96
- if (!response.pages || !response.languages || !response.theme) return;
97
-
98
- const spinner = ora('Initializing project...').start();
99
-
100
- try {
101
- await fs.ensureDir(targetDir);
102
-
103
- const pages = response.pages || [];
104
- const hasLogin = pages.includes('login');
105
- const hasHome = pages.includes('home');
106
- const hasTemplate = pages.includes('template');
107
-
108
- // Resolve selected languages fall back to all defaults if the user
109
- // somehow ended up with an empty array (the prompt's min:1 should prevent
110
- // this, but we defend defensively).
111
- const selectedLanguages: string[] =
112
- Array.isArray(response.languages) && response.languages.length > 0
113
- ? response.languages
114
- : DEFAULT_SELECTION;
115
-
116
- // 1. Copy root config files
117
- const rootFilesToCopy = [
118
- 'index.html',
119
- 'vite.config.ts',
120
- 'tsconfig.json',
121
- 'tsconfig.node.json',
122
- 'postcss.config.js',
123
- 'vite-env.d.ts',
124
- 'eslint.config.js',
125
- '.env.example',
126
- 'guidelines',
127
- 'CLAUDE.md',
128
- ];
129
-
130
- for (const file of rootFilesToCopy) {
131
- const srcPath = path.join(templatesDir, file);
132
- if (await fs.pathExists(srcPath)) {
133
- await fs.copy(srcPath, path.join(targetDir, file));
134
- }
135
- }
136
-
137
- // 2. Copy package.json
138
- const pkgTemplatePath = path.join(templatesDir, 'package.json');
139
- if (await fs.pathExists(pkgTemplatePath)) {
140
- const pkgContent = await fs.readJson(pkgTemplatePath);
141
- const projectName = path.basename(targetDir) || 'my-xertica-app';
142
- pkgContent.name = projectName.toLowerCase().replace(/[^a-z0-9-]/g, '-');
143
- await fs.writeJson(path.join(targetDir, 'package.json'), pkgContent, { spaces: 2 });
144
- }
145
-
146
- // 3. Copy src/main.tsx
147
- await fs.copy(
148
- path.join(templatesDir, 'src', 'main.tsx'),
149
- path.join(targetDir, 'src', 'main.tsx')
150
- );
151
-
152
- // 4. Generate src/app/App.tsx with the user's language selection
153
- // (instead of copying the static template, we inject `availableLanguages`)
154
- await fs.ensureDir(path.join(targetDir, 'src', 'app'));
155
- await fs.writeFile(
156
- path.join(targetDir, 'src', 'app', 'App.tsx'),
157
- generateAppTsx(selectedLanguages)
158
- );
159
-
160
- // 5. Copy src/app/components/AppLayout.tsx (always needed)
161
- await fs.ensureDir(path.join(targetDir, 'src', 'app', 'components'));
162
- await fs.copy(
163
- path.join(templatesDir, 'src', 'app', 'components', 'AppLayout.tsx'),
164
- path.join(targetDir, 'src', 'app', 'components', 'AppLayout.tsx')
165
- );
166
-
167
- // 6. Copy src/shared/ (always needed — auth helpers, navigation config, types)
168
- await fs.copy(
169
- path.join(templatesDir, 'src', 'shared'),
170
- path.join(targetDir, 'src', 'shared')
171
- );
172
-
173
- // 6.1 Generate i18n.ts with only the imports/resources for selected languages
174
- await fs.writeFile(
175
- path.join(targetDir, 'src', 'i18n.ts'),
176
- generateI18nFile(selectedLanguages)
177
- );
178
-
179
- // 6.2 Copy only the selected locale JSON files (no orphan locales)
180
- await syncLocaleFiles(templatesDir, targetDir, selectedLanguages, { pruneOthers: true });
181
-
182
- // 6.3 Persist the language selection so `update` can remember it
183
- await writeLanguagesConfig(targetDir, selectedLanguages);
184
-
185
- // 6.4 Copy context
186
- await fs.ensureDir(path.join(targetDir, 'src', 'app', 'context'));
187
- await fs.copy(
188
- path.join(templatesDir, 'src', 'app', 'context', 'AuthContext.tsx'),
189
- path.join(targetDir, 'src', 'app', 'context', 'AuthContext.tsx')
190
- );
191
-
192
- // 7. Copy features based on selections
193
- if (hasLogin) {
194
- await fs.copy(
195
- path.join(templatesDir, 'src', 'features', 'auth'),
196
- path.join(targetDir, 'src', 'features', 'auth')
197
- );
198
- }
199
- if (hasHome) {
200
- await fs.copy(
201
- path.join(templatesDir, 'src', 'features', 'home'),
202
- path.join(targetDir, 'src', 'features', 'home')
203
- );
204
- }
205
- if (hasTemplate) {
206
- await fs.copy(
207
- path.join(templatesDir, 'src', 'features', 'template'),
208
- path.join(targetDir, 'src', 'features', 'template')
209
- );
210
- }
211
- // Always copy assistant as AppLayout depends on it
212
- await fs.copy(
213
- path.join(templatesDir, 'src', 'features', 'assistant'),
214
- path.join(targetDir, 'src', 'features', 'assistant')
215
- );
216
-
217
- // 8. Copy pages based on selections
218
- await fs.ensureDir(path.join(targetDir, 'src', 'pages'));
219
-
220
- const pagesToCopy: string[] = [];
221
- if (hasLogin)
222
- pagesToCopy.push(
223
- 'LoginPage.tsx',
224
- 'ForgotPasswordPage.tsx',
225
- 'VerifyEmailPage.tsx',
226
- 'ResetPasswordPage.tsx'
227
- );
228
- if (hasHome) pagesToCopy.push('HomePage.tsx');
229
- if (hasTemplate) pagesToCopy.push('TemplatePage.tsx');
230
- pagesToCopy.push('AssistantPage.tsx');
231
-
232
- for (const pageFile of pagesToCopy) {
233
- const src = path.join(templatesDir, 'src', 'pages', pageFile);
234
- if (await fs.pathExists(src)) {
235
- await fs.copy(src, path.join(targetDir, 'src', 'pages', pageFile));
236
- }
237
- }
238
-
239
- // 9. Generate AuthGuard.tsx based on selected pages
240
- const firstProtectedPath = hasHome ? '/home' : hasTemplate ? '/template' : '/login';
241
-
242
- const authGuardContent = `import React from 'react';
243
- import { Routes, Route, Navigate } from 'react-router-dom';
244
- import { useAuth } from '../context/AuthContext';
245
-
246
- // ─── Lazy page imports ────────────────────────────────────────────────────────
247
-
248
- ${hasLogin ? `const LoginPage = React.lazy(() => import('../../pages/LoginPage').then(m => ({ default: m.LoginPage })));
249
- const ForgotPasswordPage = React.lazy(() => import('../../pages/ForgotPasswordPage').then(m => ({ default: m.ForgotPasswordPage })));
250
- const VerifyEmailPage = React.lazy(() => import('../../pages/VerifyEmailPage').then(m => ({ default: m.VerifyEmailPage })));
251
- const ResetPasswordPage = React.lazy(() => import('../../pages/ResetPasswordPage').then(m => ({ default: m.ResetPasswordPage })));` : ''}
252
-
253
- ${hasHome ? `const HomePage = React.lazy(() => import('../../pages/HomePage').then(m => ({ default: m.HomePage })));` : ''}
254
- ${hasTemplate ? `const TemplatePage = React.lazy(() => import('../../pages/TemplatePage').then(m => ({ default: m.TemplatePage })));` : ''}
255
- const AssistantPage = React.lazy(() => import('../../pages/AssistantPage').then(m => ({ default: m.AssistantPage })));
256
-
257
- // ─── Route guards ─────────────────────────────────────────────────────────────
258
-
259
- function ProtectedRoute({ children }: { children: React.ReactNode }) {
260
- const { user, isLoading } = useAuth();
261
- if (isLoading) return null;
262
- if (!user) return <Navigate to="${hasLogin ? '/login' : firstProtectedPath}" replace />;
263
- return <>{children}</>;
264
- }
265
-
266
- ${hasLogin ? `function GuestRoute({ children }: { children: React.ReactNode }) {
267
- const { user, isLoading } = useAuth();
268
- if (isLoading) return null;
269
- if (user) return <Navigate to="${firstProtectedPath}" replace />;
270
- return <>{children}</>;
271
- }
272
-
273
- function LoginPageWithAuth() {
274
- const { login } = useAuth();
275
- return <LoginPage onLogin={login} />;
276
- }` : ''}
277
-
278
- // ─── Route tree ───────────────────────────────────────────────────────────────
279
-
280
- export function AuthGuard() {
281
- const { user } = useAuth();
282
-
283
- return (
284
- <div className="min-h-screen bg-muted overflow-x-hidden max-w-full">
285
- <Routes>
286
- ${hasLogin ? ` <Route path="/login" element={<GuestRoute><LoginPageWithAuth /></GuestRoute>} />
287
- <Route path="/forgot-password" element={<GuestRoute><ForgotPasswordPage /></GuestRoute>} />
288
- <Route path="/verify-email" element={<GuestRoute><VerifyEmailPage /></GuestRoute>} />
289
- <Route path="/reset-password" element={<GuestRoute><ResetPasswordPage /></GuestRoute>} />` : ''}
290
-
291
- ${hasHome ? ` <Route path="/home" element={<ProtectedRoute><HomePage /></ProtectedRoute>} />` : ''}
292
- ${hasTemplate ? ` <Route path="/template" element={<ProtectedRoute><TemplatePage /></ProtectedRoute>} />` : ''}
293
- <Route path="/assistente" element={<ProtectedRoute><AssistantPage /></ProtectedRoute>} />
294
-
295
- <Route path="/" element={<Navigate to={user ? '${firstProtectedPath}' : '${hasLogin ? '/login' : firstProtectedPath}'} replace />} />
296
- <Route path="*" element={<Navigate to={user ? '${firstProtectedPath}' : '${hasLogin ? '/login' : firstProtectedPath}'} replace />} />
297
- </Routes>
298
- </div>
299
- );
300
- }
301
- `;
302
-
303
- await fs.writeFile(
304
- path.join(targetDir, 'src', 'app', 'components', 'AuthGuard.tsx'),
305
- authGuardContent
306
- );
307
-
308
- // 10. Generate theme tokens
309
- const selectedTheme = colorThemes.find(t => t.id === response.theme) || colorThemes[0];
310
- const tokensDir = path.join(targetDir, 'src', 'styles', 'xertica');
311
- await fs.ensureDir(tokensDir);
312
- await fs.copy(
313
- path.join(templatesDir, 'src', 'styles', 'index.css'),
314
- path.join(targetDir, 'src', 'styles', 'index.css')
315
- );
316
- await fs.writeFile(path.join(tokensDir, 'tokens.css'), generateTokensCss(selectedTheme));
317
-
318
- spinner.succeed('Project initialized successfully!');
319
-
320
- if (response.install) {
321
- const installSpinner = ora('Installing dependencies...').start();
322
- await execa('npm', ['install'], { cwd: targetDir });
323
- installSpinner.succeed('Dependencies installed!');
324
- }
325
-
326
- console.log(chalk.green('\n✅ Done! Your Xertica UI project is ready.'));
327
- console.log(chalk.cyan(`\n cd ${directory}`));
328
- if (!response.install) {
329
- console.log(chalk.cyan(' npm install'));
330
- }
331
- console.log(chalk.cyan(' npm run dev'));
332
- console.log();
333
- console.log(chalk.gray(' Components are imported from the xertica-ui package.'));
334
- console.log(chalk.gray(' Customize the theme in src/styles/xertica/tokens.css'));
335
- const langLabels = SUPPORTED_LANGUAGES.filter(l => selectedLanguages.includes(l.code))
336
- .map(l => l.label)
337
- .join(', ');
338
- console.log(
339
- chalk.gray(
340
- ` Languages: ${langLabels}${selectedLanguages.length === 1 ? ' (monolingual — LanguageSelector hidden)' : ''}`
341
- )
342
- );
343
- console.log(
344
- chalk.gray(' To add/remove languages later: npx xertica-ui update → Languages')
345
- );
346
- } catch (error) {
347
- spinner.fail('Failed to initialize project');
348
- console.error(error);
349
- }
350
- });
351
-
352
- program
353
- .command('update')
354
- .alias('update-theme')
355
- .description('Update theme or project files to the latest version')
356
- .action(async () => {
357
- const targetDir = process.cwd();
358
-
359
- const { updateType } = await prompts({
360
- type: 'select',
361
- name: 'updateType',
362
- message: 'What do you want to update?',
363
- choices: [
364
- {
365
- title: 'Theme only',
366
- description: 'Change the color tokens (tokens.css)',
367
- value: 'theme',
368
- },
369
- {
370
- title: 'Languages',
371
- description: 'Add or remove supported languages (pt-BR, en, es, …)',
372
- value: 'languages',
373
- },
374
- {
375
- title: 'Project files',
376
- description: 'Update app shell, shared, features and pages to a specific version',
377
- value: 'project',
378
- },
379
- ],
380
- });
381
-
382
- if (!updateType) return;
383
-
384
- // ── Theme update ─────────────────────────────────────────────────────────
385
- if (updateType === 'theme') {
386
- const { theme } = await prompts({
387
- type: 'select',
388
- name: 'theme',
389
- message: 'Select the new color theme:',
390
- choices: colorThemes.map(t => ({
391
- title: t.name,
392
- description: t.description,
393
- value: t.id,
394
- })),
395
- initial: 0,
396
- });
397
-
398
- if (!theme) return;
399
-
400
- const spinner = ora('Updating theme...').start();
401
- try {
402
- const tokensPath = path.join(targetDir, 'src', 'styles', 'xertica', 'tokens.css');
403
- const selectedTheme = colorThemes.find(t => t.id === theme);
404
- if (selectedTheme) {
405
- await fs.ensureDir(path.dirname(tokensPath));
406
- await fs.writeFile(tokensPath, generateTokensCss(selectedTheme));
407
- spinner.succeed(`Theme updated to "${selectedTheme.name}" successfully!`);
408
- } else {
409
- spinner.fail('Theme not found.');
410
- }
411
- } catch (error) {
412
- spinner.fail('Failed to update theme');
413
- console.error(error);
414
- }
415
- return;
416
- }
417
-
418
- // ── Languages update (add / remove) ──────────────────────────────────────
419
- if (updateType === 'languages') {
420
- // Resolve current selection — read from .languages.json if present,
421
- // else inspect the locales/ folder to infer it (for projects scaffolded
422
- // before this feature shipped).
423
- const persistedCodes = await readLanguagesConfig(targetDir);
424
- let currentCodes: string[] = persistedCodes ?? [];
425
- if (currentCodes.length === 0) {
426
- const localesDir = path.join(targetDir, 'src', 'locales');
427
- if (await fs.pathExists(localesDir)) {
428
- const entries = await fs.readdir(localesDir);
429
- // Accept both the new folder layout (locales/<code>/) and the legacy
430
- // flat layout (locales/<code>.json) when inferring the current set.
431
- currentCodes = SUPPORTED_LANGUAGES.filter(
432
- l => entries.includes(l.jsonFile) || entries.includes(`${l.jsonFile}.json`)
433
- ).map(l => l.code);
434
- }
435
- if (currentCodes.length === 0) currentCodes = DEFAULT_SELECTION;
436
- }
437
-
438
- console.log(
439
- chalk.cyan(
440
- `\nCurrent languages: ${SUPPORTED_LANGUAGES.filter(l => currentCodes.includes(l.code))
441
- .map(l => l.label)
442
- .join(', ') || '(none)'}\n`
443
- )
444
- );
445
-
446
- const { newCodes } = await prompts({
447
- type: 'multiselect',
448
- name: 'newCodes',
449
- message: 'Select the languages this project should support:',
450
- instructions: false,
451
- hint: 'Press SPACE to toggle. At least 1 required. Single-language apps auto-hide the LanguageSelector.',
452
- min: 1,
453
- choices: SUPPORTED_LANGUAGES.map(l => ({
454
- title: l.label,
455
- value: l.code,
456
- selected: currentCodes.includes(l.code),
457
- })),
458
- });
459
-
460
- if (!Array.isArray(newCodes) || newCodes.length === 0) {
461
- console.log(chalk.gray('Update cancelled.'));
462
- return;
463
- }
464
-
465
- // Compute add/remove diff for the user-facing summary
466
- const toAdd = newCodes.filter((c: string) => !currentCodes.includes(c));
467
- const toRemove = currentCodes.filter(c => !newCodes.includes(c));
468
-
469
- if (toAdd.length === 0 && toRemove.length === 0) {
470
- console.log(chalk.gray('No changes — selection matches the current set.'));
471
- return;
472
- }
473
-
474
- const summary: string[] = [];
475
- if (toAdd.length > 0)
476
- summary.push(chalk.green(` + ${toAdd.join(', ')}`));
477
- if (toRemove.length > 0)
478
- summary.push(chalk.red(` - ${toRemove.join(', ')}`));
479
- console.log(`\n${summary.join('\n')}\n`);
480
-
481
- const { confirmed } = await prompts({
482
- type: 'confirm',
483
- name: 'confirmed',
484
- message: chalk.yellow(
485
- `⚠️ This will regenerate src/app/App.tsx and src/i18n.ts (preserving language-only changes). Continue?`
486
- ),
487
- initial: true,
488
- });
489
- if (!confirmed) {
490
- console.log(chalk.gray('Update cancelled.'));
491
- return;
492
- }
493
-
494
- const spinner = ora('Updating languages...').start();
495
- try {
496
- // The freshly-installed library may not be present in this flow, so we
497
- // read locale JSON sources from `node_modules/xertica-ui/templates`
498
- // (installed when the project was created) — fallback to package
499
- // directory lookup.
500
- const installedTemplatesDir = path.join(
501
- targetDir,
502
- 'node_modules',
503
- 'xertica-ui',
504
- 'templates'
505
- );
506
- const templatesSourceDir = (await fs.pathExists(installedTemplatesDir))
507
- ? installedTemplatesDir
508
- : path.resolve(__dirname, '../templates');
509
-
510
- // 1) Sync locale JSON files: copy newly-added, prune removed
511
- const { copied, removed } = await syncLocaleFiles(
512
- templatesSourceDir,
513
- targetDir,
514
- newCodes,
515
- { pruneOthers: true }
516
- );
517
-
518
- // 2) Regenerate i18n.ts so imports/resources reflect the new set
519
- await fs.writeFile(
520
- path.join(targetDir, 'src', 'i18n.ts'),
521
- generateI18nFile(newCodes)
522
- );
523
-
524
- // 3) Regenerate App.tsx so the `availableLanguages` prop matches
525
- await fs.writeFile(
526
- path.join(targetDir, 'src', 'app', 'App.tsx'),
527
- generateAppTsx(newCodes)
528
- );
529
-
530
- // 4) Persist the new selection
531
- await writeLanguagesConfig(targetDir, newCodes);
532
-
533
- spinner.succeed('Languages updated successfully!');
534
-
535
- if (copied.length > 0) console.log(chalk.green(` Copied: ${copied.join(', ')}`));
536
- if (removed.length > 0) console.log(chalk.red(` Removed: ${removed.join(', ')}`));
537
- if (newCodes.length === 1) {
538
- console.log(
539
- chalk.gray(
540
- ` Project is now monolingual — the LanguageSelector will auto-hide.`
541
- )
542
- );
543
- }
544
- } catch (error) {
545
- spinner.fail('Failed to update languages');
546
- console.error(error);
547
- }
548
- return;
549
- }
550
-
551
- // ── Project files update ──────────────────────────────────────────────────
552
- const { versionType } = await prompts({
553
- type: 'select',
554
- name: 'versionType',
555
- message: 'Which version do you want to update to?',
556
- choices: [
557
- { title: 'Latest', description: 'Install the latest published version', value: 'latest' },
558
- {
559
- title: 'Specific version',
560
- description: 'Enter a version number (e.g. 2.0.2)',
561
- value: 'specific',
562
- },
563
- ],
564
- });
565
-
566
- if (!versionType) return;
567
-
568
- let targetVersion = 'latest';
569
- if (versionType === 'specific') {
570
- const { version } = await prompts({
571
- type: 'text',
572
- name: 'version',
573
- message: 'Enter the version (e.g. 2.0.2):',
574
- validate: v =>
575
- /^\d+\.\d+\.\d+/.test(v.trim()) ? true : 'Enter a valid semver (e.g. 2.0.2)',
576
- });
577
- if (!version) return;
578
- targetVersion = version.trim();
579
- }
580
-
581
- const { filesToUpdate } = await prompts({
582
- type: 'multiselect',
583
- name: 'filesToUpdate',
584
- message: 'Select which parts of the project to update:',
585
- choices: [
586
- {
587
- title: 'App shell (src/app/)',
588
- description: 'App.tsx, AppLayout.tsx',
589
- value: 'app',
590
- selected: true,
591
- },
592
- {
593
- title: 'Shared utilities (src/shared/)',
594
- description: 'auth.ts, navigation.ts, types',
595
- value: 'shared',
596
- selected: true,
597
- },
598
- {
599
- title: 'Features (src/features/)',
600
- description: 'auth, home, template UI components',
601
- value: 'features',
602
- selected: true,
603
- },
604
- {
605
- title: 'Pages (src/pages/)',
606
- description: 'Thin page wrapper components',
607
- value: 'pages',
608
- selected: true,
609
- },
610
- {
611
- title: 'Root config files',
612
- description: 'vite.config.ts, tsconfig.json, etc.',
613
- value: 'config',
614
- selected: false,
615
- },
616
- ],
617
- });
618
-
619
- if (!filesToUpdate || filesToUpdate.length === 0) return;
620
-
621
- const { confirmed } = await prompts({
622
- type: 'confirm',
623
- name: 'confirmed',
624
- message: chalk.yellow(
625
- `⚠️ This will overwrite the selected files. Local changes will be lost. Continue?`
626
- ),
627
- initial: false,
628
- });
629
-
630
- if (!confirmed) {
631
- console.log(chalk.gray('Update cancelled.'));
632
- return;
633
- }
634
-
635
- const spinner = ora(`Installing xertica-ui@${targetVersion}...`).start();
636
-
637
- try {
638
- // Install the target version in the consumer project
639
- await execa('npm', ['install', `xertica-ui@${targetVersion}`], { cwd: targetDir });
640
- spinner.text = 'Copying updated files...';
641
-
642
- // Templates now come from the freshly installed version
643
- const updatedTemplatesDir = path.join(targetDir, 'node_modules', 'xertica-ui', 'templates');
644
-
645
- if (filesToUpdate.includes('app')) {
646
- // AppLayout is always safe to overwrite (no per-project config baked in)
647
- await fs.copy(
648
- path.join(updatedTemplatesDir, 'src', 'app', 'components', 'AppLayout.tsx'),
649
- path.join(targetDir, 'src', 'app', 'components', 'AppLayout.tsx'),
650
- { overwrite: true }
651
- );
652
-
653
- // For App.tsx and i18n.ts we must preserve the user's language selection.
654
- // Read it from .languages.json (or fall back to inspecting locales/ for
655
- // projects scaffolded before the file existed).
656
- const persistedCodes = await readLanguagesConfig(targetDir);
657
- let selectedCodes: string[] = persistedCodes ?? [];
658
- if (selectedCodes.length === 0) {
659
- const localesDir = path.join(targetDir, 'src', 'locales');
660
- if (await fs.pathExists(localesDir)) {
661
- const entries = await fs.readdir(localesDir);
662
- // Accept both the new folder layout and the legacy flat layout
663
- selectedCodes = SUPPORTED_LANGUAGES.filter(
664
- l => entries.includes(l.jsonFile) || entries.includes(`${l.jsonFile}.json`)
665
- ).map(l => l.code);
666
- }
667
- if (selectedCodes.length === 0) selectedCodes = DEFAULT_SELECTION;
668
- // Persist the inferred selection so future updates have it cached
669
- await writeLanguagesConfig(targetDir, selectedCodes);
670
- }
671
-
672
- // Regenerate App.tsx and i18n.ts honoring the persisted language set
673
- await fs.writeFile(
674
- path.join(targetDir, 'src', 'app', 'App.tsx'),
675
- generateAppTsx(selectedCodes)
676
- );
677
- await fs.writeFile(
678
- path.join(targetDir, 'src', 'i18n.ts'),
679
- generateI18nFile(selectedCodes)
680
- );
681
-
682
- // Refresh locale JSON files for the selected languages (keys grow over
683
- // library updates) — but prune any orphans from prior selections.
684
- await syncLocaleFiles(updatedTemplatesDir, targetDir, selectedCodes, {
685
- pruneOthers: true,
686
- });
687
- }
688
-
689
- if (filesToUpdate.includes('shared')) {
690
- await fs.copy(
691
- path.join(updatedTemplatesDir, 'src', 'shared'),
692
- path.join(targetDir, 'src', 'shared'),
693
- { overwrite: true }
694
- );
695
- }
696
-
697
- if (filesToUpdate.includes('features')) {
698
- // Only update feature directories that already exist in the project.
699
- // 'assistant' is always included because AppLayout depends on it.
700
- for (const feature of ['auth', 'home', 'template', 'assistant']) {
701
- const destFeature = path.join(targetDir, 'src', 'features', feature);
702
- const srcFeature = path.join(updatedTemplatesDir, 'src', 'features', feature);
703
- if ((await fs.pathExists(destFeature)) && (await fs.pathExists(srcFeature))) {
704
- await fs.copy(srcFeature, destFeature, { overwrite: true });
705
- }
706
- }
707
- }
708
-
709
- if (filesToUpdate.includes('pages')) {
710
- const pagesDir = path.join(targetDir, 'src', 'pages');
711
- const srcPagesDir = path.join(updatedTemplatesDir, 'src', 'pages');
712
- if ((await fs.pathExists(pagesDir)) && (await fs.pathExists(srcPagesDir))) {
713
- // Only overwrite pages that already exist in the project
714
- const existingPages = await fs.readdir(pagesDir);
715
- for (const pageFile of existingPages) {
716
- const src = path.join(srcPagesDir, pageFile);
717
- if (await fs.pathExists(src)) {
718
- await fs.copy(src, path.join(pagesDir, pageFile), { overwrite: true });
719
- }
720
- }
721
- }
722
- }
723
-
724
- if (filesToUpdate.includes('config')) {
725
- // Config files are inside the templates/ directory (same level as src/)
726
- const configFiles = [
727
- 'vite.config.ts',
728
- 'tsconfig.json',
729
- 'tsconfig.node.json',
730
- 'postcss.config.js',
731
- ];
732
- for (const file of configFiles) {
733
- const src = path.join(updatedTemplatesDir, file);
734
- if (await fs.pathExists(src)) {
735
- await fs.copy(src, path.join(targetDir, file), { overwrite: true });
736
- }
737
- }
738
- }
739
-
740
- spinner.succeed(`Project updated to xertica-ui@${targetVersion} successfully!`);
741
- console.log(chalk.gray('\n Run npm run dev to start the development server.'));
742
- } catch (error) {
743
- spinner.fail('Failed to update project');
744
- console.error(error);
745
- }
746
- });
747
-
748
- program.parse();
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import prompts from 'prompts';
4
+ import chalk from 'chalk';
5
+ import ora from 'ora';
6
+ import fs from 'fs-extra';
7
+ import path from 'path';
8
+ import { fileURLToPath } from 'url';
9
+ import { execa } from 'execa';
10
+ import { colorThemes } from '../contexts/theme-data';
11
+ import { generateTokensCss } from './generate-tokens';
12
+ import {
13
+ SUPPORTED_LANGUAGES,
14
+ DEFAULT_SELECTION,
15
+ readLanguagesConfig,
16
+ writeLanguagesConfig,
17
+ syncLocaleFiles,
18
+ generateI18nFile,
19
+ generateAppTsx,
20
+ } from './language-config';
21
+
22
+ // ─────────────────────────────────────────────────────────────────────────────
23
+ // Project config helpers (.xertica.json)
24
+ // Persists per-project feature flags so `update` can read them later.
25
+ // ─────────────────────────────────────────────────────────────────────────────
26
+
27
+ const XERTICA_CONFIG_FILE = '.xertica.json';
28
+
29
+ interface XerticaConfig {
30
+ version: 1;
31
+ hasAssistant: boolean;
32
+ disableDarkMode?: boolean;
33
+ }
34
+
35
+ async function readXerticaConfig(targetDir: string): Promise<XerticaConfig | null> {
36
+ const configPath = path.join(targetDir, XERTICA_CONFIG_FILE);
37
+ if (!(await fs.pathExists(configPath))) return null;
38
+ try {
39
+ return (await fs.readJson(configPath)) as XerticaConfig;
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+
45
+ async function writeXerticaConfig(
46
+ targetDir: string,
47
+ config: Partial<XerticaConfig>
48
+ ): Promise<void> {
49
+ const configPath = path.join(targetDir, XERTICA_CONFIG_FILE);
50
+ const existing = (await readXerticaConfig(targetDir)) ?? {
51
+ version: 1 as const,
52
+ hasAssistant: false,
53
+ };
54
+ await fs.writeJson(configPath, { ...existing, ...config, version: 1 }, { spaces: 2 });
55
+ }
56
+
57
+ const __filename = fileURLToPath(import.meta.url);
58
+ const __dirname = path.dirname(__filename);
59
+
60
+ // Read CLI version from package.json so it always matches the published one,
61
+ // instead of hardcoding a literal that drifts on every version bump.
62
+ const pkgJson = JSON.parse(
63
+ fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf-8')
64
+ ) as { version: string };
65
+
66
+ // ─────────────────────────────────────────────────────────────────────────────
67
+ // AuthGuard generator
68
+ // Generates src/app/components/AuthGuard.tsx based on the selected features.
69
+ // ─────────────────────────────────────────────────────────────────────────────
70
+
71
+ function generateAuthGuard({
72
+ hasLogin,
73
+ hasHome,
74
+ hasTemplate,
75
+ hasAssistant,
76
+ firstProtectedPath,
77
+ }: {
78
+ hasLogin: boolean;
79
+ hasHome: boolean;
80
+ hasTemplate: boolean;
81
+ hasAssistant: boolean;
82
+ firstProtectedPath: string;
83
+ }): string {
84
+ return `import React from 'react';
85
+ import { Routes, Route, Navigate } from 'react-router-dom';
86
+ import { useAuth } from '../context/AuthContext';
87
+
88
+ // ─── Lazy page imports ────────────────────────────────────────────────────────
89
+
90
+ ${
91
+ hasLogin
92
+ ? `const LoginPage = React.lazy(() => import('../../pages/LoginPage').then(m => ({ default: m.LoginPage })));
93
+ const ForgotPasswordPage = React.lazy(() => import('../../pages/ForgotPasswordPage').then(m => ({ default: m.ForgotPasswordPage })));
94
+ const VerifyEmailPage = React.lazy(() => import('../../pages/VerifyEmailPage').then(m => ({ default: m.VerifyEmailPage })));
95
+ const ResetPasswordPage = React.lazy(() => import('../../pages/ResetPasswordPage').then(m => ({ default: m.ResetPasswordPage })));`
96
+ : ''
97
+ }
98
+
99
+ ${hasHome ? `const HomePage = React.lazy(() => import('../../pages/HomePage').then(m => ({ default: m.HomePage })));` : ''}
100
+ ${hasTemplate ? `const TemplatePage = React.lazy(() => import('../../pages/TemplatePage').then(m => ({ default: m.TemplatePage })));` : ''}
101
+ ${hasAssistant ? `const AssistantPage = React.lazy(() => import('../../pages/AssistantPage').then(m => ({ default: m.AssistantPage })));` : ''}
102
+
103
+ // ─── Route guards ─────────────────────────────────────────────────────────────
104
+
105
+ function ProtectedRoute({ children }: { children: React.ReactNode }) {
106
+ const { user, isLoading } = useAuth();
107
+ if (isLoading) return null;
108
+ if (!user) return <Navigate to="${hasLogin ? '/login' : firstProtectedPath}" replace />;
109
+ return <>{children}</>;
110
+ }
111
+
112
+ ${
113
+ hasLogin
114
+ ? `function GuestRoute({ children }: { children: React.ReactNode }) {
115
+ const { user, isLoading } = useAuth();
116
+ if (isLoading) return null;
117
+ if (user) return <Navigate to="${firstProtectedPath}" replace />;
118
+ return <>{children}</>;
119
+ }
120
+
121
+ function LoginPageWithAuth() {
122
+ const { login } = useAuth();
123
+ return <LoginPage onLogin={login} />;
124
+ }`
125
+ : ''
126
+ }
127
+
128
+ // ─── Route tree ───────────────────────────────────────────────────────────────
129
+
130
+ export function AuthGuard() {
131
+ const { user } = useAuth();
132
+
133
+ return (
134
+ <div className="min-h-screen bg-muted overflow-x-hidden max-w-full">
135
+ <Routes>
136
+ ${
137
+ hasLogin
138
+ ? ` <Route path="/login" element={<GuestRoute><LoginPageWithAuth /></GuestRoute>} />
139
+ <Route path="/forgot-password" element={<GuestRoute><ForgotPasswordPage /></GuestRoute>} />
140
+ <Route path="/verify-email" element={<GuestRoute><VerifyEmailPage /></GuestRoute>} />
141
+ <Route path="/reset-password" element={<GuestRoute><ResetPasswordPage /></GuestRoute>} />`
142
+ : ''
143
+ }
144
+
145
+ ${hasHome ? ` <Route path="/home" element={<ProtectedRoute><HomePage /></ProtectedRoute>} />` : ''}
146
+ ${hasTemplate ? ` <Route path="/template" element={<ProtectedRoute><TemplatePage /></ProtectedRoute>} />` : ''}
147
+ ${hasAssistant ? ` <Route path="/assistente" element={<ProtectedRoute><AssistantPage /></ProtectedRoute>} />` : ''}
148
+
149
+ <Route path="/" element={<Navigate to={user ? '${firstProtectedPath}' : '${hasLogin ? '/login' : firstProtectedPath}'} replace />} />
150
+ <Route path="*" element={<Navigate to={user ? '${firstProtectedPath}' : '${hasLogin ? '/login' : firstProtectedPath}'} replace />} />
151
+ </Routes>
152
+ </div>
153
+ );
154
+ }
155
+ `;
156
+ }
157
+
158
+ // ─────────────────────────────────────────────────────────────────────────────
159
+ // Page generators
160
+ // Generate page files that vary based on whether the assistant is included.
161
+ // ─────────────────────────────────────────────────────────────────────────────
162
+
163
+ function generateHomePage(hasAssistant: boolean): string {
164
+ if (hasAssistant) {
165
+ return `import React from 'react';
166
+ import { XerticaAssistant, generateDemoResponse } from 'xertica-ui/assistant';
167
+ import { useLayout } from 'xertica-ui/hooks';
168
+ import { useNavigate } from 'react-router-dom';
169
+ import { AppLayout } from '../app/components/AppLayout';
170
+ import { HomeContent } from '../features/home';
171
+ import { useAssistantConfig, getMockRichSuggestions, getMockFeedbackOptions } from '../features/assistant';
172
+
173
+ /**
174
+ * Home page — thin layout shell.
175
+ *
176
+ * Assistant config (suggestions, feedback options) is fetched via React Query.
177
+ * To connect to a real API replace \`fetchAssistantConfig\` in
178
+ * \`features/assistant/data/mock.ts\`.
179
+ */
180
+ export function HomePage() {
181
+ const { assistenteExpanded, toggleAssistente } = useLayout();
182
+ const navigate = useNavigate();
183
+
184
+ const { data: assistantConfig } = useAssistantConfig();
185
+
186
+ return (
187
+ <AppLayout
188
+ assistant={
189
+ <XerticaAssistant
190
+ isExpanded={assistenteExpanded}
191
+ onToggle={toggleAssistente}
192
+ defaultTab="chat"
193
+ demoMode={true}
194
+ userName="Ariel Santos"
195
+ responseGenerator={generateDemoResponse}
196
+ suggestions={assistantConfig?.suggestions}
197
+ richSuggestions={assistantConfig?.richSuggestions ?? getMockRichSuggestions()}
198
+ feedbackOptions={assistantConfig?.feedbackOptions ?? getMockFeedbackOptions()}
199
+ showHistory={false}
200
+ showFavorites={false}
201
+ onNavigateSettings={() => navigate('/settings')}
202
+ onNavigateFullPage={() => navigate('/assistente')}
203
+ onEvaluation={(messageId, type, reason) => {
204
+ // Wire your feedback persistence logic here
205
+ console.log(\`Avaliação: \${type} na mensagem \${messageId}. Motivo: \${reason}\`);
206
+ }}
207
+ />
208
+ }
209
+ >
210
+ <HomeContent />
211
+ </AppLayout>
212
+ );
213
+ }
214
+ `;
215
+ }
216
+
217
+ return `import React from 'react';
218
+ import { AppLayout } from '../app/components/AppLayout';
219
+ import { HomeContent } from '../features/home';
220
+
221
+ /**
222
+ * Home page — thin layout shell.
223
+ */
224
+ export function HomePage() {
225
+ return (
226
+ <AppLayout>
227
+ <HomeContent />
228
+ </AppLayout>
229
+ );
230
+ }
231
+ `;
232
+ }
233
+
234
+ function generateTemplatePage(hasAssistant: boolean): string {
235
+ if (hasAssistant) {
236
+ return `import React from 'react';
237
+ import { XerticaAssistant } from 'xertica-ui/assistant';
238
+ import { useLayout } from 'xertica-ui/hooks';
239
+ import { AppLayout } from '../app/components/AppLayout';
240
+ import { TemplateContent } from '../features/template';
241
+
242
+ /**
243
+ * Template page thin layout shell.
244
+ *
245
+ * Auth state is consumed from \`AuthContext\` via \`AppLayout\` — no props needed.
246
+ */
247
+ export function TemplatePage() {
248
+ const { assistenteExpanded, toggleAssistente } = useLayout();
249
+
250
+ return (
251
+ <AppLayout
252
+ assistant={
253
+ <XerticaAssistant
254
+ isExpanded={assistenteExpanded}
255
+ onToggle={toggleAssistente}
256
+ onEvaluation={(id, type, reason) => console.log('Feedback:', id, type, reason)}
257
+ />
258
+ }
259
+ >
260
+ <TemplateContent />
261
+ </AppLayout>
262
+ );
263
+ }
264
+ `;
265
+ }
266
+
267
+ return `import React from 'react';
268
+ import { AppLayout } from '../app/components/AppLayout';
269
+ import { TemplateContent } from '../features/template';
270
+
271
+ /**
272
+ * Template page — thin layout shell.
273
+ *
274
+ * Auth state is consumed from \`AuthContext\` via \`AppLayout\` — no props needed.
275
+ */
276
+ export function TemplatePage() {
277
+ return (
278
+ <AppLayout>
279
+ <TemplateContent />
280
+ </AppLayout>
281
+ );
282
+ }
283
+ `;
284
+ }
285
+
286
+ const program = new Command();
287
+
288
+ program
289
+ .name('xertica-ui')
290
+ .description('CLI to initialize Xertica UI projects')
291
+ .version(pkgJson.version);
292
+
293
+ program
294
+ .command('init')
295
+ .description('Initialize a new Xertica UI project')
296
+ .argument('[directory]', 'Directory to initialize in', '.')
297
+ .action(async directory => {
298
+ const targetDir = path.resolve(process.cwd(), directory);
299
+ const templatesDir = path.resolve(__dirname, '../templates');
300
+
301
+ console.log(chalk.blue(`🚀 Welcome to Xertica UI CLI! ${chalk.dim(`v${pkgJson.version}`)}`));
302
+
303
+ const response = await prompts([
304
+ {
305
+ type: 'multiselect',
306
+ name: 'pages',
307
+ message: 'Which pages/templates to include?',
308
+ choices: [
309
+ {
310
+ title: 'Login Page (+ Forgot / Verify / Reset Password)',
311
+ value: 'login',
312
+ selected: true,
313
+ },
314
+ { title: 'Home Page', value: 'home', selected: true },
315
+ { title: 'Template Page (components showcase)', value: 'template', selected: true },
316
+ ],
317
+ },
318
+ {
319
+ type: 'multiselect',
320
+ name: 'languages',
321
+ message: 'Which languages should the app support?',
322
+ instructions: false,
323
+ hint: 'Select at least 1. Single-language apps auto-hide the LanguageSelector.',
324
+ min: 1,
325
+ choices: SUPPORTED_LANGUAGES.map(l => ({
326
+ title: l.label,
327
+ value: l.code,
328
+ selected: true,
329
+ })),
330
+ },
331
+ {
332
+ type: 'select',
333
+ name: 'theme',
334
+ message: 'Select the default color theme for your project:',
335
+ choices: colorThemes.map(t => ({
336
+ title: t.name,
337
+ description: t.description,
338
+ value: t.id,
339
+ })),
340
+ initial: 0,
341
+ },
342
+ {
343
+ type: 'confirm',
344
+ name: 'hasAssistant',
345
+ message: 'Include AI Assistant? (XerticaAssistant chat page + sidebar variant)',
346
+ initial: true,
347
+ },
348
+ {
349
+ type: 'confirm',
350
+ name: 'enableDarkMode',
351
+ message: 'Enable dark mode support?',
352
+ initial: true,
353
+ },
354
+ {
355
+ type: 'confirm',
356
+ name: 'install',
357
+ message: 'Install dependencies automatically?',
358
+ initial: true,
359
+ },
360
+ ]);
361
+
362
+ // Abort if the user cancelled any prompt (prompts returns undefined on Ctrl+C)
363
+ if (!response.pages || !response.languages || !response.theme) return;
364
+
365
+ const spinner = ora('Initializing project...').start();
366
+
367
+ try {
368
+ await fs.ensureDir(targetDir);
369
+
370
+ const pages = response.pages || [];
371
+ const hasLogin = pages.includes('login');
372
+ const hasHome = pages.includes('home');
373
+ const hasTemplate = pages.includes('template');
374
+ const hasAssistant = response.hasAssistant ?? true;
375
+
376
+ // Resolve selected languages fall back to all defaults if the user
377
+ // somehow ended up with an empty array (the prompt's min:1 should prevent
378
+ // this, but we defend defensively).
379
+ const selectedLanguages: string[] =
380
+ Array.isArray(response.languages) && response.languages.length > 0
381
+ ? response.languages
382
+ : DEFAULT_SELECTION;
383
+
384
+ // 1. Copy root config files
385
+ const rootFilesToCopy = [
386
+ 'index.html',
387
+ 'vite.config.ts',
388
+ 'tsconfig.json',
389
+ 'tsconfig.node.json',
390
+ 'postcss.config.js',
391
+ 'vite-env.d.ts',
392
+ 'eslint.config.js',
393
+ '.env.example',
394
+ 'guidelines',
395
+ 'CLAUDE.md',
396
+ ];
397
+
398
+ for (const file of rootFilesToCopy) {
399
+ const srcPath = path.join(templatesDir, file);
400
+ if (await fs.pathExists(srcPath)) {
401
+ await fs.copy(srcPath, path.join(targetDir, file));
402
+ }
403
+ }
404
+
405
+ // 2. Copy package.json
406
+ const pkgTemplatePath = path.join(templatesDir, 'package.json');
407
+ if (await fs.pathExists(pkgTemplatePath)) {
408
+ const pkgContent = await fs.readJson(pkgTemplatePath);
409
+ const projectName = path.basename(targetDir) || 'my-xertica-app';
410
+ pkgContent.name = projectName.toLowerCase().replace(/[^a-z0-9-]/g, '-');
411
+ await fs.writeJson(path.join(targetDir, 'package.json'), pkgContent, { spaces: 2 });
412
+ }
413
+
414
+ // 3. Copy src/main.tsx
415
+ await fs.copy(
416
+ path.join(templatesDir, 'src', 'main.tsx'),
417
+ path.join(targetDir, 'src', 'main.tsx')
418
+ );
419
+
420
+ const disableDarkMode = response.enableDarkMode === false;
421
+
422
+ // 4. Generate src/app/App.tsx with the user's language selection
423
+ // (instead of copying the static template, we inject `availableLanguages`)
424
+ await fs.ensureDir(path.join(targetDir, 'src', 'app'));
425
+ await fs.writeFile(
426
+ path.join(targetDir, 'src', 'app', 'App.tsx'),
427
+ generateAppTsx(selectedLanguages, disableDarkMode)
428
+ );
429
+
430
+ // 5. Copy src/app/components/AppLayout.tsx (always needed)
431
+ await fs.ensureDir(path.join(targetDir, 'src', 'app', 'components'));
432
+ await fs.copy(
433
+ path.join(templatesDir, 'src', 'app', 'components', 'AppLayout.tsx'),
434
+ path.join(targetDir, 'src', 'app', 'components', 'AppLayout.tsx')
435
+ );
436
+
437
+ // 6. Copy src/shared/ (always needed — auth helpers, navigation config, types)
438
+ await fs.copy(
439
+ path.join(templatesDir, 'src', 'shared'),
440
+ path.join(targetDir, 'src', 'shared')
441
+ );
442
+
443
+ // 6.1 Generate i18n.ts with only the imports/resources for selected languages
444
+ await fs.writeFile(
445
+ path.join(targetDir, 'src', 'i18n.ts'),
446
+ generateI18nFile(selectedLanguages)
447
+ );
448
+
449
+ // 6.2 Copy only the selected locale JSON files (no orphan locales)
450
+ await syncLocaleFiles(templatesDir, targetDir, selectedLanguages, { pruneOthers: true });
451
+
452
+ // 6.3 Persist the language selection so `update` can remember it
453
+ await writeLanguagesConfig(targetDir, selectedLanguages);
454
+
455
+ // 6.5 Persist project feature flags (.xertica.json)
456
+ await writeXerticaConfig(targetDir, { hasAssistant, disableDarkMode });
457
+
458
+ // 6.4 Copy context
459
+ await fs.ensureDir(path.join(targetDir, 'src', 'app', 'context'));
460
+ await fs.copy(
461
+ path.join(templatesDir, 'src', 'app', 'context', 'AuthContext.tsx'),
462
+ path.join(targetDir, 'src', 'app', 'context', 'AuthContext.tsx')
463
+ );
464
+
465
+ // 7. Copy features based on selections
466
+ if (hasLogin) {
467
+ await fs.copy(
468
+ path.join(templatesDir, 'src', 'features', 'auth'),
469
+ path.join(targetDir, 'src', 'features', 'auth')
470
+ );
471
+ }
472
+ if (hasHome) {
473
+ await fs.copy(
474
+ path.join(templatesDir, 'src', 'features', 'home'),
475
+ path.join(targetDir, 'src', 'features', 'home')
476
+ );
477
+ }
478
+ if (hasTemplate) {
479
+ await fs.copy(
480
+ path.join(templatesDir, 'src', 'features', 'template'),
481
+ path.join(targetDir, 'src', 'features', 'template')
482
+ );
483
+ }
484
+ // Copy assistant feature only if selected
485
+ if (hasAssistant) {
486
+ await fs.copy(
487
+ path.join(templatesDir, 'src', 'features', 'assistant'),
488
+ path.join(targetDir, 'src', 'features', 'assistant')
489
+ );
490
+ }
491
+
492
+ // 8. Copy pages based on selections
493
+ await fs.ensureDir(path.join(targetDir, 'src', 'pages'));
494
+
495
+ const pagesToCopy: string[] = [];
496
+ if (hasLogin)
497
+ pagesToCopy.push(
498
+ 'LoginPage.tsx',
499
+ 'ForgotPasswordPage.tsx',
500
+ 'VerifyEmailPage.tsx',
501
+ 'ResetPasswordPage.tsx'
502
+ );
503
+ if (hasHome) pagesToCopy.push('HomePage.tsx');
504
+ if (hasTemplate) pagesToCopy.push('TemplatePage.tsx');
505
+ if (hasAssistant) pagesToCopy.push('AssistantPage.tsx');
506
+
507
+ for (const pageFile of pagesToCopy) {
508
+ // HomePage and TemplatePage are generated (they vary by hasAssistant)
509
+ if (pageFile === 'HomePage.tsx') {
510
+ await fs.writeFile(
511
+ path.join(targetDir, 'src', 'pages', 'HomePage.tsx'),
512
+ generateHomePage(hasAssistant)
513
+ );
514
+ continue;
515
+ }
516
+ if (pageFile === 'TemplatePage.tsx') {
517
+ await fs.writeFile(
518
+ path.join(targetDir, 'src', 'pages', 'TemplatePage.tsx'),
519
+ generateTemplatePage(hasAssistant)
520
+ );
521
+ continue;
522
+ }
523
+ const src = path.join(templatesDir, 'src', 'pages', pageFile);
524
+ if (await fs.pathExists(src)) {
525
+ await fs.copy(src, path.join(targetDir, 'src', 'pages', pageFile));
526
+ }
527
+ }
528
+
529
+ // 9. Generate AuthGuard.tsx based on selected pages
530
+ const firstProtectedPath = hasHome ? '/home' : hasTemplate ? '/template' : '/login';
531
+ const authGuardContent = generateAuthGuard({
532
+ hasLogin,
533
+ hasHome,
534
+ hasTemplate,
535
+ hasAssistant,
536
+ firstProtectedPath,
537
+ });
538
+
539
+ await fs.writeFile(
540
+ path.join(targetDir, 'src', 'app', 'components', 'AuthGuard.tsx'),
541
+ authGuardContent
542
+ );
543
+
544
+ // 10. Generate theme tokens
545
+ const selectedTheme = colorThemes.find(t => t.id === response.theme) || colorThemes[0];
546
+ const tokensDir = path.join(targetDir, 'src', 'styles', 'xertica');
547
+ await fs.ensureDir(tokensDir);
548
+ await fs.copy(
549
+ path.join(templatesDir, 'src', 'styles', 'index.css'),
550
+ path.join(targetDir, 'src', 'styles', 'index.css')
551
+ );
552
+ await fs.writeFile(path.join(tokensDir, 'tokens.css'), generateTokensCss(selectedTheme));
553
+
554
+ spinner.succeed('Project initialized successfully!');
555
+
556
+ if (response.install) {
557
+ const installSpinner = ora('Installing dependencies...').start();
558
+ await execa('npm', ['install'], { cwd: targetDir });
559
+ installSpinner.succeed('Dependencies installed!');
560
+ }
561
+
562
+ console.log(chalk.green('\n✅ Done! Your Xertica UI project is ready.'));
563
+ console.log(chalk.cyan(`\n cd ${directory}`));
564
+ if (!response.install) {
565
+ console.log(chalk.cyan(' npm install'));
566
+ }
567
+ console.log(chalk.cyan(' npm run dev'));
568
+ console.log();
569
+ console.log(chalk.gray(' Components are imported from the xertica-ui package.'));
570
+ console.log(chalk.gray(' Customize the theme in src/styles/xertica/tokens.css'));
571
+ const langLabels = SUPPORTED_LANGUAGES.filter(l => selectedLanguages.includes(l.code))
572
+ .map(l => l.label)
573
+ .join(', ');
574
+ console.log(
575
+ chalk.gray(
576
+ ` Languages: ${langLabels}${selectedLanguages.length === 1 ? ' (monolingual — LanguageSelector hidden)' : ''}`
577
+ )
578
+ );
579
+ console.log(chalk.gray(' To add/remove languages later: npx xertica-ui update → Languages'));
580
+ console.log(
581
+ chalk.gray(` AI Assistant: ${hasAssistant ? 'included (/assistente)' : 'not included'}`)
582
+ );
583
+ if (!hasAssistant) {
584
+ console.log(chalk.gray(' To add the assistant later: npx xertica-ui update → Assistant'));
585
+ }
586
+ } catch (error) {
587
+ spinner.fail('Failed to initialize project');
588
+ console.error(error);
589
+ }
590
+ });
591
+
592
+ program
593
+ .command('update')
594
+ .alias('update-theme')
595
+ .description('Update theme or project files to the latest version')
596
+ .action(async () => {
597
+ const targetDir = process.cwd();
598
+
599
+ console.log(chalk.blue(`🔧 Xertica UI CLI ${chalk.dim(`v${pkgJson.version}`)}`));
600
+
601
+ const currentConfig = await readXerticaConfig(targetDir);
602
+
603
+ const { updateType } = await prompts({
604
+ type: 'select',
605
+ name: 'updateType',
606
+ message: 'What do you want to update?',
607
+ choices: [
608
+ {
609
+ title: 'Theme only',
610
+ description: 'Change the color tokens (tokens.css)',
611
+ value: 'theme',
612
+ },
613
+ {
614
+ title: 'Languages',
615
+ description: 'Add or remove supported languages (pt-BR, en, es, …)',
616
+ value: 'languages',
617
+ },
618
+ {
619
+ title: 'Assistant',
620
+ description: currentConfig?.hasAssistant
621
+ ? 'Remove the AI Assistant from your project'
622
+ : 'Add the AI Assistant to your project',
623
+ value: 'assistant',
624
+ },
625
+ {
626
+ title: 'Dark Mode',
627
+ description: currentConfig?.disableDarkMode
628
+ ? 'Enable dark mode support in your project'
629
+ : 'Disable dark mode support in your project',
630
+ value: 'darkmode',
631
+ },
632
+ {
633
+ title: 'Project files',
634
+ description: 'Update app shell, shared, features and pages to a specific version',
635
+ value: 'project',
636
+ },
637
+ ],
638
+ });
639
+
640
+ if (!updateType) return;
641
+
642
+ // ── Theme update ─────────────────────────────────────────────────────────
643
+ if (updateType === 'theme') {
644
+ const { theme } = await prompts({
645
+ type: 'select',
646
+ name: 'theme',
647
+ message: 'Select the new color theme:',
648
+ choices: colorThemes.map(t => ({
649
+ title: t.name,
650
+ description: t.description,
651
+ value: t.id,
652
+ })),
653
+ initial: 0,
654
+ });
655
+
656
+ if (!theme) return;
657
+
658
+ const spinner = ora('Updating theme...').start();
659
+ try {
660
+ const tokensPath = path.join(targetDir, 'src', 'styles', 'xertica', 'tokens.css');
661
+ const selectedTheme = colorThemes.find(t => t.id === theme);
662
+ if (selectedTheme) {
663
+ await fs.ensureDir(path.dirname(tokensPath));
664
+ await fs.writeFile(tokensPath, generateTokensCss(selectedTheme));
665
+ spinner.succeed(`Theme updated to "${selectedTheme.name}" successfully!`);
666
+ } else {
667
+ spinner.fail('Theme not found.');
668
+ }
669
+ } catch (error) {
670
+ spinner.fail('Failed to update theme');
671
+ console.error(error);
672
+ }
673
+ return;
674
+ }
675
+
676
+ // ── Languages update (add / remove) ──────────────────────────────────────
677
+ if (updateType === 'languages') {
678
+ // Resolve current selection — read from .languages.json if present,
679
+ // else inspect the locales/ folder to infer it (for projects scaffolded
680
+ // before this feature shipped).
681
+ const persistedCodes = await readLanguagesConfig(targetDir);
682
+ let currentCodes: string[] = persistedCodes ?? [];
683
+ if (currentCodes.length === 0) {
684
+ const localesDir = path.join(targetDir, 'src', 'locales');
685
+ if (await fs.pathExists(localesDir)) {
686
+ const entries = await fs.readdir(localesDir);
687
+ // Accept both the new folder layout (locales/<code>/) and the legacy
688
+ // flat layout (locales/<code>.json) when inferring the current set.
689
+ currentCodes = SUPPORTED_LANGUAGES.filter(
690
+ l => entries.includes(l.jsonFile) || entries.includes(`${l.jsonFile}.json`)
691
+ ).map(l => l.code);
692
+ }
693
+ if (currentCodes.length === 0) currentCodes = DEFAULT_SELECTION;
694
+ }
695
+
696
+ console.log(
697
+ chalk.cyan(
698
+ `\nCurrent languages: ${
699
+ SUPPORTED_LANGUAGES.filter(l => currentCodes.includes(l.code))
700
+ .map(l => l.label)
701
+ .join(', ') || '(none)'
702
+ }\n`
703
+ )
704
+ );
705
+
706
+ const { newCodes } = await prompts({
707
+ type: 'multiselect',
708
+ name: 'newCodes',
709
+ message: 'Select the languages this project should support:',
710
+ instructions: false,
711
+ hint: 'Press SPACE to toggle. At least 1 required. Single-language apps auto-hide the LanguageSelector.',
712
+ min: 1,
713
+ choices: SUPPORTED_LANGUAGES.map(l => ({
714
+ title: l.label,
715
+ value: l.code,
716
+ selected: currentCodes.includes(l.code),
717
+ })),
718
+ });
719
+
720
+ if (!Array.isArray(newCodes) || newCodes.length === 0) {
721
+ console.log(chalk.gray('Update cancelled.'));
722
+ return;
723
+ }
724
+
725
+ // Compute add/remove diff for the user-facing summary
726
+ const toAdd = newCodes.filter((c: string) => !currentCodes.includes(c));
727
+ const toRemove = currentCodes.filter(c => !newCodes.includes(c));
728
+
729
+ if (toAdd.length === 0 && toRemove.length === 0) {
730
+ console.log(chalk.gray('No changes — selection matches the current set.'));
731
+ return;
732
+ }
733
+
734
+ const summary: string[] = [];
735
+ if (toAdd.length > 0) summary.push(chalk.green(` + ${toAdd.join(', ')}`));
736
+ if (toRemove.length > 0) summary.push(chalk.red(` - ${toRemove.join(', ')}`));
737
+ console.log(`\n${summary.join('\n')}\n`);
738
+
739
+ const { confirmed } = await prompts({
740
+ type: 'confirm',
741
+ name: 'confirmed',
742
+ message: chalk.yellow(
743
+ `⚠️ This will regenerate src/app/App.tsx and src/i18n.ts (preserving language-only changes). Continue?`
744
+ ),
745
+ initial: true,
746
+ });
747
+ if (!confirmed) {
748
+ console.log(chalk.gray('Update cancelled.'));
749
+ return;
750
+ }
751
+
752
+ const spinner = ora('Updating languages...').start();
753
+ try {
754
+ // The freshly-installed library may not be present in this flow, so we
755
+ // read locale JSON sources from `node_modules/xertica-ui/templates`
756
+ // (installed when the project was created) — fallback to package
757
+ // directory lookup.
758
+ const installedTemplatesDir = path.join(
759
+ targetDir,
760
+ 'node_modules',
761
+ 'xertica-ui',
762
+ 'templates'
763
+ );
764
+ const templatesSourceDir = (await fs.pathExists(installedTemplatesDir))
765
+ ? installedTemplatesDir
766
+ : path.resolve(__dirname, '../templates');
767
+
768
+ // 1) Sync locale JSON files: copy newly-added, prune removed
769
+ const { copied, removed } = await syncLocaleFiles(templatesSourceDir, targetDir, newCodes, {
770
+ pruneOthers: true,
771
+ });
772
+
773
+ // 2) Regenerate i18n.ts so imports/resources reflect the new set
774
+ await fs.writeFile(path.join(targetDir, 'src', 'i18n.ts'), generateI18nFile(newCodes));
775
+
776
+ // 3) Regenerate App.tsx so the `availableLanguages` prop matches
777
+ await fs.writeFile(
778
+ path.join(targetDir, 'src', 'app', 'App.tsx'),
779
+ generateAppTsx(newCodes, currentConfig?.disableDarkMode ?? false)
780
+ );
781
+
782
+ // 4) Persist the new selection
783
+ await writeLanguagesConfig(targetDir, newCodes);
784
+
785
+ spinner.succeed('Languages updated successfully!');
786
+
787
+ if (copied.length > 0) console.log(chalk.green(` Copied: ${copied.join(', ')}`));
788
+ if (removed.length > 0) console.log(chalk.red(` Removed: ${removed.join(', ')}`));
789
+ if (newCodes.length === 1) {
790
+ console.log(
791
+ chalk.gray(` Project is now monolingual — the LanguageSelector will auto-hide.`)
792
+ );
793
+ }
794
+ } catch (error) {
795
+ spinner.fail('Failed to update languages');
796
+ console.error(error);
797
+ }
798
+ return;
799
+ }
800
+
801
+ // ── Assistant add / remove ────────────────────────────────────────────────
802
+ if (updateType === 'assistant') {
803
+ // Determine current state: prefer persisted config, fall back to file presence
804
+ // (handles projects scaffolded before .xertica.json existed).
805
+ let currentlyHas: boolean;
806
+ if (currentConfig !== null) {
807
+ currentlyHas = currentConfig.hasAssistant;
808
+ } else {
809
+ const assistantFeatureDir = path.join(targetDir, 'src', 'features', 'assistant');
810
+ const assistantPage = path.join(targetDir, 'src', 'pages', 'AssistantPage.tsx');
811
+ currentlyHas =
812
+ (await fs.pathExists(assistantFeatureDir)) || (await fs.pathExists(assistantPage));
813
+ // Persist the inferred state so future runs don't need to infer again
814
+ await writeXerticaConfig(targetDir, { hasAssistant: currentlyHas });
815
+ }
816
+
817
+ console.log(
818
+ chalk.cyan(
819
+ `\nAI Assistant is currently: ${currentlyHas ? chalk.green('enabled') : chalk.red('disabled')}\n`
820
+ )
821
+ );
822
+
823
+ const { action } = await prompts({
824
+ type: 'select',
825
+ name: 'action',
826
+ message: currentlyHas
827
+ ? 'Remove the AI Assistant from your project?'
828
+ : 'Add the AI Assistant to your project?',
829
+ choices: currentlyHas
830
+ ? [
831
+ {
832
+ title: 'Remove assistant',
833
+ description: 'Deletes AssistantPage and assistant feature files',
834
+ value: 'remove',
835
+ },
836
+ { title: 'Cancel', value: 'cancel' },
837
+ ]
838
+ : [
839
+ {
840
+ title: 'Add assistant',
841
+ description: 'Copies AssistantPage and assistant feature files',
842
+ value: 'add',
843
+ },
844
+ { title: 'Cancel', value: 'cancel' },
845
+ ],
846
+ });
847
+
848
+ if (!action || action === 'cancel') {
849
+ console.log(chalk.gray('Update cancelled.'));
850
+ return;
851
+ }
852
+
853
+ const { confirmed } = await prompts({
854
+ type: 'confirm',
855
+ name: 'confirmed',
856
+ message: chalk.yellow(
857
+ action === 'remove'
858
+ ? '⚠️ This will delete src/features/assistant/ and src/pages/AssistantPage.tsx and regenerate AuthGuard.tsx. Continue?'
859
+ : '⚠️ This will copy src/features/assistant/ and src/pages/AssistantPage.tsx and regenerate AuthGuard.tsx. Continue?'
860
+ ),
861
+ initial: action === 'add',
862
+ });
863
+
864
+ if (!confirmed) {
865
+ console.log(chalk.gray('Update cancelled.'));
866
+ return;
867
+ }
868
+
869
+ const spinner = ora(
870
+ action === 'add' ? 'Adding assistant...' : 'Removing assistant...'
871
+ ).start();
872
+
873
+ try {
874
+ const installedTemplatesDir = path.join(
875
+ targetDir,
876
+ 'node_modules',
877
+ 'xertica-ui',
878
+ 'templates'
879
+ );
880
+ const templatesSourceDir = (await fs.pathExists(installedTemplatesDir))
881
+ ? installedTemplatesDir
882
+ : path.resolve(__dirname, '../templates');
883
+
884
+ // Infer current page set from the pages directory
885
+ const pagesDir = path.join(targetDir, 'src', 'pages');
886
+ const existingPages = (await fs.pathExists(pagesDir)) ? await fs.readdir(pagesDir) : [];
887
+ const hasLogin = existingPages.includes('LoginPage.tsx');
888
+ const hasHome = existingPages.includes('HomePage.tsx');
889
+ const hasTemplate = existingPages.includes('TemplatePage.tsx');
890
+ const firstProtectedPath = hasHome ? '/home' : hasTemplate ? '/template' : '/login';
891
+
892
+ // Read persisted language selection so AuthGuard can be regenerated correctly
893
+ const persistedCodes = await readLanguagesConfig(targetDir);
894
+ const selectedCodes =
895
+ persistedCodes && persistedCodes.length > 0 ? persistedCodes : DEFAULT_SELECTION;
896
+
897
+ if (action === 'add') {
898
+ // Copy assistant feature
899
+ await fs.copy(
900
+ path.join(templatesSourceDir, 'src', 'features', 'assistant'),
901
+ path.join(targetDir, 'src', 'features', 'assistant'),
902
+ { overwrite: true }
903
+ );
904
+ // Copy AssistantPage
905
+ await fs.copy(
906
+ path.join(templatesSourceDir, 'src', 'pages', 'AssistantPage.tsx'),
907
+ path.join(targetDir, 'src', 'pages', 'AssistantPage.tsx'),
908
+ { overwrite: true }
909
+ );
910
+ } else {
911
+ // Remove assistant feature
912
+ await fs.remove(path.join(targetDir, 'src', 'features', 'assistant'));
913
+ await fs.remove(path.join(targetDir, 'src', 'pages', 'AssistantPage.tsx'));
914
+ }
915
+
916
+ // Regenerate pages and AuthGuard reflecting the new assistant state
917
+ const newHasAssistant = action === 'add';
918
+
919
+ if (hasHome) {
920
+ await fs.writeFile(
921
+ path.join(targetDir, 'src', 'pages', 'HomePage.tsx'),
922
+ generateHomePage(newHasAssistant)
923
+ );
924
+ }
925
+ if (hasTemplate) {
926
+ await fs.writeFile(
927
+ path.join(targetDir, 'src', 'pages', 'TemplatePage.tsx'),
928
+ generateTemplatePage(newHasAssistant)
929
+ );
930
+ }
931
+
932
+ await fs.writeFile(
933
+ path.join(targetDir, 'src', 'app', 'components', 'AuthGuard.tsx'),
934
+ generateAuthGuard({
935
+ hasLogin,
936
+ hasHome,
937
+ hasTemplate,
938
+ hasAssistant: newHasAssistant,
939
+ firstProtectedPath,
940
+ })
941
+ );
942
+
943
+ // Persist the updated flag
944
+ await writeXerticaConfig(targetDir, { hasAssistant: newHasAssistant });
945
+
946
+ spinner.succeed(
947
+ action === 'add'
948
+ ? 'AI Assistant added successfully!'
949
+ : 'AI Assistant removed successfully!'
950
+ );
951
+
952
+ if (action === 'add') {
953
+ console.log(chalk.gray('\n Route /assistente is now available.'));
954
+ console.log(chalk.gray(' Configure your Gemini API key in VITE_GEMINI_API_KEY.'));
955
+ } else {
956
+ console.log(chalk.gray('\n Assistant files removed and AuthGuard updated.'));
957
+ }
958
+ } catch (error) {
959
+ spinner.fail('Failed to update assistant');
960
+ console.error(error);
961
+ }
962
+ return;
963
+ }
964
+
965
+ // ── Dark Mode update (enable / disable) ──────────────────────────────────
966
+ if (updateType === 'darkmode') {
967
+ const currentlyDisabled = currentConfig?.disableDarkMode ?? false;
968
+ const { enableDarkMode } = await prompts({
969
+ type: 'confirm',
970
+ name: 'enableDarkMode',
971
+ message: currentlyDisabled
972
+ ? 'Enable dark mode support in your project?'
973
+ : 'Disable dark mode support in your project? (This will hide the toggle and force light mode)',
974
+ initial: !currentlyDisabled,
975
+ });
976
+
977
+ if (enableDarkMode === undefined) return;
978
+
979
+ const newDisableDarkMode = !enableDarkMode;
980
+
981
+ const spinner = ora(
982
+ newDisableDarkMode ? 'Disabling dark mode...' : 'Enabling dark mode...'
983
+ ).start();
984
+ try {
985
+ // Persist the selection
986
+ await writeXerticaConfig(targetDir, { disableDarkMode: newDisableDarkMode });
987
+
988
+ // Regenerate App.tsx with the new dark mode flag
989
+ const persistedCodes = await readLanguagesConfig(targetDir);
990
+ const selectedCodes =
991
+ persistedCodes && persistedCodes.length > 0 ? persistedCodes : DEFAULT_SELECTION;
992
+
993
+ await fs.writeFile(
994
+ path.join(targetDir, 'src', 'app', 'App.tsx'),
995
+ generateAppTsx(selectedCodes, newDisableDarkMode)
996
+ );
997
+
998
+ spinner.succeed(
999
+ newDisableDarkMode
1000
+ ? 'Dark mode disabled successfully! (Locked to Light Mode)'
1001
+ : 'Dark mode enabled successfully!'
1002
+ );
1003
+ } catch (error) {
1004
+ spinner.fail('Failed to update dark mode configuration');
1005
+ console.error(error);
1006
+ }
1007
+ return;
1008
+ }
1009
+
1010
+ // ── Project files update ──────────────────────────────────────────────────
1011
+ const { versionType } = await prompts({
1012
+ type: 'select',
1013
+ name: 'versionType',
1014
+ message: 'Which version do you want to update to?',
1015
+ choices: [
1016
+ { title: 'Latest', description: 'Install the latest published version', value: 'latest' },
1017
+ {
1018
+ title: 'Specific version',
1019
+ description: 'Enter a version number (e.g. 2.0.2)',
1020
+ value: 'specific',
1021
+ },
1022
+ ],
1023
+ });
1024
+
1025
+ if (!versionType) return;
1026
+
1027
+ let targetVersion = 'latest';
1028
+ if (versionType === 'specific') {
1029
+ const { version } = await prompts({
1030
+ type: 'text',
1031
+ name: 'version',
1032
+ message: 'Enter the version (e.g. 2.0.2):',
1033
+ validate: v =>
1034
+ /^\d+\.\d+\.\d+/.test(v.trim()) ? true : 'Enter a valid semver (e.g. 2.0.2)',
1035
+ });
1036
+ if (!version) return;
1037
+ targetVersion = version.trim();
1038
+ }
1039
+
1040
+ const { filesToUpdate } = await prompts({
1041
+ type: 'multiselect',
1042
+ name: 'filesToUpdate',
1043
+ message: 'Select which parts of the project to update:',
1044
+ choices: [
1045
+ {
1046
+ title: 'App shell (src/app/)',
1047
+ description: 'App.tsx, AppLayout.tsx',
1048
+ value: 'app',
1049
+ selected: true,
1050
+ },
1051
+ {
1052
+ title: 'Shared utilities (src/shared/)',
1053
+ description: 'auth.ts, navigation.ts, types',
1054
+ value: 'shared',
1055
+ selected: true,
1056
+ },
1057
+ {
1058
+ title: 'Features (src/features/)',
1059
+ description: 'auth, home, template UI components',
1060
+ value: 'features',
1061
+ selected: true,
1062
+ },
1063
+ {
1064
+ title: 'Pages (src/pages/)',
1065
+ description: 'Thin page wrapper components',
1066
+ value: 'pages',
1067
+ selected: true,
1068
+ },
1069
+ {
1070
+ title: 'Root config files',
1071
+ description: 'vite.config.ts, tsconfig.json, etc.',
1072
+ value: 'config',
1073
+ selected: false,
1074
+ },
1075
+ ],
1076
+ });
1077
+
1078
+ if (!filesToUpdate || filesToUpdate.length === 0) return;
1079
+
1080
+ const { confirmed } = await prompts({
1081
+ type: 'confirm',
1082
+ name: 'confirmed',
1083
+ message: chalk.yellow(
1084
+ `⚠️ This will overwrite the selected files. Local changes will be lost. Continue?`
1085
+ ),
1086
+ initial: false,
1087
+ });
1088
+
1089
+ if (!confirmed) {
1090
+ console.log(chalk.gray('Update cancelled.'));
1091
+ return;
1092
+ }
1093
+
1094
+ const spinner = ora(`Installing xertica-ui@${targetVersion}...`).start();
1095
+
1096
+ try {
1097
+ // Install the target version in the consumer project
1098
+ await execa('npm', ['install', `xertica-ui@${targetVersion}`], { cwd: targetDir });
1099
+ spinner.text = 'Copying updated files...';
1100
+
1101
+ // Templates now come from the freshly installed version
1102
+ const updatedTemplatesDir = path.join(targetDir, 'node_modules', 'xertica-ui', 'templates');
1103
+
1104
+ if (filesToUpdate.includes('app')) {
1105
+ // AppLayout is always safe to overwrite (no per-project config baked in)
1106
+ await fs.copy(
1107
+ path.join(updatedTemplatesDir, 'src', 'app', 'components', 'AppLayout.tsx'),
1108
+ path.join(targetDir, 'src', 'app', 'components', 'AppLayout.tsx'),
1109
+ { overwrite: true }
1110
+ );
1111
+
1112
+ // For App.tsx and i18n.ts we must preserve the user's language selection.
1113
+ // Read it from .languages.json (or fall back to inspecting locales/ for
1114
+ // projects scaffolded before the file existed).
1115
+ const persistedCodes = await readLanguagesConfig(targetDir);
1116
+ let selectedCodes: string[] = persistedCodes ?? [];
1117
+ if (selectedCodes.length === 0) {
1118
+ const localesDir = path.join(targetDir, 'src', 'locales');
1119
+ if (await fs.pathExists(localesDir)) {
1120
+ const entries = await fs.readdir(localesDir);
1121
+ // Accept both the new folder layout and the legacy flat layout
1122
+ selectedCodes = SUPPORTED_LANGUAGES.filter(
1123
+ l => entries.includes(l.jsonFile) || entries.includes(`${l.jsonFile}.json`)
1124
+ ).map(l => l.code);
1125
+ }
1126
+ if (selectedCodes.length === 0) selectedCodes = DEFAULT_SELECTION;
1127
+ // Persist the inferred selection so future updates have it cached
1128
+ await writeLanguagesConfig(targetDir, selectedCodes);
1129
+ }
1130
+
1131
+ const projectConfig = await readXerticaConfig(targetDir);
1132
+
1133
+ // Regenerate App.tsx and i18n.ts honoring the persisted language set
1134
+ await fs.writeFile(
1135
+ path.join(targetDir, 'src', 'app', 'App.tsx'),
1136
+ generateAppTsx(selectedCodes, projectConfig?.disableDarkMode ?? false)
1137
+ );
1138
+ await fs.writeFile(path.join(targetDir, 'src', 'i18n.ts'), generateI18nFile(selectedCodes));
1139
+
1140
+ // Refresh locale JSON files for the selected languages (keys grow over
1141
+ // library updates) — but prune any orphans from prior selections.
1142
+ await syncLocaleFiles(updatedTemplatesDir, targetDir, selectedCodes, {
1143
+ pruneOthers: true,
1144
+ });
1145
+
1146
+ // Regenerate AuthGuard preserving the current page set and assistant flag
1147
+ const pagesDir = path.join(targetDir, 'src', 'pages');
1148
+ const existingPages = (await fs.pathExists(pagesDir)) ? await fs.readdir(pagesDir) : [];
1149
+ const hasLoginP = existingPages.includes('LoginPage.tsx');
1150
+ const hasHomeP = existingPages.includes('HomePage.tsx');
1151
+ const hasTemplateP = existingPages.includes('TemplatePage.tsx');
1152
+ const hasAssistantP =
1153
+ projectConfig?.hasAssistant ?? existingPages.includes('AssistantPage.tsx');
1154
+ const firstProtectedP = hasHomeP ? '/home' : hasTemplateP ? '/template' : '/login';
1155
+ await fs.writeFile(
1156
+ path.join(targetDir, 'src', 'app', 'components', 'AuthGuard.tsx'),
1157
+ generateAuthGuard({
1158
+ hasLogin: hasLoginP,
1159
+ hasHome: hasHomeP,
1160
+ hasTemplate: hasTemplateP,
1161
+ hasAssistant: hasAssistantP,
1162
+ firstProtectedPath: firstProtectedP,
1163
+ })
1164
+ );
1165
+ }
1166
+
1167
+ if (filesToUpdate.includes('shared')) {
1168
+ await fs.copy(
1169
+ path.join(updatedTemplatesDir, 'src', 'shared'),
1170
+ path.join(targetDir, 'src', 'shared'),
1171
+ { overwrite: true }
1172
+ );
1173
+ }
1174
+
1175
+ if (filesToUpdate.includes('features')) {
1176
+ // Only update feature directories that already exist in the project.
1177
+ // 'assistant' is only present if it was included during init (or added via update → Assistant).
1178
+ for (const feature of ['auth', 'home', 'template', 'assistant']) {
1179
+ const destFeature = path.join(targetDir, 'src', 'features', feature);
1180
+ const srcFeature = path.join(updatedTemplatesDir, 'src', 'features', feature);
1181
+ if ((await fs.pathExists(destFeature)) && (await fs.pathExists(srcFeature))) {
1182
+ await fs.copy(srcFeature, destFeature, { overwrite: true });
1183
+ }
1184
+ }
1185
+ }
1186
+
1187
+ if (filesToUpdate.includes('pages')) {
1188
+ const pagesDir = path.join(targetDir, 'src', 'pages');
1189
+ const srcPagesDir = path.join(updatedTemplatesDir, 'src', 'pages');
1190
+ if ((await fs.pathExists(pagesDir)) && (await fs.pathExists(srcPagesDir))) {
1191
+ const projectCfg = await readXerticaConfig(targetDir);
1192
+ const existingPages = await fs.readdir(pagesDir);
1193
+ const assistantEnabled =
1194
+ projectCfg?.hasAssistant ?? existingPages.includes('AssistantPage.tsx');
1195
+
1196
+ for (const pageFile of existingPages) {
1197
+ // Generated pages: regenerate instead of copy so assistant imports stay correct
1198
+ if (pageFile === 'HomePage.tsx') {
1199
+ await fs.writeFile(
1200
+ path.join(pagesDir, 'HomePage.tsx'),
1201
+ generateHomePage(assistantEnabled)
1202
+ );
1203
+ continue;
1204
+ }
1205
+ if (pageFile === 'TemplatePage.tsx') {
1206
+ await fs.writeFile(
1207
+ path.join(pagesDir, 'TemplatePage.tsx'),
1208
+ generateTemplatePage(assistantEnabled)
1209
+ );
1210
+ continue;
1211
+ }
1212
+ const src = path.join(srcPagesDir, pageFile);
1213
+ if (await fs.pathExists(src)) {
1214
+ await fs.copy(src, path.join(pagesDir, pageFile), { overwrite: true });
1215
+ }
1216
+ }
1217
+ }
1218
+ }
1219
+
1220
+ if (filesToUpdate.includes('config')) {
1221
+ // Config files are inside the templates/ directory (same level as src/)
1222
+ const configFiles = [
1223
+ 'vite.config.ts',
1224
+ 'tsconfig.json',
1225
+ 'tsconfig.node.json',
1226
+ 'postcss.config.js',
1227
+ ];
1228
+ for (const file of configFiles) {
1229
+ const src = path.join(updatedTemplatesDir, file);
1230
+ if (await fs.pathExists(src)) {
1231
+ await fs.copy(src, path.join(targetDir, file), { overwrite: true });
1232
+ }
1233
+ }
1234
+ }
1235
+
1236
+ spinner.succeed(`Project updated to xertica-ui@${targetVersion} successfully!`);
1237
+ console.log(chalk.gray('\n Run npm run dev to start the development server.'));
1238
+ } catch (error) {
1239
+ spinner.fail('Failed to update project');
1240
+ console.error(error);
1241
+ }
1242
+ });
1243
+
1244
+ program.parse();