xertica-ui 2.3.0 → 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 (534) hide show
  1. package/CHANGELOG.md +564 -552
  2. package/README.md +417 -406
  3. package/assets/xertica-logo.svg +37 -37
  4. package/assets/xertica-x-logo.svg +20 -20
  5. package/bin/cli.ts +1244 -1155
  6. package/bin/language-config.ts +358 -361
  7. package/components/assistant/code-block/CodeBlock.tsx +268 -268
  8. package/components/assistant/formatted-document/FormattedDocument.tsx +147 -147
  9. package/components/assistant/modern-chat-input/ModernChatInput.tsx +564 -554
  10. package/components/assistant/xertica-assistant/parts/AssistantCollapsedView.tsx +99 -99
  11. package/components/assistant/xertica-assistant/parts/AssistantConversationList.tsx +104 -106
  12. package/components/assistant/xertica-assistant/parts/AssistantDocumentEditor.tsx +81 -81
  13. package/components/assistant/xertica-assistant/parts/AssistantFeedbackDialog.tsx +88 -78
  14. package/components/assistant/xertica-assistant/parts/AssistantHeader.tsx +75 -75
  15. package/components/assistant/xertica-assistant/parts/AssistantMessageBubble.tsx +564 -560
  16. package/components/assistant/xertica-assistant/parts/AssistantTabBar.tsx +67 -67
  17. package/components/assistant/xertica-assistant/parts/AssistantWelcomeScreen.tsx +103 -103
  18. package/components/assistant/xertica-assistant/use-assistant.ts +615 -615
  19. package/components/assistant/xertica-assistant/xertica-assistant.tsx +611 -613
  20. package/components/blocks/card-patterns/ActivityCard.tsx +100 -100
  21. package/components/blocks/card-patterns/ActivityCardSkeleton.tsx +56 -56
  22. package/components/blocks/card-patterns/FeatureCardSkeleton.tsx +58 -63
  23. package/components/blocks/card-patterns/NotificationCard.tsx +140 -140
  24. package/components/blocks/card-patterns/NotificationCardSkeleton.tsx +81 -81
  25. package/components/blocks/card-patterns/ProfileCard.tsx +112 -114
  26. package/components/blocks/card-patterns/ProfileCardSkeleton.tsx +69 -69
  27. package/components/blocks/card-patterns/ProjectCard.tsx +123 -123
  28. package/components/blocks/card-patterns/ProjectCardSkeleton.tsx +67 -72
  29. package/components/blocks/card-patterns/QuickActionCardSkeleton.tsx +44 -44
  30. package/components/blocks/card-patterns/card-patterns.stories.tsx +594 -594
  31. package/components/blocks/card-patterns/index.ts +29 -29
  32. package/components/brand/language-selector/LanguageSelector.tsx +102 -102
  33. package/components/brand/language-selector/language-selector.stories.tsx +111 -114
  34. package/components/brand/language-selector/language-selector.test.tsx +101 -101
  35. package/components/brand/theme-toggle/ThemeToggle.tsx +74 -70
  36. package/components/brand/xertica-provider/XerticaProvider.tsx +109 -112
  37. package/components/brand/xertica-provider/xertica-provider.mdx +61 -61
  38. package/components/index.ts +86 -90
  39. package/components/layout/sidebar/sidebar.mdx +1 -1
  40. package/components/layout/sidebar/sidebar.tsx +1079 -1073
  41. package/components/media/FloatingMediaWrapper.tsx +371 -371
  42. package/components/media/audio-player/AudioPlayer.tsx +768 -766
  43. package/components/media/video-player/VideoPlayer.tsx +310 -310
  44. package/components/pages/forgot-password-page/ForgotPasswordPage.tsx +1 -1
  45. package/components/pages/home-content/HomeContent.tsx +120 -120
  46. package/components/pages/home-content/home-content.mdx +62 -62
  47. package/components/pages/home-page/HomePage.tsx +78 -74
  48. package/components/pages/home-page/home-page.mdx +53 -53
  49. package/components/pages/login-page/LoginPage.tsx +218 -216
  50. package/components/pages/reset-password-page/ResetPasswordPage.tsx +243 -239
  51. package/components/pages/template-content/TemplateContent.tsx +1354 -1235
  52. package/components/pages/template-content/template-content.mdx +61 -61
  53. package/components/pages/template-page/template-page.mdx +53 -53
  54. package/components/pages/verify-email-page/VerifyEmailPage.tsx +206 -206
  55. package/components/shared/error-boundary.stories.tsx +4 -22
  56. package/components/shared/error-boundary.tsx +1 -5
  57. package/components/shared/error-fallbacks.tsx +4 -8
  58. package/components/ui/accordion/accordion.mdx +8 -8
  59. package/components/ui/alert/alert.mdx +8 -8
  60. package/components/ui/alert-dialog/alert-dialog.mdx +8 -8
  61. package/components/ui/aspect-ratio/aspect-ratio.mdx +8 -8
  62. package/components/ui/assistant-chart/assistant-chart.mdx +8 -8
  63. package/components/ui/avatar/avatar.mdx +8 -8
  64. package/components/ui/badge/badge.mdx +8 -8
  65. package/components/ui/breadcrumb/breadcrumb.mdx +8 -8
  66. package/components/ui/button/button.mdx +8 -8
  67. package/components/ui/calendar/calendar.mdx +8 -8
  68. package/components/ui/card/card.mdx +8 -8
  69. package/components/ui/carousel/carousel.mdx +8 -8
  70. package/components/ui/chart/chart.mdx +8 -8
  71. package/components/ui/checkbox/checkbox.mdx +8 -8
  72. package/components/ui/collapsible/collapsible.mdx +8 -8
  73. package/components/ui/command/command.mdx +8 -8
  74. package/components/ui/context-menu/context-menu.mdx +8 -8
  75. package/components/ui/dialog/dialog.mdx +8 -8
  76. package/components/ui/drawer/drawer.mdx +8 -8
  77. package/components/ui/dropdown-menu/dropdown-menu.mdx +8 -8
  78. package/components/ui/empty/empty.mdx +8 -8
  79. package/components/ui/file-upload/file-upload.mdx +8 -8
  80. package/components/ui/hover-card/hover-card.mdx +8 -8
  81. package/components/ui/input/input.mdx +8 -8
  82. package/components/ui/input-otp/input-otp.mdx +8 -8
  83. package/components/ui/label/label.mdx +8 -8
  84. package/components/ui/map/map.mdx +8 -8
  85. package/components/ui/menubar/menubar.mdx +8 -8
  86. package/components/ui/navigation-menu/navigation-menu.mdx +8 -8
  87. package/components/ui/notification-badge/notification-badge.mdx +8 -8
  88. package/components/ui/pagination/pagination.mdx +8 -8
  89. package/components/ui/popover/popover.mdx +8 -8
  90. package/components/ui/progress/progress.mdx +8 -8
  91. package/components/ui/radio-group/radio-group.mdx +8 -8
  92. package/components/ui/rating/rating.mdx +8 -8
  93. package/components/ui/resizable/resizable.mdx +8 -8
  94. package/components/ui/route-map/route-map.mdx +8 -8
  95. package/components/ui/scroll-area/scroll-area.mdx +8 -8
  96. package/components/ui/search/search.mdx +8 -8
  97. package/components/ui/select/select.mdx +8 -8
  98. package/components/ui/separator/separator.mdx +8 -8
  99. package/components/ui/sheet/sheet.mdx +8 -8
  100. package/components/ui/simple-map/simple-map.mdx +8 -8
  101. package/components/ui/skeleton/skeleton.mdx +8 -8
  102. package/components/ui/slider/slider.mdx +8 -8
  103. package/components/ui/sonner/sonner.mdx +8 -8
  104. package/components/ui/stats-card/index.ts +2 -2
  105. package/components/ui/stats-card/stats-card-skeleton.tsx +60 -62
  106. package/components/ui/stats-card/stats-card.mdx +8 -8
  107. package/components/ui/stats-card/stats-card.stories.tsx +99 -99
  108. package/components/ui/stepper/stepper.mdx +8 -8
  109. package/components/ui/switch/switch.mdx +8 -8
  110. package/components/ui/table/table.mdx +8 -8
  111. package/components/ui/tabs/tabs.mdx +8 -8
  112. package/components/ui/textarea/textarea.mdx +8 -8
  113. package/components/ui/timeline/timeline.mdx +8 -8
  114. package/components/ui/toggle/toggle.mdx +8 -8
  115. package/components/ui/toggle-group/toggle-group.mdx +8 -8
  116. package/components/ui/tooltip/tooltip.mdx +8 -8
  117. package/components/ui/tree-view/tree-view.mdx +8 -8
  118. package/components.json +892 -892
  119. package/contexts/AuthContext.tsx +11 -8
  120. package/contexts/LanguageContext.test.tsx +121 -121
  121. package/contexts/LanguageContext.tsx +250 -251
  122. package/dist/{AssistantChart-DoZCyS5r.cjs → AssistantChart-9w31gdAb.cjs} +4 -4
  123. package/dist/{AssistantChart-CldVCVDe.cjs → AssistantChart-BAudAfne.cjs} +5 -5
  124. package/dist/{AssistantChart-Bdd44uBn.cjs → AssistantChart-BAx9VQvb.cjs} +127 -388
  125. package/dist/{AssistantChart-Cu3m7RBo.js → AssistantChart-BP8upjMk.js} +5 -5
  126. package/dist/{AssistantChart-CFhDdGyU.js → AssistantChart-CVko2A1W.js} +130 -391
  127. package/dist/{AssistantChart-C_hwFRRr.js → AssistantChart-CVzmmhx4.js} +4 -4
  128. package/dist/{AudioPlayer-IAU5q5T1.cjs → AudioPlayer-1ypwE2Wh.cjs} +1 -1
  129. package/dist/{AudioPlayer-CGRUtUdN.js → AudioPlayer-DuKXrCfy.js} +1 -1
  130. package/dist/{LanguageContext-CS14yCpi.js → LanguageContext-BwhwC3G2.js} +2 -2
  131. package/dist/{LanguageContext-B_KFTCzT.cjs → LanguageContext-DvUt5jBg.cjs} +2 -2
  132. package/dist/{ThemeContext-C2EwAPDt.js → ThemeContext-BbBNoFTG.js} +2 -2
  133. package/dist/{ThemeContext-Bmod0Cg2.cjs → ThemeContext-BblcjQup.cjs} +13 -8
  134. package/dist/{ThemeContext-BWq9ACPo.js → ThemeContext-Bo-W2WZH.js} +13 -8
  135. package/dist/{ThemeContext-j5aGtPky.cjs → ThemeContext-CP3a0jxy.cjs} +193 -262
  136. package/dist/{ThemeContext-vTjumZeM.cjs → ThemeContext-Cmr8Ex8H.cjs} +2 -2
  137. package/dist/ThemeContext-CpqYShLq.cjs +324 -0
  138. package/dist/{ThemeContext-CQSo4Iwc.js → ThemeContext-D3LzacmG.js} +8 -1
  139. package/dist/ThemeContext-Du2nE1PL.js +325 -0
  140. package/dist/ThemeContext-GeEBTJ3q.cjs +1621 -0
  141. package/dist/ThemeContext-JyLK9B1o.js +1622 -0
  142. package/dist/{ThemeContext-CGk3KK0k.cjs → ThemeContext-U4dEYc6C.cjs} +8 -1
  143. package/dist/{ThemeContext-BXjrgUjW.js → ThemeContext-ept8jhXI.js} +200 -261
  144. package/dist/{VerifyEmailPage-C0c2e5n0.js → VerifyEmailPage-BE-L9mB7.js} +7 -7
  145. package/dist/{VerifyEmailPage-DSBMRHtl.js → VerifyEmailPage-BIBOKV7Z.js} +41 -36
  146. package/dist/{VerifyEmailPage-DgIid028.js → VerifyEmailPage-BJjAMUTW.js} +4 -4
  147. package/dist/{VerifyEmailPage--1Vurewl.cjs → VerifyEmailPage-BRSP-Pwt.cjs} +3 -3
  148. package/dist/{VerifyEmailPage-Cwi3kbol.cjs → VerifyEmailPage-Bae2cBXT.cjs} +7 -7
  149. package/dist/{VerifyEmailPage-De6bQjrz.cjs → VerifyEmailPage-BiRm7Nh4.cjs} +41 -36
  150. package/dist/{VerifyEmailPage-ByerOcm4.cjs → VerifyEmailPage-Bv8Ah_TK.cjs} +23 -20
  151. package/dist/VerifyEmailPage-Bvfv8HVQ.js +3214 -0
  152. package/dist/{VerifyEmailPage-BComraR7.cjs → VerifyEmailPage-CR7kb5df.cjs} +22 -12
  153. package/dist/{VerifyEmailPage-MTD7AG1Z.js → VerifyEmailPage-C_ihbcth.js} +4 -4
  154. package/dist/{VerifyEmailPage-1WwWczAn.js → VerifyEmailPage-CbgjOF0v.js} +22 -12
  155. package/dist/{VerifyEmailPage-DvMLZgFt.js → VerifyEmailPage-CdYPSJoO.js} +1 -1
  156. package/dist/{VerifyEmailPage-By3Jf__L.cjs → VerifyEmailPage-CkBYfsNy.cjs} +4 -4
  157. package/dist/{VerifyEmailPage-CJLz3jrn.js → VerifyEmailPage-Cyl55sJb.js} +23 -20
  158. package/dist/VerifyEmailPage-D-FRj5TU.cjs +3213 -0
  159. package/dist/VerifyEmailPage-DF2ilhum.cjs +3210 -0
  160. package/dist/{VerifyEmailPage-CYXtbKi3.cjs → VerifyEmailPage-DMBh4NM9.cjs} +1 -1
  161. package/dist/{VerifyEmailPage-CgMxRb4z.js → VerifyEmailPage-DTtFfC-J.js} +3 -3
  162. package/dist/{VerifyEmailPage-CFLMls1p.cjs → VerifyEmailPage-Dt7zgA4w.cjs} +4 -4
  163. package/dist/VerifyEmailPage-EhudUdqF.js +3211 -0
  164. package/dist/{VerifyEmailPage-C5TNQTBa.js → VerifyEmailPage-X14vhdyl.js} +148 -75
  165. package/dist/VerifyEmailPage-hdB8JQGv.cjs +3213 -0
  166. package/dist/{VerifyEmailPage-B4peJjAT.cjs → VerifyEmailPage-u_Dn7t1U.cjs} +148 -75
  167. package/dist/VerifyEmailPage-vYHbYK3q.js +3214 -0
  168. package/dist/{XerticaProvider-CBGc4EMA.cjs → XerticaProvider-AChwphCO.cjs} +4 -4
  169. package/dist/{XerticaProvider-BIrqfZ-i.cjs → XerticaProvider-AbWlr7Af.cjs} +8 -11
  170. package/dist/{XerticaProvider-D-yNhF94.cjs → XerticaProvider-B8CaV7xu.cjs} +1 -1
  171. package/dist/{XerticaProvider-DDuiIcKo.js → XerticaProvider-BErr83Bg.js} +14 -11
  172. package/dist/{XerticaProvider-CEoWMTxu.js → XerticaProvider-BITjgC5p.js} +2 -2
  173. package/dist/{XerticaProvider-CllrbMEJ.cjs → XerticaProvider-By8q3Roe.cjs} +2 -2
  174. package/dist/{XerticaProvider-C1DKnvLh.js → XerticaProvider-CUYJZc32.js} +4 -4
  175. package/dist/{XerticaProvider-ET0ihewn.cjs → XerticaProvider-CW9hpCdF.cjs} +2 -2
  176. package/dist/{XerticaProvider-Dt5HEzbQ.js → XerticaProvider-CWgby5mY.js} +10 -10
  177. package/dist/XerticaProvider-CWs6EwNa.js +49 -0
  178. package/dist/XerticaProvider-CjQAQPcn.cjs +48 -0
  179. package/dist/XerticaProvider-CwOkHxiT.cjs +44 -0
  180. package/dist/XerticaProvider-D5lLumH-.js +49 -0
  181. package/dist/{XerticaProvider-DYq4JWtg.js → XerticaProvider-DQtvJU7m.js} +1 -1
  182. package/dist/XerticaProvider-qQUDop71.cjs +48 -0
  183. package/dist/{XerticaProvider-B7EVH-NF.js → XerticaProvider-siSt9uG2.js} +2 -2
  184. package/dist/{XerticaXLogo-Zw2B276b.cjs → XerticaXLogo-8TTzBjHw.cjs} +1 -1
  185. package/dist/{XerticaXLogo-B7xQ5dhi.js → XerticaXLogo-BWaag64t.js} +1 -1
  186. package/dist/{XerticaXLogo-DZbo4vOE.js → XerticaXLogo-BX3ueACh.js} +5 -2
  187. package/dist/XerticaXLogo-CFuIlYFH.js +252 -0
  188. package/dist/XerticaXLogo-CU-U-GP4.cjs +251 -0
  189. package/dist/XerticaXLogo-ChryA6xj.js +252 -0
  190. package/dist/{XerticaXLogo-CQUUjXoH.cjs → XerticaXLogo-CziKMQil.cjs} +8 -8
  191. package/dist/XerticaXLogo-DHz5SugF.js +252 -0
  192. package/dist/XerticaXLogo-DTee_y8X.cjs +251 -0
  193. package/dist/{XerticaXLogo-Cmsp-Eey.js → XerticaXLogo-DfUvz-lD.js} +9 -9
  194. package/dist/XerticaXLogo-kslQ8Tk_.cjs +251 -0
  195. package/dist/{XerticaXLogo-bvZSgwGF.cjs → XerticaXLogo-qBPhwK3g.cjs} +5 -2
  196. package/dist/{alert-dialog-s-vmNkJ_.js → alert-dialog-iDe5VE5o.js} +3 -3
  197. package/dist/{alert-dialog-DSKByiKZ.cjs → alert-dialog-yckpaOpy.cjs} +3 -3
  198. package/dist/assistant.cjs.js +1 -1
  199. package/dist/assistant.es.js +1 -1
  200. package/dist/brand.cjs.js +2 -2
  201. package/dist/brand.es.js +2 -2
  202. package/dist/cli.js +90 -37
  203. package/dist/components/brand/theme-toggle/ThemeToggle.d.ts +1 -1
  204. package/dist/components/index.d.ts +1 -1
  205. package/dist/{google-maps-loader-Y-QkD-Li.cjs → google-maps-loader-BqsYL48U.cjs} +0 -5
  206. package/dist/{google-maps-loader-CTYySAun.js → google-maps-loader-t2IlYBzw.js} +0 -4
  207. package/dist/index-CkTUgOwX.js +8 -0
  208. package/dist/{index-COtD8bRW.cjs → index-D3RLKRAs.cjs} +1 -1
  209. package/dist/index.cjs.js +5 -5
  210. package/dist/index.es.js +5 -5
  211. package/dist/index.umd.js +454 -1027
  212. package/dist/layout.cjs.js +1 -1
  213. package/dist/layout.es.js +1 -1
  214. package/dist/pages.cjs.js +1 -1
  215. package/dist/pages.es.js +1 -1
  216. package/dist/{sidebar-DAaY8bRU.cjs → sidebar-B3EYhli0.cjs} +33 -24
  217. package/dist/{sidebar-B6SlKZYN.js → sidebar-B4ZWaMrE.js} +1 -1
  218. package/dist/{sidebar-DQj1z3jG.cjs → sidebar-B9NR0lCe.cjs} +269 -227
  219. package/dist/{sidebar-nzPoVHBQ.cjs → sidebar-BS1p2V7t.cjs} +1 -1
  220. package/dist/sidebar-BvF5I2Ue.cjs +800 -0
  221. package/dist/{sidebar-q7P2Godd.cjs → sidebar-C5B_LHek.cjs} +1 -1
  222. package/dist/{sidebar-CrQDDdcz.js → sidebar-CA6_ek3f.js} +33 -24
  223. package/dist/{sidebar-BxGXsDAd.cjs → sidebar-CVUGHOS_.cjs} +8 -16
  224. package/dist/{sidebar-BViy8Eeu.js → sidebar-CmvwjnVb.js} +9 -17
  225. package/dist/sidebar-CplprZpM.js +801 -0
  226. package/dist/{sidebar-BbVIQvlP.js → sidebar-Dz7bd3zP.js} +1 -1
  227. package/dist/sidebar-KIS0C2JH.js +801 -0
  228. package/dist/sidebar-OTO_up7Z.js +801 -0
  229. package/dist/sidebar-zowjejT2.cjs +800 -0
  230. package/dist/{use-audio-player-nv8ZSGa1.js → use-audio-player-Bkh23vQ3.js} +3 -7
  231. package/dist/{use-audio-player-NKsWyjWu.cjs → use-audio-player-Dn1NR9xN.cjs} +3 -7
  232. package/dist/{xertica-assistant-dyP7KHM5.cjs → xertica-assistant-B1IaHXnB.cjs} +388 -529
  233. package/dist/{xertica-assistant-DCsnQyi5.js → xertica-assistant-B1NaSFFj.js} +46 -29
  234. package/dist/{xertica-assistant-ciJaWqm1.js → xertica-assistant-BMqdyRVi.js} +10 -28
  235. package/dist/{xertica-assistant-V_IdW4WF.cjs → xertica-assistant-Bj3vBCq_.cjs} +9 -27
  236. package/dist/{xertica-assistant-CrgTb6Hs.cjs → xertica-assistant-CIaUlbIt.cjs} +47 -22
  237. package/dist/{xertica-assistant-yX1CFBBo.js → xertica-assistant-DPsESB6t.js} +390 -531
  238. package/dist/{CodeBlock-BgfYL_rD.cjs → xertica-assistant-Qp3ydksa.cjs} +51 -263
  239. package/dist/{CodeBlock-BeSt1h5P.js → xertica-assistant-gnCJdcZY.js} +7 -219
  240. package/dist/xertica-ui.css +2 -2
  241. package/docs/architecture-improvements.md +456 -456
  242. package/docs/architecture.md +312 -306
  243. package/docs/components/assistant.md +428 -428
  244. package/docs/components/branding.md +252 -252
  245. package/docs/components/card-patterns.md +447 -445
  246. package/docs/components/error-boundary.md +32 -22
  247. package/docs/components/hooks.md +432 -430
  248. package/docs/components/language-selector.md +176 -172
  249. package/docs/components/pages.md +20 -6
  250. package/docs/doc-audit.md +244 -243
  251. package/docs/getting-started.md +616 -603
  252. package/docs/guidelines.md +330 -328
  253. package/docs/i18n.md +480 -476
  254. package/docs/installation.md +7 -6
  255. package/docs/llms.md +295 -295
  256. package/docs/state-management.md +289 -289
  257. package/guidelines/Guidelines.md +409 -406
  258. package/llms-compact.txt +1 -1
  259. package/llms.txt +1 -1
  260. package/package.json +219 -219
  261. package/styles/xertica/base.css +6 -0
  262. package/templates/.prettierignore +4 -4
  263. package/templates/.prettierrc +10 -10
  264. package/templates/CLAUDE.md +180 -165
  265. package/templates/guidelines/Guidelines.md +577 -553
  266. package/templates/package.json +69 -69
  267. package/templates/src/app/App.tsx +46 -46
  268. package/templates/src/app/components/AuthGuard.tsx +57 -8
  269. package/templates/src/features/assistant/data/mock.ts +75 -75
  270. package/templates/src/features/assistant/hooks/useAssistantConfig.ts +20 -20
  271. package/templates/src/features/assistant/index.ts +5 -5
  272. package/templates/src/features/auth/ui/AuthPageShell.tsx +1 -1
  273. package/templates/src/features/auth/ui/ForgotPasswordContent.tsx +70 -72
  274. package/templates/src/features/auth/ui/LoginContent.tsx +92 -92
  275. package/templates/src/features/auth/ui/ResetPasswordContent.tsx +183 -179
  276. package/templates/src/features/auth/ui/SocialLoginButtons.tsx +78 -78
  277. package/templates/src/features/auth/ui/VerifyEmailContent.tsx +80 -84
  278. package/templates/src/features/home/data/mock.ts +6 -0
  279. package/templates/src/features/home/hooks/useFeatureCards.ts +20 -20
  280. package/templates/src/features/home/index.ts +11 -11
  281. package/templates/src/features/home/ui/HomeContent.tsx +117 -119
  282. package/templates/src/features/template/ui/CrudTemplate.tsx +112 -115
  283. package/templates/src/features/template/ui/DashboardTemplate.tsx +110 -110
  284. package/templates/src/features/template/ui/FormTemplate.tsx +117 -117
  285. package/templates/src/features/template/ui/LoginTemplate.tsx +59 -59
  286. package/templates/src/features/template/ui/TemplateContent.tsx +1322 -1314
  287. package/templates/src/i18n.ts +124 -124
  288. package/templates/src/locales/en/common.json +21 -21
  289. package/templates/src/locales/en/components/activityCard.json +10 -10
  290. package/templates/src/locales/en/components/assistant.json +119 -119
  291. package/templates/src/locales/en/components/media.json +29 -29
  292. package/templates/src/locales/en/components/notificationCard.json +5 -5
  293. package/templates/src/locales/en/components/profileCard.json +8 -8
  294. package/templates/src/locales/en/components/projectCard.json +10 -10
  295. package/templates/src/locales/en/components/sidebar.json +14 -14
  296. package/templates/src/locales/en/components/stats.json +8 -8
  297. package/templates/src/locales/en/components/team.json +14 -14
  298. package/templates/src/locales/en/errors.json +9 -9
  299. package/templates/src/locales/en/languageSelector.json +7 -7
  300. package/templates/src/locales/en/nav.json +6 -6
  301. package/templates/src/locales/en/pages/crudTemplate.json +25 -25
  302. package/templates/src/locales/en/pages/dashboardTemplate.json +20 -20
  303. package/templates/src/locales/en/pages/forgotPassword.json +10 -10
  304. package/templates/src/locales/en/pages/formTemplate.json +16 -16
  305. package/templates/src/locales/en/pages/home.json +7 -7
  306. package/templates/src/locales/en/pages/login.json +15 -15
  307. package/templates/src/locales/en/pages/loginTemplate.json +9 -9
  308. package/templates/src/locales/en/pages/resetPassword.json +18 -18
  309. package/templates/src/locales/en/pages/templates.json +317 -317
  310. package/templates/src/locales/en/pages/verifyEmail.json +12 -12
  311. package/templates/src/locales/en/themeToggle.json +6 -6
  312. package/templates/src/locales/es/common.json +21 -21
  313. package/templates/src/locales/es/components/activityCard.json +10 -10
  314. package/templates/src/locales/es/components/assistant.json +119 -119
  315. package/templates/src/locales/es/components/media.json +29 -29
  316. package/templates/src/locales/es/components/notificationCard.json +5 -5
  317. package/templates/src/locales/es/components/profileCard.json +8 -8
  318. package/templates/src/locales/es/components/projectCard.json +10 -10
  319. package/templates/src/locales/es/components/sidebar.json +14 -14
  320. package/templates/src/locales/es/components/stats.json +8 -8
  321. package/templates/src/locales/es/components/team.json +14 -14
  322. package/templates/src/locales/es/errors.json +9 -9
  323. package/templates/src/locales/es/languageSelector.json +7 -7
  324. package/templates/src/locales/es/nav.json +6 -6
  325. package/templates/src/locales/es/pages/crudTemplate.json +25 -25
  326. package/templates/src/locales/es/pages/dashboardTemplate.json +20 -20
  327. package/templates/src/locales/es/pages/forgotPassword.json +10 -10
  328. package/templates/src/locales/es/pages/formTemplate.json +16 -16
  329. package/templates/src/locales/es/pages/home.json +7 -7
  330. package/templates/src/locales/es/pages/login.json +15 -15
  331. package/templates/src/locales/es/pages/loginTemplate.json +9 -9
  332. package/templates/src/locales/es/pages/resetPassword.json +18 -18
  333. package/templates/src/locales/es/pages/templates.json +317 -317
  334. package/templates/src/locales/es/pages/verifyEmail.json +12 -12
  335. package/templates/src/locales/es/themeToggle.json +6 -6
  336. package/templates/src/locales/pt-BR/common.json +21 -21
  337. package/templates/src/locales/pt-BR/components/activityCard.json +10 -10
  338. package/templates/src/locales/pt-BR/components/assistant.json +119 -119
  339. package/templates/src/locales/pt-BR/components/media.json +29 -29
  340. package/templates/src/locales/pt-BR/components/notificationCard.json +5 -5
  341. package/templates/src/locales/pt-BR/components/profileCard.json +8 -8
  342. package/templates/src/locales/pt-BR/components/projectCard.json +10 -10
  343. package/templates/src/locales/pt-BR/components/sidebar.json +14 -14
  344. package/templates/src/locales/pt-BR/components/stats.json +8 -8
  345. package/templates/src/locales/pt-BR/components/team.json +14 -14
  346. package/templates/src/locales/pt-BR/errors.json +9 -9
  347. package/templates/src/locales/pt-BR/languageSelector.json +7 -7
  348. package/templates/src/locales/pt-BR/nav.json +6 -6
  349. package/templates/src/locales/pt-BR/pages/crudTemplate.json +25 -25
  350. package/templates/src/locales/pt-BR/pages/dashboardTemplate.json +20 -20
  351. package/templates/src/locales/pt-BR/pages/forgotPassword.json +10 -10
  352. package/templates/src/locales/pt-BR/pages/formTemplate.json +16 -16
  353. package/templates/src/locales/pt-BR/pages/home.json +7 -7
  354. package/templates/src/locales/pt-BR/pages/login.json +15 -15
  355. package/templates/src/locales/pt-BR/pages/loginTemplate.json +9 -9
  356. package/templates/src/locales/pt-BR/pages/resetPassword.json +18 -18
  357. package/templates/src/locales/pt-BR/pages/templates.json +317 -317
  358. package/templates/src/locales/pt-BR/pages/verifyEmail.json +12 -12
  359. package/templates/src/locales/pt-BR/themeToggle.json +6 -6
  360. package/templates/src/pages/AssistantPage.tsx +470 -464
  361. package/templates/src/pages/HomePage.tsx +53 -49
  362. package/templates/src/shared/error-boundary.tsx +1 -5
  363. package/templates/src/shared/error-fallbacks.tsx +4 -8
  364. package/templates/vite.config.js +20 -20
  365. package/templates/vite.config.ts +55 -52
  366. package/dist/AssistantChart-CxGjH7Qk.js +0 -3477
  367. package/dist/AssistantChart-DIpshm3i.js +0 -4784
  368. package/dist/AssistantChart-D_PTeu8P.cjs +0 -3503
  369. package/dist/AssistantChart-zjsy2GaZ.cjs +0 -4810
  370. package/dist/AudioPlayer-B1lt5cPl.cjs +0 -989
  371. package/dist/AudioPlayer-BZ7bibzU.cjs +0 -982
  372. package/dist/AudioPlayer-BpRPS4-1.cjs +0 -1277
  373. package/dist/AudioPlayer-C12BjQBV.cjs +0 -997
  374. package/dist/AudioPlayer-CFeV8t-5.cjs +0 -936
  375. package/dist/AudioPlayer-Coly3q5R.js +0 -1278
  376. package/dist/AudioPlayer-CySJIyvL.js +0 -937
  377. package/dist/AudioPlayer-DMcG_c7L.js +0 -990
  378. package/dist/AudioPlayer-DcFKRJE_.js +0 -998
  379. package/dist/AudioPlayer-e8LfNoqO.js +0 -983
  380. package/dist/BrandColorsContext-565dDHd5.js +0 -660
  381. package/dist/BrandColorsContext-BcJbtkqn.cjs +0 -659
  382. package/dist/CodeBlock-7TTgmdGG.cjs +0 -2094
  383. package/dist/CodeBlock-BlcqlA9M.cjs +0 -2094
  384. package/dist/CodeBlock-Bnmeu5ez.cjs +0 -2094
  385. package/dist/CodeBlock-BtfPlbAI.js +0 -2078
  386. package/dist/CodeBlock-CIySIuYr.js +0 -2078
  387. package/dist/CodeBlock-CuPtUM-7.cjs +0 -2094
  388. package/dist/CodeBlock-D6ffWXgc.js +0 -2078
  389. package/dist/CodeBlock-D8dcwbit.cjs +0 -2094
  390. package/dist/CodeBlock-DMZrFnlw.cjs +0 -2094
  391. package/dist/CodeBlock-DlBehYN8.js +0 -2078
  392. package/dist/CodeBlock-DnYNI8rQ.js +0 -2078
  393. package/dist/CodeBlock-DvKWbSnE.cjs +0 -2094
  394. package/dist/CodeBlock-DwMCfkFY.js +0 -2078
  395. package/dist/CodeBlock-Dy6CNYyj.js +0 -2078
  396. package/dist/CodeBlock-U1pPOQI7.cjs +0 -2094
  397. package/dist/CodeBlock-f_GpNhEB.js +0 -2078
  398. package/dist/CodeBlock-oB6u8nI1.js +0 -2078
  399. package/dist/CodeBlock-tZC31B73.cjs +0 -2094
  400. package/dist/FeatureCard-CxC-7C-C.cjs +0 -300
  401. package/dist/FeatureCard-DbHWCb4E.js +0 -301
  402. package/dist/ImageWithFallback-CGtidP6B.cjs +0 -4542
  403. package/dist/ImageWithFallback-lsg3pdFg.js +0 -4508
  404. package/dist/LanguageSelector-B5YfbHra.js +0 -231
  405. package/dist/LanguageSelector-D6uacAIM.cjs +0 -230
  406. package/dist/LayoutContext-B45-e9DI.cjs +0 -93
  407. package/dist/LayoutContext-BAql6ZRY.js +0 -97
  408. package/dist/LayoutContext-Bav3UMEA.js +0 -94
  409. package/dist/LayoutContext-BvK-ggDa.cjs +0 -96
  410. package/dist/ThemeContext-BoH4NLfN.js +0 -734
  411. package/dist/ThemeContext-r69W20Xg.cjs +0 -733
  412. package/dist/VerifyEmailPage-COiyNl1y.js +0 -2825
  413. package/dist/VerifyEmailPage-CqKsR2v8.js +0 -2827
  414. package/dist/VerifyEmailPage-DjQKRlUS.cjs +0 -2824
  415. package/dist/VerifyEmailPage-s-1X3LDJ.cjs +0 -2826
  416. package/dist/XerticaOrbe-KL1RBHzw.cjs +0 -1354
  417. package/dist/XerticaOrbe-zwS1p2a8.js +0 -1355
  418. package/dist/XerticaProvider-6btlAlzc.js +0 -17
  419. package/dist/XerticaProvider-BNoNOxQ5.cjs +0 -16
  420. package/dist/XerticaProvider-BlY2limY.cjs +0 -38
  421. package/dist/XerticaProvider-cI9hSs27.cjs +0 -38
  422. package/dist/XerticaProvider-hSwhNQex.js +0 -39
  423. package/dist/alert-dialog-BOje--vD.js +0 -847
  424. package/dist/alert-dialog-BtEuQqrg.cjs +0 -870
  425. package/dist/breadcrumb-CqJ7bHY5.js +0 -161
  426. package/dist/breadcrumb-m9Hb2_XN.cjs +0 -177
  427. package/dist/components/assistant/xertica-assistant/hooks/index.d.ts +0 -6
  428. package/dist/components/assistant/xertica-assistant/hooks/use-assistant-conversations.d.ts +0 -21
  429. package/dist/components/assistant/xertica-assistant/hooks/use-assistant-messages.d.ts +0 -49
  430. package/dist/components/assistant/xertica-assistant/hooks/use-assistant-suggestions.d.ts +0 -16
  431. package/dist/components/blocks/audio-player/AudioPlayer.d.ts +0 -35
  432. package/dist/components/blocks/audio-player/index.d.ts +0 -1
  433. package/dist/components/blocks/document-editor/DocumentEditor.d.ts +0 -26
  434. package/dist/components/blocks/document-editor/index.d.ts +0 -1
  435. package/dist/components/blocks/podcast-player/PodcastPlayer.d.ts +0 -41
  436. package/dist/components/blocks/podcast-player/index.d.ts +0 -1
  437. package/dist/components/ui/chart/parts/chart-dashboard.d.ts +0 -113
  438. package/dist/components/ui/chart/parts/chart-metric.d.ts +0 -118
  439. package/dist/components/ui/chart/parts/chart-primitives.d.ts +0 -101
  440. package/dist/components/ui/chart/parts/chart-shared.d.ts +0 -20
  441. package/dist/components/ui/chart/parts/chart-utils.d.ts +0 -12
  442. package/dist/components/ui/chart/parts/index.d.ts +0 -5
  443. package/dist/dropdown-menu-BDB5CmQs.cjs +0 -247
  444. package/dist/dropdown-menu-DQidbKBD.js +0 -231
  445. package/dist/google-maps-loader-BFWp6VPd.js +0 -287
  446. package/dist/google-maps-loader-BKcdgFbu.cjs +0 -312
  447. package/dist/google-maps-loader-CumCNXeG.js +0 -312
  448. package/dist/google-maps-loader-eS3uQ5TA.cjs +0 -287
  449. package/dist/header-Cgy6vYPk.cjs +0 -731
  450. package/dist/header-DRlT4jgI.js +0 -715
  451. package/dist/header-Dux00SI4.cjs +0 -731
  452. package/dist/header-EkGKXPsD.js +0 -715
  453. package/dist/header-WfEywpyc.cjs +0 -731
  454. package/dist/header-tifNQn2U.js +0 -715
  455. package/dist/index-BhapVLVj.js +0 -8
  456. package/dist/index-D6fxYEY8.cjs +0 -7
  457. package/dist/index-DAIp0_HK.js +0 -8
  458. package/dist/index-DW5tYe26.js +0 -8
  459. package/dist/index-GA__GvnG.cjs +0 -7
  460. package/dist/input-2R4loU86.js +0 -127
  461. package/dist/input-DWANSKGb.cjs +0 -145
  462. package/dist/progress-DPtzoVV8.js +0 -175
  463. package/dist/progress-EeaoqqUs.cjs +0 -191
  464. package/dist/rich-text-editor-0mraWT5y.cjs +0 -2376
  465. package/dist/rich-text-editor-B-IkcPD0.js +0 -2874
  466. package/dist/rich-text-editor-B6jMRLzk.cjs +0 -1939
  467. package/dist/rich-text-editor-B8_oYcIR.js +0 -1730
  468. package/dist/rich-text-editor-B9UbSXNb.js +0 -1203
  469. package/dist/rich-text-editor-BYuRBNBU.js +0 -2373
  470. package/dist/rich-text-editor-Bb9pySTs.cjs +0 -2374
  471. package/dist/rich-text-editor-BcL6L3cm.cjs +0 -2374
  472. package/dist/rich-text-editor-BoVZYtTs.cjs +0 -2391
  473. package/dist/rich-text-editor-Bp3zQqMC.js +0 -2954
  474. package/dist/rich-text-editor-CMgSN_w2.js +0 -1189
  475. package/dist/rich-text-editor-CPV1lEPH.cjs +0 -1748
  476. package/dist/rich-text-editor-CeucBdIv.cjs +0 -2971
  477. package/dist/rich-text-editor-CoKqbCtu.cjs +0 -1799
  478. package/dist/rich-text-editor-Cw56T_mB.js +0 -2356
  479. package/dist/rich-text-editor-Cyt8qs2b.js +0 -1921
  480. package/dist/rich-text-editor-D6H84OcX.cjs +0 -1220
  481. package/dist/rich-text-editor-D76gD-QI.js +0 -2328
  482. package/dist/rich-text-editor-DKkokOnA.js +0 -1781
  483. package/dist/rich-text-editor-DNsdpN64.cjs +0 -2359
  484. package/dist/rich-text-editor-DfG8bCyY.js +0 -2358
  485. package/dist/rich-text-editor-Dxjw31Z4.js +0 -2341
  486. package/dist/rich-text-editor-DzP0Epmb.js +0 -2356
  487. package/dist/rich-text-editor-bRkNoeZY.cjs +0 -2891
  488. package/dist/rich-text-editor-lyYE2ZG5.cjs +0 -1207
  489. package/dist/rich-text-editor-skplNlBM.cjs +0 -2345
  490. package/dist/select-Bkbr0f-Z.cjs +0 -162
  491. package/dist/select-CvIVdX2n.js +0 -145
  492. package/dist/sidebar-CK_0ZQHj.cjs +0 -803
  493. package/dist/sidebar-CUuOvYhK.js +0 -787
  494. package/dist/sidebar-Djn5syhi.cjs +0 -786
  495. package/dist/sidebar-LluMXfam.js +0 -759
  496. package/dist/sidebar-_rT7rBMk.js +0 -787
  497. package/dist/slider-Bc5Hd0y1.js +0 -56
  498. package/dist/slider-N7hFFj6X.cjs +0 -73
  499. package/dist/tooltip-Ded96neP.cjs +0 -137
  500. package/dist/tooltip-HDOoD2-0.js +0 -120
  501. package/dist/use-audio-player-B31J-aqh.cjs +0 -187
  502. package/dist/use-audio-player-BkmEmj8Q.js +0 -185
  503. package/dist/use-audio-player-CLFTWFW1.cjs +0 -184
  504. package/dist/use-audio-player-CLLn00I6.js +0 -188
  505. package/dist/use-file-upload-BcjEo2S5.js +0 -404
  506. package/dist/use-file-upload-CRJR68Tj.cjs +0 -403
  507. package/dist/use-mobile-B0hNy_Y6.cjs +0 -4303
  508. package/dist/use-mobile-BXuYROXM.js +0 -4202
  509. package/dist/use-mobile-Bbd51ASU.cjs +0 -4392
  510. package/dist/use-mobile-Bk6CX-TC.js +0 -4359
  511. package/dist/use-mobile-BvYdisLP.js +0 -4202
  512. package/dist/use-mobile-BzuxjzNX.cjs +0 -4392
  513. package/dist/use-mobile-CG2-SdXV.cjs +0 -4235
  514. package/dist/use-mobile-CKb5pqTs.js +0 -4269
  515. package/dist/use-mobile-CYuAuGDl.js +0 -4202
  516. package/dist/use-mobile-CaENcqm-.js +0 -4508
  517. package/dist/use-mobile-CbrYgJGJ.js +0 -4203
  518. package/dist/use-mobile-Cd4xPrKq.cjs +0 -46
  519. package/dist/use-mobile-DMOvImGQ.cjs +0 -4542
  520. package/dist/use-mobile-DRB3BQgD.cjs +0 -4235
  521. package/dist/use-mobile-DZvv7QMR.js +0 -4359
  522. package/dist/use-mobile-DdI_TXam.cjs +0 -4235
  523. package/dist/use-mobile-DlceKf8a.js +0 -4359
  524. package/dist/use-mobile-DsOnow1o.cjs +0 -4236
  525. package/dist/use-mobile-Kcj6jSnK.cjs +0 -4392
  526. package/dist/use-mobile-bnKcua_i.js +0 -4202
  527. package/dist/use-mobile-j4w2Jrf1.js +0 -30
  528. package/dist/use-mobile-ncXBeE2z.cjs +0 -4235
  529. package/dist/use-rich-text-editor-DjiddBGv.js +0 -282
  530. package/dist/use-rich-text-editor-lpeswbCs.cjs +0 -281
  531. package/dist/xertica-assistant-BdiZag0h.js +0 -2187
  532. package/dist/xertica-assistant-DUBpmEgo.cjs +0 -2186
  533. package/dist/{rich-text-editor-DgF8s7xW.js → rich-text-editor-BmsjY03B.js} +26 -26
  534. package/dist/{rich-text-editor-mWoaSCE4.cjs → rich-text-editor-GS2kpTAK.cjs} +26 -26
package/bin/cli.ts CHANGED
@@ -1,1155 +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
- // ─────────────────────────────────────────────────────────────────────────────
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
- }
33
-
34
- async function readXerticaConfig(targetDir: string): Promise<XerticaConfig | null> {
35
- const configPath = path.join(targetDir, XERTICA_CONFIG_FILE);
36
- if (!(await fs.pathExists(configPath))) return null;
37
- try {
38
- return await fs.readJson(configPath) as XerticaConfig;
39
- } catch {
40
- return null;
41
- }
42
- }
43
-
44
- async function writeXerticaConfig(targetDir: string, config: Partial<XerticaConfig>): Promise<void> {
45
- const configPath = path.join(targetDir, XERTICA_CONFIG_FILE);
46
- const existing = (await readXerticaConfig(targetDir)) ?? { version: 1 as const, hasAssistant: false };
47
- await fs.writeJson(configPath, { ...existing, ...config, version: 1 }, { spaces: 2 });
48
- }
49
-
50
- const __filename = fileURLToPath(import.meta.url);
51
- const __dirname = path.dirname(__filename);
52
-
53
- // Read CLI version from package.json so it always matches the published one,
54
- // instead of hardcoding a literal that drifts on every version bump.
55
- const pkgJson = JSON.parse(
56
- fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf-8')
57
- ) as { version: string };
58
-
59
- // ─────────────────────────────────────────────────────────────────────────────
60
- // AuthGuard generator
61
- // Generates src/app/components/AuthGuard.tsx based on the selected features.
62
- // ─────────────────────────────────────────────────────────────────────────────
63
-
64
- function generateAuthGuard({
65
- hasLogin,
66
- hasHome,
67
- hasTemplate,
68
- hasAssistant,
69
- firstProtectedPath,
70
- }: {
71
- hasLogin: boolean;
72
- hasHome: boolean;
73
- hasTemplate: boolean;
74
- hasAssistant: boolean;
75
- firstProtectedPath: string;
76
- }): string {
77
- return `import React from 'react';
78
- import { Routes, Route, Navigate } from 'react-router-dom';
79
- import { useAuth } from '../context/AuthContext';
80
-
81
- // ─── Lazy page imports ────────────────────────────────────────────────────────
82
-
83
- ${hasLogin ? `const LoginPage = React.lazy(() => import('../../pages/LoginPage').then(m => ({ default: m.LoginPage })));
84
- const ForgotPasswordPage = React.lazy(() => import('../../pages/ForgotPasswordPage').then(m => ({ default: m.ForgotPasswordPage })));
85
- const VerifyEmailPage = React.lazy(() => import('../../pages/VerifyEmailPage').then(m => ({ default: m.VerifyEmailPage })));
86
- const ResetPasswordPage = React.lazy(() => import('../../pages/ResetPasswordPage').then(m => ({ default: m.ResetPasswordPage })));` : ''}
87
-
88
- ${hasHome ? `const HomePage = React.lazy(() => import('../../pages/HomePage').then(m => ({ default: m.HomePage })));` : ''}
89
- ${hasTemplate ? `const TemplatePage = React.lazy(() => import('../../pages/TemplatePage').then(m => ({ default: m.TemplatePage })));` : ''}
90
- ${hasAssistant ? `const AssistantPage = React.lazy(() => import('../../pages/AssistantPage').then(m => ({ default: m.AssistantPage })));` : ''}
91
-
92
- // ─── Route guards ─────────────────────────────────────────────────────────────
93
-
94
- function ProtectedRoute({ children }: { children: React.ReactNode }) {
95
- const { user, isLoading } = useAuth();
96
- if (isLoading) return null;
97
- if (!user) return <Navigate to="${hasLogin ? '/login' : firstProtectedPath}" replace />;
98
- return <>{children}</>;
99
- }
100
-
101
- ${hasLogin ? `function GuestRoute({ children }: { children: React.ReactNode }) {
102
- const { user, isLoading } = useAuth();
103
- if (isLoading) return null;
104
- if (user) return <Navigate to="${firstProtectedPath}" replace />;
105
- return <>{children}</>;
106
- }
107
-
108
- function LoginPageWithAuth() {
109
- const { login } = useAuth();
110
- return <LoginPage onLogin={login} />;
111
- }` : ''}
112
-
113
- // ─── Route tree ───────────────────────────────────────────────────────────────
114
-
115
- export function AuthGuard() {
116
- const { user } = useAuth();
117
-
118
- return (
119
- <div className="min-h-screen bg-muted overflow-x-hidden max-w-full">
120
- <Routes>
121
- ${hasLogin ? ` <Route path="/login" element={<GuestRoute><LoginPageWithAuth /></GuestRoute>} />
122
- <Route path="/forgot-password" element={<GuestRoute><ForgotPasswordPage /></GuestRoute>} />
123
- <Route path="/verify-email" element={<GuestRoute><VerifyEmailPage /></GuestRoute>} />
124
- <Route path="/reset-password" element={<GuestRoute><ResetPasswordPage /></GuestRoute>} />` : ''}
125
-
126
- ${hasHome ? ` <Route path="/home" element={<ProtectedRoute><HomePage /></ProtectedRoute>} />` : ''}
127
- ${hasTemplate ? ` <Route path="/template" element={<ProtectedRoute><TemplatePage /></ProtectedRoute>} />` : ''}
128
- ${hasAssistant ? ` <Route path="/assistente" element={<ProtectedRoute><AssistantPage /></ProtectedRoute>} />` : ''}
129
-
130
- <Route path="/" element={<Navigate to={user ? '${firstProtectedPath}' : '${hasLogin ? '/login' : firstProtectedPath}'} replace />} />
131
- <Route path="*" element={<Navigate to={user ? '${firstProtectedPath}' : '${hasLogin ? '/login' : firstProtectedPath}'} replace />} />
132
- </Routes>
133
- </div>
134
- );
135
- }
136
- `;
137
- }
138
-
139
- // ─────────────────────────────────────────────────────────────────────────────
140
- // Page generators
141
- // Generate page files that vary based on whether the assistant is included.
142
- // ─────────────────────────────────────────────────────────────────────────────
143
-
144
- function generateHomePage(hasAssistant: boolean): string {
145
- if (hasAssistant) {
146
- return `import React from 'react';
147
- import { XerticaAssistant, generateDemoResponse } from 'xertica-ui/assistant';
148
- import { useLayout } from 'xertica-ui/hooks';
149
- import { useNavigate } from 'react-router-dom';
150
- import { AppLayout } from '../app/components/AppLayout';
151
- import { HomeContent } from '../features/home';
152
- import { useAssistantConfig, getMockRichSuggestions, getMockFeedbackOptions } from '../features/assistant';
153
-
154
- /**
155
- * Home page — thin layout shell.
156
- *
157
- * Assistant config (suggestions, feedback options) is fetched via React Query.
158
- * To connect to a real API replace \`fetchAssistantConfig\` in
159
- * \`features/assistant/data/mock.ts\`.
160
- */
161
- export function HomePage() {
162
- const { assistenteExpanded, toggleAssistente } = useLayout();
163
- const navigate = useNavigate();
164
-
165
- const { data: assistantConfig } = useAssistantConfig();
166
-
167
- return (
168
- <AppLayout
169
- assistant={
170
- <XerticaAssistant
171
- isExpanded={assistenteExpanded}
172
- onToggle={toggleAssistente}
173
- defaultTab="chat"
174
- demoMode={true}
175
- userName="Ariel Santos"
176
- responseGenerator={generateDemoResponse}
177
- suggestions={assistantConfig?.suggestions}
178
- richSuggestions={assistantConfig?.richSuggestions ?? getMockRichSuggestions()}
179
- feedbackOptions={assistantConfig?.feedbackOptions ?? getMockFeedbackOptions()}
180
- showHistory={false}
181
- showFavorites={false}
182
- onNavigateSettings={() => navigate('/settings')}
183
- onNavigateFullPage={() => navigate('/assistente')}
184
- onEvaluation={(messageId, type, reason) => {
185
- // Wire your feedback persistence logic here
186
- console.log(\`Avaliação: \${type} na mensagem \${messageId}. Motivo: \${reason}\`);
187
- }}
188
- />
189
- }
190
- >
191
- <HomeContent />
192
- </AppLayout>
193
- );
194
- }
195
- `;
196
- }
197
-
198
- return `import React from 'react';
199
- import { AppLayout } from '../app/components/AppLayout';
200
- import { HomeContent } from '../features/home';
201
-
202
- /**
203
- * Home page — thin layout shell.
204
- */
205
- export function HomePage() {
206
- return (
207
- <AppLayout>
208
- <HomeContent />
209
- </AppLayout>
210
- );
211
- }
212
- `;
213
- }
214
-
215
- function generateTemplatePage(hasAssistant: boolean): string {
216
- if (hasAssistant) {
217
- return `import React from 'react';
218
- import { XerticaAssistant } from 'xertica-ui/assistant';
219
- import { useLayout } from 'xertica-ui/hooks';
220
- import { AppLayout } from '../app/components/AppLayout';
221
- import { TemplateContent } from '../features/template';
222
-
223
- /**
224
- * Template page — thin layout shell.
225
- *
226
- * Auth state is consumed from \`AuthContext\` via \`AppLayout\` — no props needed.
227
- */
228
- export function TemplatePage() {
229
- const { assistenteExpanded, toggleAssistente } = useLayout();
230
-
231
- return (
232
- <AppLayout
233
- assistant={
234
- <XerticaAssistant
235
- isExpanded={assistenteExpanded}
236
- onToggle={toggleAssistente}
237
- onEvaluation={(id, type, reason) => console.log('Feedback:', id, type, reason)}
238
- />
239
- }
240
- >
241
- <TemplateContent />
242
- </AppLayout>
243
- );
244
- }
245
- `;
246
- }
247
-
248
- return `import React from 'react';
249
- import { AppLayout } from '../app/components/AppLayout';
250
- import { TemplateContent } from '../features/template';
251
-
252
- /**
253
- * Template page — thin layout shell.
254
- *
255
- * Auth state is consumed from \`AuthContext\` via \`AppLayout\` — no props needed.
256
- */
257
- export function TemplatePage() {
258
- return (
259
- <AppLayout>
260
- <TemplateContent />
261
- </AppLayout>
262
- );
263
- }
264
- `;
265
- }
266
-
267
- const program = new Command();
268
-
269
- program
270
- .name('xertica-ui')
271
- .description('CLI to initialize Xertica UI projects')
272
- .version(pkgJson.version);
273
-
274
- program
275
- .command('init')
276
- .description('Initialize a new Xertica UI project')
277
- .argument('[directory]', 'Directory to initialize in', '.')
278
- .action(async directory => {
279
- const targetDir = path.resolve(process.cwd(), directory);
280
- const templatesDir = path.resolve(__dirname, '../templates');
281
-
282
- console.log(chalk.blue(`🚀 Welcome to Xertica UI CLI! ${chalk.dim(`v${pkgJson.version}`)}`));
283
-
284
- const response = await prompts([
285
- {
286
- type: 'multiselect',
287
- name: 'pages',
288
- message: 'Which pages/templates to include?',
289
- choices: [
290
- {
291
- title: 'Login Page (+ Forgot / Verify / Reset Password)',
292
- value: 'login',
293
- selected: true,
294
- },
295
- { title: 'Home Page', value: 'home', selected: true },
296
- { title: 'Template Page (components showcase)', value: 'template', selected: true },
297
- ],
298
- },
299
- {
300
- type: 'multiselect',
301
- name: 'languages',
302
- message: 'Which languages should the app support?',
303
- instructions: false,
304
- hint: 'Select at least 1. Single-language apps auto-hide the LanguageSelector.',
305
- min: 1,
306
- choices: SUPPORTED_LANGUAGES.map(l => ({
307
- title: l.label,
308
- value: l.code,
309
- selected: true,
310
- })),
311
- },
312
- {
313
- type: 'select',
314
- name: 'theme',
315
- message: 'Select the default color theme for your project:',
316
- choices: colorThemes.map(t => ({
317
- title: t.name,
318
- description: t.description,
319
- value: t.id,
320
- })),
321
- initial: 0,
322
- },
323
- {
324
- type: 'confirm',
325
- name: 'hasAssistant',
326
- message: 'Include AI Assistant? (XerticaAssistant chat page + sidebar variant)',
327
- initial: true,
328
- },
329
- {
330
- type: 'confirm',
331
- name: 'install',
332
- message: 'Install dependencies automatically?',
333
- initial: true,
334
- },
335
- ]);
336
-
337
- // Abort if the user cancelled any prompt (prompts returns undefined on Ctrl+C)
338
- if (!response.pages || !response.languages || !response.theme) return;
339
-
340
- const spinner = ora('Initializing project...').start();
341
-
342
- try {
343
- await fs.ensureDir(targetDir);
344
-
345
- const pages = response.pages || [];
346
- const hasLogin = pages.includes('login');
347
- const hasHome = pages.includes('home');
348
- const hasTemplate = pages.includes('template');
349
- const hasAssistant = response.hasAssistant ?? true;
350
-
351
- // Resolve selected languages — fall back to all defaults if the user
352
- // somehow ended up with an empty array (the prompt's min:1 should prevent
353
- // this, but we defend defensively).
354
- const selectedLanguages: string[] =
355
- Array.isArray(response.languages) && response.languages.length > 0
356
- ? response.languages
357
- : DEFAULT_SELECTION;
358
-
359
- // 1. Copy root config files
360
- const rootFilesToCopy = [
361
- 'index.html',
362
- 'vite.config.ts',
363
- 'tsconfig.json',
364
- 'tsconfig.node.json',
365
- 'postcss.config.js',
366
- 'vite-env.d.ts',
367
- 'eslint.config.js',
368
- '.env.example',
369
- 'guidelines',
370
- 'CLAUDE.md',
371
- ];
372
-
373
- for (const file of rootFilesToCopy) {
374
- const srcPath = path.join(templatesDir, file);
375
- if (await fs.pathExists(srcPath)) {
376
- await fs.copy(srcPath, path.join(targetDir, file));
377
- }
378
- }
379
-
380
- // 2. Copy package.json
381
- const pkgTemplatePath = path.join(templatesDir, 'package.json');
382
- if (await fs.pathExists(pkgTemplatePath)) {
383
- const pkgContent = await fs.readJson(pkgTemplatePath);
384
- const projectName = path.basename(targetDir) || 'my-xertica-app';
385
- pkgContent.name = projectName.toLowerCase().replace(/[^a-z0-9-]/g, '-');
386
- await fs.writeJson(path.join(targetDir, 'package.json'), pkgContent, { spaces: 2 });
387
- }
388
-
389
- // 3. Copy src/main.tsx
390
- await fs.copy(
391
- path.join(templatesDir, 'src', 'main.tsx'),
392
- path.join(targetDir, 'src', 'main.tsx')
393
- );
394
-
395
- // 4. Generate src/app/App.tsx with the user's language selection
396
- // (instead of copying the static template, we inject `availableLanguages`)
397
- await fs.ensureDir(path.join(targetDir, 'src', 'app'));
398
- await fs.writeFile(
399
- path.join(targetDir, 'src', 'app', 'App.tsx'),
400
- generateAppTsx(selectedLanguages)
401
- );
402
-
403
- // 5. Copy src/app/components/AppLayout.tsx (always needed)
404
- await fs.ensureDir(path.join(targetDir, 'src', 'app', 'components'));
405
- await fs.copy(
406
- path.join(templatesDir, 'src', 'app', 'components', 'AppLayout.tsx'),
407
- path.join(targetDir, 'src', 'app', 'components', 'AppLayout.tsx')
408
- );
409
-
410
- // 6. Copy src/shared/ (always needed — auth helpers, navigation config, types)
411
- await fs.copy(
412
- path.join(templatesDir, 'src', 'shared'),
413
- path.join(targetDir, 'src', 'shared')
414
- );
415
-
416
- // 6.1 Generate i18n.ts with only the imports/resources for selected languages
417
- await fs.writeFile(
418
- path.join(targetDir, 'src', 'i18n.ts'),
419
- generateI18nFile(selectedLanguages)
420
- );
421
-
422
- // 6.2 Copy only the selected locale JSON files (no orphan locales)
423
- await syncLocaleFiles(templatesDir, targetDir, selectedLanguages, { pruneOthers: true });
424
-
425
- // 6.3 Persist the language selection so `update` can remember it
426
- await writeLanguagesConfig(targetDir, selectedLanguages);
427
-
428
- // 6.5 Persist project feature flags (.xertica.json)
429
- await writeXerticaConfig(targetDir, { hasAssistant });
430
-
431
- // 6.4 Copy context
432
- await fs.ensureDir(path.join(targetDir, 'src', 'app', 'context'));
433
- await fs.copy(
434
- path.join(templatesDir, 'src', 'app', 'context', 'AuthContext.tsx'),
435
- path.join(targetDir, 'src', 'app', 'context', 'AuthContext.tsx')
436
- );
437
-
438
- // 7. Copy features based on selections
439
- if (hasLogin) {
440
- await fs.copy(
441
- path.join(templatesDir, 'src', 'features', 'auth'),
442
- path.join(targetDir, 'src', 'features', 'auth')
443
- );
444
- }
445
- if (hasHome) {
446
- await fs.copy(
447
- path.join(templatesDir, 'src', 'features', 'home'),
448
- path.join(targetDir, 'src', 'features', 'home')
449
- );
450
- }
451
- if (hasTemplate) {
452
- await fs.copy(
453
- path.join(templatesDir, 'src', 'features', 'template'),
454
- path.join(targetDir, 'src', 'features', 'template')
455
- );
456
- }
457
- // Copy assistant feature only if selected
458
- if (hasAssistant) {
459
- await fs.copy(
460
- path.join(templatesDir, 'src', 'features', 'assistant'),
461
- path.join(targetDir, 'src', 'features', 'assistant')
462
- );
463
- }
464
-
465
- // 8. Copy pages based on selections
466
- await fs.ensureDir(path.join(targetDir, 'src', 'pages'));
467
-
468
- const pagesToCopy: string[] = [];
469
- if (hasLogin)
470
- pagesToCopy.push(
471
- 'LoginPage.tsx',
472
- 'ForgotPasswordPage.tsx',
473
- 'VerifyEmailPage.tsx',
474
- 'ResetPasswordPage.tsx'
475
- );
476
- if (hasHome) pagesToCopy.push('HomePage.tsx');
477
- if (hasTemplate) pagesToCopy.push('TemplatePage.tsx');
478
- if (hasAssistant) pagesToCopy.push('AssistantPage.tsx');
479
-
480
- for (const pageFile of pagesToCopy) {
481
- // HomePage and TemplatePage are generated (they vary by hasAssistant)
482
- if (pageFile === 'HomePage.tsx') {
483
- await fs.writeFile(
484
- path.join(targetDir, 'src', 'pages', 'HomePage.tsx'),
485
- generateHomePage(hasAssistant)
486
- );
487
- continue;
488
- }
489
- if (pageFile === 'TemplatePage.tsx') {
490
- await fs.writeFile(
491
- path.join(targetDir, 'src', 'pages', 'TemplatePage.tsx'),
492
- generateTemplatePage(hasAssistant)
493
- );
494
- continue;
495
- }
496
- const src = path.join(templatesDir, 'src', 'pages', pageFile);
497
- if (await fs.pathExists(src)) {
498
- await fs.copy(src, path.join(targetDir, 'src', 'pages', pageFile));
499
- }
500
- }
501
-
502
- // 9. Generate AuthGuard.tsx based on selected pages
503
- const firstProtectedPath = hasHome ? '/home' : hasTemplate ? '/template' : '/login';
504
- const authGuardContent = generateAuthGuard({ hasLogin, hasHome, hasTemplate, hasAssistant, firstProtectedPath });
505
-
506
- await fs.writeFile(
507
- path.join(targetDir, 'src', 'app', 'components', 'AuthGuard.tsx'),
508
- authGuardContent
509
- );
510
-
511
- // 10. Generate theme tokens
512
- const selectedTheme = colorThemes.find(t => t.id === response.theme) || colorThemes[0];
513
- const tokensDir = path.join(targetDir, 'src', 'styles', 'xertica');
514
- await fs.ensureDir(tokensDir);
515
- await fs.copy(
516
- path.join(templatesDir, 'src', 'styles', 'index.css'),
517
- path.join(targetDir, 'src', 'styles', 'index.css')
518
- );
519
- await fs.writeFile(path.join(tokensDir, 'tokens.css'), generateTokensCss(selectedTheme));
520
-
521
- spinner.succeed('Project initialized successfully!');
522
-
523
- if (response.install) {
524
- const installSpinner = ora('Installing dependencies...').start();
525
- await execa('npm', ['install'], { cwd: targetDir });
526
- installSpinner.succeed('Dependencies installed!');
527
- }
528
-
529
- console.log(chalk.green('\n✅ Done! Your Xertica UI project is ready.'));
530
- console.log(chalk.cyan(`\n cd ${directory}`));
531
- if (!response.install) {
532
- console.log(chalk.cyan(' npm install'));
533
- }
534
- console.log(chalk.cyan(' npm run dev'));
535
- console.log();
536
- console.log(chalk.gray(' Components are imported from the xertica-ui package.'));
537
- console.log(chalk.gray(' Customize the theme in src/styles/xertica/tokens.css'));
538
- const langLabels = SUPPORTED_LANGUAGES.filter(l => selectedLanguages.includes(l.code))
539
- .map(l => l.label)
540
- .join(', ');
541
- console.log(
542
- chalk.gray(
543
- ` Languages: ${langLabels}${selectedLanguages.length === 1 ? ' (monolingual — LanguageSelector hidden)' : ''}`
544
- )
545
- );
546
- console.log(
547
- chalk.gray(' To add/remove languages later: npx xertica-ui update → Languages')
548
- );
549
- console.log(
550
- chalk.gray(` AI Assistant: ${hasAssistant ? 'included (/assistente)' : 'not included'}`)
551
- );
552
- if (!hasAssistant) {
553
- console.log(chalk.gray(' To add the assistant later: npx xertica-ui update → Assistant'));
554
- }
555
- } catch (error) {
556
- spinner.fail('Failed to initialize project');
557
- console.error(error);
558
- }
559
- });
560
-
561
- program
562
- .command('update')
563
- .alias('update-theme')
564
- .description('Update theme or project files to the latest version')
565
- .action(async () => {
566
- const targetDir = process.cwd();
567
-
568
- console.log(chalk.blue(`🔧 Xertica UI CLI ${chalk.dim(`v${pkgJson.version}`)}`));
569
-
570
- const currentConfig = await readXerticaConfig(targetDir);
571
-
572
- const { updateType } = await prompts({
573
- type: 'select',
574
- name: 'updateType',
575
- message: 'What do you want to update?',
576
- choices: [
577
- {
578
- title: 'Theme only',
579
- description: 'Change the color tokens (tokens.css)',
580
- value: 'theme',
581
- },
582
- {
583
- title: 'Languages',
584
- description: 'Add or remove supported languages (pt-BR, en, es, )',
585
- value: 'languages',
586
- },
587
- {
588
- title: 'Assistant',
589
- description: currentConfig?.hasAssistant
590
- ? 'Remove the AI Assistant from your project'
591
- : 'Add the AI Assistant to your project',
592
- value: 'assistant',
593
- },
594
- {
595
- title: 'Project files',
596
- description: 'Update app shell, shared, features and pages to a specific version',
597
- value: 'project',
598
- },
599
- ],
600
- });
601
-
602
- if (!updateType) return;
603
-
604
- // ── Theme update ─────────────────────────────────────────────────────────
605
- if (updateType === 'theme') {
606
- const { theme } = await prompts({
607
- type: 'select',
608
- name: 'theme',
609
- message: 'Select the new color theme:',
610
- choices: colorThemes.map(t => ({
611
- title: t.name,
612
- description: t.description,
613
- value: t.id,
614
- })),
615
- initial: 0,
616
- });
617
-
618
- if (!theme) return;
619
-
620
- const spinner = ora('Updating theme...').start();
621
- try {
622
- const tokensPath = path.join(targetDir, 'src', 'styles', 'xertica', 'tokens.css');
623
- const selectedTheme = colorThemes.find(t => t.id === theme);
624
- if (selectedTheme) {
625
- await fs.ensureDir(path.dirname(tokensPath));
626
- await fs.writeFile(tokensPath, generateTokensCss(selectedTheme));
627
- spinner.succeed(`Theme updated to "${selectedTheme.name}" successfully!`);
628
- } else {
629
- spinner.fail('Theme not found.');
630
- }
631
- } catch (error) {
632
- spinner.fail('Failed to update theme');
633
- console.error(error);
634
- }
635
- return;
636
- }
637
-
638
- // ── Languages update (add / remove) ──────────────────────────────────────
639
- if (updateType === 'languages') {
640
- // Resolve current selection — read from .languages.json if present,
641
- // else inspect the locales/ folder to infer it (for projects scaffolded
642
- // before this feature shipped).
643
- const persistedCodes = await readLanguagesConfig(targetDir);
644
- let currentCodes: string[] = persistedCodes ?? [];
645
- if (currentCodes.length === 0) {
646
- const localesDir = path.join(targetDir, 'src', 'locales');
647
- if (await fs.pathExists(localesDir)) {
648
- const entries = await fs.readdir(localesDir);
649
- // Accept both the new folder layout (locales/<code>/) and the legacy
650
- // flat layout (locales/<code>.json) when inferring the current set.
651
- currentCodes = SUPPORTED_LANGUAGES.filter(
652
- l => entries.includes(l.jsonFile) || entries.includes(`${l.jsonFile}.json`)
653
- ).map(l => l.code);
654
- }
655
- if (currentCodes.length === 0) currentCodes = DEFAULT_SELECTION;
656
- }
657
-
658
- console.log(
659
- chalk.cyan(
660
- `\nCurrent languages: ${SUPPORTED_LANGUAGES.filter(l => currentCodes.includes(l.code))
661
- .map(l => l.label)
662
- .join(', ') || '(none)'}\n`
663
- )
664
- );
665
-
666
- const { newCodes } = await prompts({
667
- type: 'multiselect',
668
- name: 'newCodes',
669
- message: 'Select the languages this project should support:',
670
- instructions: false,
671
- hint: 'Press SPACE to toggle. At least 1 required. Single-language apps auto-hide the LanguageSelector.',
672
- min: 1,
673
- choices: SUPPORTED_LANGUAGES.map(l => ({
674
- title: l.label,
675
- value: l.code,
676
- selected: currentCodes.includes(l.code),
677
- })),
678
- });
679
-
680
- if (!Array.isArray(newCodes) || newCodes.length === 0) {
681
- console.log(chalk.gray('Update cancelled.'));
682
- return;
683
- }
684
-
685
- // Compute add/remove diff for the user-facing summary
686
- const toAdd = newCodes.filter((c: string) => !currentCodes.includes(c));
687
- const toRemove = currentCodes.filter(c => !newCodes.includes(c));
688
-
689
- if (toAdd.length === 0 && toRemove.length === 0) {
690
- console.log(chalk.gray('No changes — selection matches the current set.'));
691
- return;
692
- }
693
-
694
- const summary: string[] = [];
695
- if (toAdd.length > 0)
696
- summary.push(chalk.green(` + ${toAdd.join(', ')}`));
697
- if (toRemove.length > 0)
698
- summary.push(chalk.red(` - ${toRemove.join(', ')}`));
699
- console.log(`\n${summary.join('\n')}\n`);
700
-
701
- const { confirmed } = await prompts({
702
- type: 'confirm',
703
- name: 'confirmed',
704
- message: chalk.yellow(
705
- `⚠️ This will regenerate src/app/App.tsx and src/i18n.ts (preserving language-only changes). Continue?`
706
- ),
707
- initial: true,
708
- });
709
- if (!confirmed) {
710
- console.log(chalk.gray('Update cancelled.'));
711
- return;
712
- }
713
-
714
- const spinner = ora('Updating languages...').start();
715
- try {
716
- // The freshly-installed library may not be present in this flow, so we
717
- // read locale JSON sources from `node_modules/xertica-ui/templates`
718
- // (installed when the project was created) — fallback to package
719
- // directory lookup.
720
- const installedTemplatesDir = path.join(
721
- targetDir,
722
- 'node_modules',
723
- 'xertica-ui',
724
- 'templates'
725
- );
726
- const templatesSourceDir = (await fs.pathExists(installedTemplatesDir))
727
- ? installedTemplatesDir
728
- : path.resolve(__dirname, '../templates');
729
-
730
- // 1) Sync locale JSON files: copy newly-added, prune removed
731
- const { copied, removed } = await syncLocaleFiles(
732
- templatesSourceDir,
733
- targetDir,
734
- newCodes,
735
- { pruneOthers: true }
736
- );
737
-
738
- // 2) Regenerate i18n.ts so imports/resources reflect the new set
739
- await fs.writeFile(
740
- path.join(targetDir, 'src', 'i18n.ts'),
741
- generateI18nFile(newCodes)
742
- );
743
-
744
- // 3) Regenerate App.tsx so the `availableLanguages` prop matches
745
- await fs.writeFile(
746
- path.join(targetDir, 'src', 'app', 'App.tsx'),
747
- generateAppTsx(newCodes)
748
- );
749
-
750
- // 4) Persist the new selection
751
- await writeLanguagesConfig(targetDir, newCodes);
752
-
753
- spinner.succeed('Languages updated successfully!');
754
-
755
- if (copied.length > 0) console.log(chalk.green(` Copied: ${copied.join(', ')}`));
756
- if (removed.length > 0) console.log(chalk.red(` Removed: ${removed.join(', ')}`));
757
- if (newCodes.length === 1) {
758
- console.log(
759
- chalk.gray(
760
- ` Project is now monolingual — the LanguageSelector will auto-hide.`
761
- )
762
- );
763
- }
764
- } catch (error) {
765
- spinner.fail('Failed to update languages');
766
- console.error(error);
767
- }
768
- return;
769
- }
770
-
771
- // ── Assistant add / remove ────────────────────────────────────────────────
772
- if (updateType === 'assistant') {
773
- // Determine current state: prefer persisted config, fall back to file presence
774
- // (handles projects scaffolded before .xertica.json existed).
775
- let currentlyHas: boolean;
776
- if (currentConfig !== null) {
777
- currentlyHas = currentConfig.hasAssistant;
778
- } else {
779
- const assistantFeatureDir = path.join(targetDir, 'src', 'features', 'assistant');
780
- const assistantPage = path.join(targetDir, 'src', 'pages', 'AssistantPage.tsx');
781
- currentlyHas =
782
- (await fs.pathExists(assistantFeatureDir)) || (await fs.pathExists(assistantPage));
783
- // Persist the inferred state so future runs don't need to infer again
784
- await writeXerticaConfig(targetDir, { hasAssistant: currentlyHas });
785
- }
786
-
787
- console.log(
788
- chalk.cyan(
789
- `\nAI Assistant is currently: ${currentlyHas ? chalk.green('enabled') : chalk.red('disabled')}\n`
790
- )
791
- );
792
-
793
- const { action } = await prompts({
794
- type: 'select',
795
- name: 'action',
796
- message: currentlyHas
797
- ? 'Remove the AI Assistant from your project?'
798
- : 'Add the AI Assistant to your project?',
799
- choices: currentlyHas
800
- ? [
801
- { title: 'Remove assistant', description: 'Deletes AssistantPage and assistant feature files', value: 'remove' },
802
- { title: 'Cancel', value: 'cancel' },
803
- ]
804
- : [
805
- { title: 'Add assistant', description: 'Copies AssistantPage and assistant feature files', value: 'add' },
806
- { title: 'Cancel', value: 'cancel' },
807
- ],
808
- });
809
-
810
- if (!action || action === 'cancel') {
811
- console.log(chalk.gray('Update cancelled.'));
812
- return;
813
- }
814
-
815
- const { confirmed } = await prompts({
816
- type: 'confirm',
817
- name: 'confirmed',
818
- message: chalk.yellow(
819
- action === 'remove'
820
- ? '⚠️ This will delete src/features/assistant/ and src/pages/AssistantPage.tsx and regenerate AuthGuard.tsx. Continue?'
821
- : '⚠️ This will copy src/features/assistant/ and src/pages/AssistantPage.tsx and regenerate AuthGuard.tsx. Continue?'
822
- ),
823
- initial: action === 'add',
824
- });
825
-
826
- if (!confirmed) {
827
- console.log(chalk.gray('Update cancelled.'));
828
- return;
829
- }
830
-
831
- const spinner = ora(action === 'add' ? 'Adding assistant...' : 'Removing assistant...').start();
832
-
833
- try {
834
- const installedTemplatesDir = path.join(targetDir, 'node_modules', 'xertica-ui', 'templates');
835
- const templatesSourceDir = (await fs.pathExists(installedTemplatesDir))
836
- ? installedTemplatesDir
837
- : path.resolve(__dirname, '../templates');
838
-
839
- // Infer current page set from the pages directory
840
- const pagesDir = path.join(targetDir, 'src', 'pages');
841
- const existingPages = (await fs.pathExists(pagesDir)) ? await fs.readdir(pagesDir) : [];
842
- const hasLogin = existingPages.includes('LoginPage.tsx');
843
- const hasHome = existingPages.includes('HomePage.tsx');
844
- const hasTemplate = existingPages.includes('TemplatePage.tsx');
845
- const firstProtectedPath = hasHome ? '/home' : hasTemplate ? '/template' : '/login';
846
-
847
- // Read persisted language selection so AuthGuard can be regenerated correctly
848
- const persistedCodes = await readLanguagesConfig(targetDir);
849
- const selectedCodes =
850
- persistedCodes && persistedCodes.length > 0 ? persistedCodes : DEFAULT_SELECTION;
851
-
852
- if (action === 'add') {
853
- // Copy assistant feature
854
- await fs.copy(
855
- path.join(templatesSourceDir, 'src', 'features', 'assistant'),
856
- path.join(targetDir, 'src', 'features', 'assistant'),
857
- { overwrite: true }
858
- );
859
- // Copy AssistantPage
860
- await fs.copy(
861
- path.join(templatesSourceDir, 'src', 'pages', 'AssistantPage.tsx'),
862
- path.join(targetDir, 'src', 'pages', 'AssistantPage.tsx'),
863
- { overwrite: true }
864
- );
865
- } else {
866
- // Remove assistant feature
867
- await fs.remove(path.join(targetDir, 'src', 'features', 'assistant'));
868
- await fs.remove(path.join(targetDir, 'src', 'pages', 'AssistantPage.tsx'));
869
- }
870
-
871
- // Regenerate pages and AuthGuard reflecting the new assistant state
872
- const newHasAssistant = action === 'add';
873
-
874
- if (hasHome) {
875
- await fs.writeFile(
876
- path.join(targetDir, 'src', 'pages', 'HomePage.tsx'),
877
- generateHomePage(newHasAssistant)
878
- );
879
- }
880
- if (hasTemplate) {
881
- await fs.writeFile(
882
- path.join(targetDir, 'src', 'pages', 'TemplatePage.tsx'),
883
- generateTemplatePage(newHasAssistant)
884
- );
885
- }
886
-
887
- await fs.writeFile(
888
- path.join(targetDir, 'src', 'app', 'components', 'AuthGuard.tsx'),
889
- generateAuthGuard({
890
- hasLogin,
891
- hasHome,
892
- hasTemplate,
893
- hasAssistant: newHasAssistant,
894
- firstProtectedPath,
895
- })
896
- );
897
-
898
- // Persist the updated flag
899
- await writeXerticaConfig(targetDir, { hasAssistant: newHasAssistant });
900
-
901
- spinner.succeed(
902
- action === 'add'
903
- ? 'AI Assistant added successfully!'
904
- : 'AI Assistant removed successfully!'
905
- );
906
-
907
- if (action === 'add') {
908
- console.log(chalk.gray('\n Route /assistente is now available.'));
909
- console.log(chalk.gray(' Configure your Gemini API key in VITE_GEMINI_API_KEY.'));
910
- } else {
911
- console.log(chalk.gray('\n Assistant files removed and AuthGuard updated.'));
912
- }
913
- } catch (error) {
914
- spinner.fail('Failed to update assistant');
915
- console.error(error);
916
- }
917
- return;
918
- }
919
-
920
- // ── Project files update ──────────────────────────────────────────────────
921
- const { versionType } = await prompts({
922
- type: 'select',
923
- name: 'versionType',
924
- message: 'Which version do you want to update to?',
925
- choices: [
926
- { title: 'Latest', description: 'Install the latest published version', value: 'latest' },
927
- {
928
- title: 'Specific version',
929
- description: 'Enter a version number (e.g. 2.0.2)',
930
- value: 'specific',
931
- },
932
- ],
933
- });
934
-
935
- if (!versionType) return;
936
-
937
- let targetVersion = 'latest';
938
- if (versionType === 'specific') {
939
- const { version } = await prompts({
940
- type: 'text',
941
- name: 'version',
942
- message: 'Enter the version (e.g. 2.0.2):',
943
- validate: v =>
944
- /^\d+\.\d+\.\d+/.test(v.trim()) ? true : 'Enter a valid semver (e.g. 2.0.2)',
945
- });
946
- if (!version) return;
947
- targetVersion = version.trim();
948
- }
949
-
950
- const { filesToUpdate } = await prompts({
951
- type: 'multiselect',
952
- name: 'filesToUpdate',
953
- message: 'Select which parts of the project to update:',
954
- choices: [
955
- {
956
- title: 'App shell (src/app/)',
957
- description: 'App.tsx, AppLayout.tsx',
958
- value: 'app',
959
- selected: true,
960
- },
961
- {
962
- title: 'Shared utilities (src/shared/)',
963
- description: 'auth.ts, navigation.ts, types',
964
- value: 'shared',
965
- selected: true,
966
- },
967
- {
968
- title: 'Features (src/features/)',
969
- description: 'auth, home, template UI components',
970
- value: 'features',
971
- selected: true,
972
- },
973
- {
974
- title: 'Pages (src/pages/)',
975
- description: 'Thin page wrapper components',
976
- value: 'pages',
977
- selected: true,
978
- },
979
- {
980
- title: 'Root config files',
981
- description: 'vite.config.ts, tsconfig.json, etc.',
982
- value: 'config',
983
- selected: false,
984
- },
985
- ],
986
- });
987
-
988
- if (!filesToUpdate || filesToUpdate.length === 0) return;
989
-
990
- const { confirmed } = await prompts({
991
- type: 'confirm',
992
- name: 'confirmed',
993
- message: chalk.yellow(
994
- `⚠️ This will overwrite the selected files. Local changes will be lost. Continue?`
995
- ),
996
- initial: false,
997
- });
998
-
999
- if (!confirmed) {
1000
- console.log(chalk.gray('Update cancelled.'));
1001
- return;
1002
- }
1003
-
1004
- const spinner = ora(`Installing xertica-ui@${targetVersion}...`).start();
1005
-
1006
- try {
1007
- // Install the target version in the consumer project
1008
- await execa('npm', ['install', `xertica-ui@${targetVersion}`], { cwd: targetDir });
1009
- spinner.text = 'Copying updated files...';
1010
-
1011
- // Templates now come from the freshly installed version
1012
- const updatedTemplatesDir = path.join(targetDir, 'node_modules', 'xertica-ui', 'templates');
1013
-
1014
- if (filesToUpdate.includes('app')) {
1015
- // AppLayout is always safe to overwrite (no per-project config baked in)
1016
- await fs.copy(
1017
- path.join(updatedTemplatesDir, 'src', 'app', 'components', 'AppLayout.tsx'),
1018
- path.join(targetDir, 'src', 'app', 'components', 'AppLayout.tsx'),
1019
- { overwrite: true }
1020
- );
1021
-
1022
- // For App.tsx and i18n.ts we must preserve the user's language selection.
1023
- // Read it from .languages.json (or fall back to inspecting locales/ for
1024
- // projects scaffolded before the file existed).
1025
- const persistedCodes = await readLanguagesConfig(targetDir);
1026
- let selectedCodes: string[] = persistedCodes ?? [];
1027
- if (selectedCodes.length === 0) {
1028
- const localesDir = path.join(targetDir, 'src', 'locales');
1029
- if (await fs.pathExists(localesDir)) {
1030
- const entries = await fs.readdir(localesDir);
1031
- // Accept both the new folder layout and the legacy flat layout
1032
- selectedCodes = SUPPORTED_LANGUAGES.filter(
1033
- l => entries.includes(l.jsonFile) || entries.includes(`${l.jsonFile}.json`)
1034
- ).map(l => l.code);
1035
- }
1036
- if (selectedCodes.length === 0) selectedCodes = DEFAULT_SELECTION;
1037
- // Persist the inferred selection so future updates have it cached
1038
- await writeLanguagesConfig(targetDir, selectedCodes);
1039
- }
1040
-
1041
- // Regenerate App.tsx and i18n.ts honoring the persisted language set
1042
- await fs.writeFile(
1043
- path.join(targetDir, 'src', 'app', 'App.tsx'),
1044
- generateAppTsx(selectedCodes)
1045
- );
1046
- await fs.writeFile(
1047
- path.join(targetDir, 'src', 'i18n.ts'),
1048
- generateI18nFile(selectedCodes)
1049
- );
1050
-
1051
- // Refresh locale JSON files for the selected languages (keys grow over
1052
- // library updates) — but prune any orphans from prior selections.
1053
- await syncLocaleFiles(updatedTemplatesDir, targetDir, selectedCodes, {
1054
- pruneOthers: true,
1055
- });
1056
-
1057
- // Regenerate AuthGuard preserving the current page set and assistant flag
1058
- const projectConfig = await readXerticaConfig(targetDir);
1059
- const pagesDir = path.join(targetDir, 'src', 'pages');
1060
- const existingPages = (await fs.pathExists(pagesDir)) ? await fs.readdir(pagesDir) : [];
1061
- const hasLoginP = existingPages.includes('LoginPage.tsx');
1062
- const hasHomeP = existingPages.includes('HomePage.tsx');
1063
- const hasTemplateP = existingPages.includes('TemplatePage.tsx');
1064
- const hasAssistantP = projectConfig?.hasAssistant ?? existingPages.includes('AssistantPage.tsx');
1065
- const firstProtectedP = hasHomeP ? '/home' : hasTemplateP ? '/template' : '/login';
1066
- await fs.writeFile(
1067
- path.join(targetDir, 'src', 'app', 'components', 'AuthGuard.tsx'),
1068
- generateAuthGuard({
1069
- hasLogin: hasLoginP,
1070
- hasHome: hasHomeP,
1071
- hasTemplate: hasTemplateP,
1072
- hasAssistant: hasAssistantP,
1073
- firstProtectedPath: firstProtectedP,
1074
- })
1075
- );
1076
- }
1077
-
1078
- if (filesToUpdate.includes('shared')) {
1079
- await fs.copy(
1080
- path.join(updatedTemplatesDir, 'src', 'shared'),
1081
- path.join(targetDir, 'src', 'shared'),
1082
- { overwrite: true }
1083
- );
1084
- }
1085
-
1086
- if (filesToUpdate.includes('features')) {
1087
- // Only update feature directories that already exist in the project.
1088
- // 'assistant' is only present if it was included during init (or added via update → Assistant).
1089
- for (const feature of ['auth', 'home', 'template', 'assistant']) {
1090
- const destFeature = path.join(targetDir, 'src', 'features', feature);
1091
- const srcFeature = path.join(updatedTemplatesDir, 'src', 'features', feature);
1092
- if ((await fs.pathExists(destFeature)) && (await fs.pathExists(srcFeature))) {
1093
- await fs.copy(srcFeature, destFeature, { overwrite: true });
1094
- }
1095
- }
1096
- }
1097
-
1098
- if (filesToUpdate.includes('pages')) {
1099
- const pagesDir = path.join(targetDir, 'src', 'pages');
1100
- const srcPagesDir = path.join(updatedTemplatesDir, 'src', 'pages');
1101
- if ((await fs.pathExists(pagesDir)) && (await fs.pathExists(srcPagesDir))) {
1102
- const projectCfg = await readXerticaConfig(targetDir);
1103
- const existingPages = await fs.readdir(pagesDir);
1104
- const assistantEnabled =
1105
- projectCfg?.hasAssistant ?? existingPages.includes('AssistantPage.tsx');
1106
-
1107
- for (const pageFile of existingPages) {
1108
- // Generated pages: regenerate instead of copy so assistant imports stay correct
1109
- if (pageFile === 'HomePage.tsx') {
1110
- await fs.writeFile(
1111
- path.join(pagesDir, 'HomePage.tsx'),
1112
- generateHomePage(assistantEnabled)
1113
- );
1114
- continue;
1115
- }
1116
- if (pageFile === 'TemplatePage.tsx') {
1117
- await fs.writeFile(
1118
- path.join(pagesDir, 'TemplatePage.tsx'),
1119
- generateTemplatePage(assistantEnabled)
1120
- );
1121
- continue;
1122
- }
1123
- const src = path.join(srcPagesDir, pageFile);
1124
- if (await fs.pathExists(src)) {
1125
- await fs.copy(src, path.join(pagesDir, pageFile), { overwrite: true });
1126
- }
1127
- }
1128
- }
1129
- }
1130
-
1131
- if (filesToUpdate.includes('config')) {
1132
- // Config files are inside the templates/ directory (same level as src/)
1133
- const configFiles = [
1134
- 'vite.config.ts',
1135
- 'tsconfig.json',
1136
- 'tsconfig.node.json',
1137
- 'postcss.config.js',
1138
- ];
1139
- for (const file of configFiles) {
1140
- const src = path.join(updatedTemplatesDir, file);
1141
- if (await fs.pathExists(src)) {
1142
- await fs.copy(src, path.join(targetDir, file), { overwrite: true });
1143
- }
1144
- }
1145
- }
1146
-
1147
- spinner.succeed(`Project updated to xertica-ui@${targetVersion} successfully!`);
1148
- console.log(chalk.gray('\n Run npm run dev to start the development server.'));
1149
- } catch (error) {
1150
- spinner.fail('Failed to update project');
1151
- console.error(error);
1152
- }
1153
- });
1154
-
1155
- 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();