@rebasepro/cli 0.30.1 → 0.31.0-canary.g902a0ce

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 (283) hide show
  1. package/README.md +8 -7
  2. package/dist/{agent-setup-0uyfC7VX.js → agent-setup-DqAcoDcn.js} +10 -5
  3. package/dist/{agent-setup-0uyfC7VX.js.map → agent-setup-DqAcoDcn.js.map} +1 -1
  4. package/dist/{api-keys-Dfw5-9s1.js → api-keys-eIUjMqWn.js} +8 -7
  5. package/dist/api-keys-eIUjMqWn.js.map +1 -0
  6. package/dist/{apps-MKQbgDtN.js → apps-DExO4PEl.js} +8 -7
  7. package/dist/apps-DExO4PEl.js.map +1 -0
  8. package/dist/{project-CasK56vN.js → args-CaCcrYE1.js} +2 -351
  9. package/dist/args-CaCcrYE1.js.map +1 -0
  10. package/dist/{atlas-dev-database-BODqdCWt.js → atlas-dev-database-DOCKk6ht.js} +2 -2
  11. package/dist/{atlas-dev-database-BODqdCWt.js.map → atlas-dev-database-DOCKk6ht.js.map} +1 -1
  12. package/dist/{auth-Bv0rTbQX.js → auth-CyADghFQ.js} +7 -6
  13. package/dist/{auth-Bv0rTbQX.js.map → auth-CyADghFQ.js.map} +1 -1
  14. package/dist/backend-guard-C0mVkXBw.js +162 -0
  15. package/dist/backend-guard-C0mVkXBw.js.map +1 -0
  16. package/dist/{branch-pointer-BQUF6lYa.js → branch-pointer-DMPyvZoK.js} +1 -1
  17. package/dist/{build-BuKTnec8.js → build-CA5R07tw.js} +29 -9
  18. package/dist/build-CA5R07tw.js.map +1 -0
  19. package/dist/{bundle-BAH4FCju.js → bundle-DgILeA5b.js} +112 -138
  20. package/dist/bundle-DgILeA5b.js.map +1 -0
  21. package/dist/bundle.d.ts +35 -12
  22. package/dist/cli.d.ts +2 -2
  23. package/dist/{cloud-DtADfWwn.js → cloud-CYMk92iG.js} +72 -71
  24. package/dist/cloud-CYMk92iG.js.map +1 -0
  25. package/dist/cms-directories-BK3vcswg.js +33 -0
  26. package/dist/cms-directories-BK3vcswg.js.map +1 -0
  27. package/dist/codemod/collections-to-tables/ast.d.ts +135 -0
  28. package/dist/codemod/collections-to-tables/backend.d.ts +38 -0
  29. package/dist/codemod/collections-to-tables/command.d.ts +35 -0
  30. package/dist/codemod/collections-to-tables/comments.d.ts +45 -0
  31. package/dist/codemod/collections-to-tables/customization.d.ts +47 -0
  32. package/dist/codemod/collections-to-tables/dynamic-props.d.ts +34 -0
  33. package/dist/codemod/collections-to-tables/export-changes.d.ts +83 -0
  34. package/dist/codemod/collections-to-tables/firestore.d.ts +11 -0
  35. package/dist/codemod/collections-to-tables/helper-hooks.d.ts +41 -0
  36. package/dist/codemod/collections-to-tables/hooks.d.ts +44 -0
  37. package/dist/codemod/collections-to-tables/journal.d.ts +10 -0
  38. package/dist/codemod/collections-to-tables/legacy-shims.d.ts +52 -0
  39. package/dist/codemod/collections-to-tables/load-legacy.d.ts +81 -0
  40. package/dist/codemod/collections-to-tables/migrate.d.ts +20 -0
  41. package/dist/codemod/collections-to-tables/modules.d.ts +127 -0
  42. package/dist/codemod/collections-to-tables/moved-imports.d.ts +70 -0
  43. package/dist/codemod/collections-to-tables/moved-symbols.generated.d.ts +12 -0
  44. package/dist/codemod/collections-to-tables/own.d.ts +10 -0
  45. package/dist/codemod/collections-to-tables/path-aliases.d.ts +26 -0
  46. package/dist/codemod/collections-to-tables/plan-context.d.ts +49 -0
  47. package/dist/codemod/collections-to-tables/print-js.d.ts +44 -0
  48. package/dist/codemod/collections-to-tables/project-files.d.ts +144 -0
  49. package/dist/codemod/collections-to-tables/repoint.d.ts +50 -0
  50. package/dist/codemod/collections-to-tables/row-hands.d.ts +7 -0
  51. package/dist/codemod/collections-to-tables/sdk-calls.d.ts +88 -0
  52. package/dist/codemod/collections-to-tables/skills-step.d.ts +13 -0
  53. package/dist/codemod/collections-to-tables/split-constants.d.ts +42 -0
  54. package/dist/codemod/collections-to-tables/storage-paths.d.ts +28 -0
  55. package/dist/codemod/collections-to-tables/types.d.ts +164 -0
  56. package/dist/codemod/collections-to-tables/verify.d.ts +27 -0
  57. package/dist/codemod/collections-to-tables/vocabulary.d.ts +40 -0
  58. package/dist/command-D5lhW_-B.js +9984 -0
  59. package/dist/command-D5lhW_-B.js.map +1 -0
  60. package/dist/commands/agent-setup.d.ts +6 -2
  61. package/dist/commands/cloud/context.d.ts +1 -1
  62. package/dist/commands/cloud/init.d.ts +2 -2
  63. package/dist/commands/console.d.ts +1 -2
  64. package/dist/commands/db.d.ts +5 -6
  65. package/dist/commands/dev.d.ts +18 -17
  66. package/dist/commands/doctor.d.ts +4 -5
  67. package/dist/commands/eject.d.ts +17 -13
  68. package/dist/commands/generate-view.d.ts +20 -9
  69. package/dist/commands/generate_sdk.d.ts +27 -27
  70. package/dist/commands/init.d.ts +21 -8
  71. package/dist/commands/migrate.d.ts +24 -0
  72. package/dist/commands/schema-reconcile.d.ts +1 -1
  73. package/dist/commands/skills.d.ts +8 -0
  74. package/dist/commands/verify-cms.d.ts +28 -0
  75. package/dist/commands/verify.d.ts +14 -9
  76. package/dist/{consent-BD7F29T3.js → consent-BXLIrMl8.js} +2 -2
  77. package/dist/{consent-BD7F29T3.js.map → consent-BXLIrMl8.js.map} +1 -1
  78. package/dist/{console-CdwIYOMV.js → console-CMjhgMUE.js} +14 -14
  79. package/dist/console-CMjhgMUE.js.map +1 -0
  80. package/dist/{context-AXdAh-q8.js → context--JwaHaZp.js} +6 -5
  81. package/dist/context--JwaHaZp.js.map +1 -0
  82. package/dist/{daemon-Cp7oNXth.js → daemon-w30PsdwV.js} +2 -2
  83. package/dist/{daemon-Cp7oNXth.js.map → daemon-w30PsdwV.js.map} +1 -1
  84. package/dist/{db-DBbKpjYX.js → db-A7XDCIIO.js} +51 -51
  85. package/dist/db-A7XDCIIO.js.map +1 -0
  86. package/dist/{derive-ae9UOoOB.js → derive-C3ezmY-p.js} +105 -133
  87. package/dist/derive-C3ezmY-p.js.map +1 -0
  88. package/dist/dev-db/attver.d.ts +11 -0
  89. package/dist/{dev-preflight-Cxv3TiD1.js → dev-preflight-DjvcV6SK.js} +5 -5
  90. package/dist/dev-preflight-DjvcV6SK.js.map +1 -0
  91. package/dist/{dev-server-OJsUGZEB.js → dev-server-BLxCbQEP.js} +2 -2
  92. package/dist/{dev-server-OJsUGZEB.js.map → dev-server-BLxCbQEP.js.map} +1 -1
  93. package/dist/{dev-C93d4QIv.js → dev-tWwPyWkQ.js} +142 -84
  94. package/dist/dev-tWwPyWkQ.js.map +1 -0
  95. package/dist/{doctor-BBPQUO2g.js → doctor-BBM0dWvZ.js} +39 -62
  96. package/dist/doctor-BBM0dWvZ.js.map +1 -0
  97. package/dist/doctor-environment.d.ts +6 -6
  98. package/dist/{eject-DABcDnPN.js → eject-Bhzd6hgb.js} +25 -16
  99. package/dist/eject-Bhzd6hgb.js.map +1 -0
  100. package/dist/{fold-static-BWzxNn06.js → fold-static-CKewnAPX.js} +5 -3
  101. package/dist/fold-static-CKewnAPX.js.map +1 -0
  102. package/dist/{generate-view-IFwCADvb.js → generate-view-CTOluXvH.js} +160 -89
  103. package/dist/generate-view-CTOluXvH.js.map +1 -0
  104. package/dist/{generate_sdk-DNmNuFuW.js → generate_sdk-De-aLC1L.js} +120 -137
  105. package/dist/generate_sdk-De-aLC1L.js.map +1 -0
  106. package/dist/import-schema-module-Df67TIWj.js +51 -0
  107. package/dist/import-schema-module-Df67TIWj.js.map +1 -0
  108. package/dist/index.es.js +64 -51
  109. package/dist/index.es.js.map +1 -1
  110. package/dist/{init-vL1DWOeC.js → init-Dtl-IcXf.js} +83 -80
  111. package/dist/init-Dtl-IcXf.js.map +1 -0
  112. package/dist/last-dev-database-Dc8cP01o.js +2 -0
  113. package/dist/{manifest-BtzDy7KQ.js → manifest-C3uLDrrJ.js} +115 -40
  114. package/dist/manifest-C3uLDrrJ.js.map +1 -0
  115. package/dist/manifest.d.ts +79 -24
  116. package/dist/migrate-VrKoi3nB.js +138 -0
  117. package/dist/migrate-VrKoi3nB.js.map +1 -0
  118. package/dist/{normalize-imports-Bd5Y4yLp.js → normalize-imports-DwxqEMYq.js} +3 -3
  119. package/dist/{normalize-imports-Bd5Y4yLp.js.map → normalize-imports-DwxqEMYq.js.map} +1 -1
  120. package/dist/path-flags-7O5uPBcQ.js +139 -0
  121. package/dist/path-flags-7O5uPBcQ.js.map +1 -0
  122. package/dist/{prepare-CTw9NEkh.js → prepare-Ccxspoj-.js} +4 -4
  123. package/dist/{prepare-CTw9NEkh.js.map → prepare-Ccxspoj-.js.map} +1 -1
  124. package/dist/project-CLcF5i8c.js +360 -0
  125. package/dist/project-CLcF5i8c.js.map +1 -0
  126. package/dist/project-schema-CsSOG2gE.js +30 -0
  127. package/dist/project-schema-CsSOG2gE.js.map +1 -0
  128. package/dist/{pull-DDMpsZ5r.js → pull-D9WvpDYY.js} +189 -1
  129. package/dist/pull-D9WvpDYY.js.map +1 -0
  130. package/dist/resolve-BY7bSFRT.js +2 -0
  131. package/dist/resources/derive.d.ts +19 -13
  132. package/dist/{resources-CPSC5Kcu.js → resources-Dpfs2y8P.js} +5 -4
  133. package/dist/{resources-CPSC5Kcu.js.map → resources-Dpfs2y8P.js.map} +1 -1
  134. package/dist/{schema-DtLPsXbT.js → schema-DwFDI1iU.js} +41 -39
  135. package/dist/schema-DwFDI1iU.js.map +1 -0
  136. package/dist/schema-dir-Cd1kvYbf.js +98 -0
  137. package/dist/schema-dir-Cd1kvYbf.js.map +1 -0
  138. package/dist/schema-reconcile-Tto54Qbv.js +2 -0
  139. package/dist/schema-text-CpNrsuMe.js +73 -0
  140. package/dist/schema-text-CpNrsuMe.js.map +1 -0
  141. package/dist/{skills-CbwV6vw_.js → skills-CXjA9TWw.js} +54 -10
  142. package/dist/skills-CXjA9TWw.js.map +1 -0
  143. package/dist/{start-YOr3X5Zm.js → start-Bwbtt2W5.js} +7 -10
  144. package/dist/{start-YOr3X5Zm.js.map → start-Bwbtt2W5.js.map} +1 -1
  145. package/dist/{status-BREvtzJm.js → status-DQ_PPz4C.js} +12 -12
  146. package/dist/status-DQ_PPz4C.js.map +1 -0
  147. package/dist/{storage-CO9ouK76.js → storage-iTqj5-Av.js} +12 -11
  148. package/dist/storage-iTqj5-Av.js.map +1 -0
  149. package/dist/{telemetry-DwK5RQJl.js → telemetry-BP_1Cl9r.js} +4 -4
  150. package/dist/{telemetry-DwK5RQJl.js.map → telemetry-BP_1Cl9r.js.map} +1 -1
  151. package/dist/{telemetry-CgwJPVMO.js → telemetry-M3HjlyhZ.js} +2 -2
  152. package/dist/{telemetry-CgwJPVMO.js.map → telemetry-M3HjlyhZ.js.map} +1 -1
  153. package/dist/{upgrade-B7sVwL8S.js → upgrade-oZzJ13jM.js} +5 -4
  154. package/dist/{upgrade-B7sVwL8S.js.map → upgrade-oZzJ13jM.js.map} +1 -1
  155. package/dist/utils/backend-guard.d.ts +47 -0
  156. package/dist/utils/cms-directories.d.ts +6 -0
  157. package/dist/utils/dev-preflight.d.ts +2 -2
  158. package/dist/utils/import-schema-module.d.ts +16 -0
  159. package/dist/utils/path-flags.d.ts +35 -16
  160. package/dist/utils/project-schema.d.ts +40 -0
  161. package/dist/utils/project.d.ts +8 -2
  162. package/dist/utils/schema-dir.d.ts +32 -0
  163. package/dist/utils/schema-drift.d.ts +6 -0
  164. package/dist/utils/schema-text.d.ts +24 -0
  165. package/dist/verify-DkJqhYPI.js +1160 -0
  166. package/dist/verify-DkJqhYPI.js.map +1 -0
  167. package/package.json +11 -8
  168. package/runtime/dev-server.mjs +5 -1
  169. package/templates/eject/Dockerfile +1 -4
  170. package/templates/eject/backend/src/env.ts +1 -1
  171. package/templates/eject/backend/src/index.ts +53 -40
  172. package/templates/eject/docker-compose.custom.yml +1 -1
  173. package/templates/overlays/baas/README.md +39 -12
  174. package/templates/overlays/baas/ai-instructions.md +8 -8
  175. package/templates/overlays/baas/{config → backend}/storage.ts +3 -4
  176. package/templates/overlays/baas/backend/tsconfig.json +10 -12
  177. package/templates/overlays/baas/package.json +1 -2
  178. package/templates/overlays/baas/pnpm-workspace.yaml +0 -1
  179. package/templates/presets/blank/backend/schema/index.ts +19 -0
  180. package/templates/presets/blank/frontend/src/App.tsx +56 -0
  181. package/templates/presets/ecommerce/backend/schema/categories.ts +12 -0
  182. package/templates/presets/ecommerce/backend/schema/index.ts +23 -0
  183. package/templates/presets/ecommerce/backend/schema/orders.ts +13 -0
  184. package/templates/presets/ecommerce/backend/schema/products.ts +18 -0
  185. package/templates/presets/ecommerce/frontend/src/App.tsx +59 -0
  186. package/templates/presets/ecommerce/frontend/src/cms/categories.tsx +12 -0
  187. package/templates/presets/ecommerce/frontend/src/cms/orders.tsx +38 -0
  188. package/templates/presets/ecommerce/frontend/src/cms/products.tsx +27 -0
  189. package/templates/resource-graphs/blank.json +2 -2
  190. package/templates/resource-graphs/blog.json +5 -5
  191. package/templates/resource-graphs/ecommerce.json +5 -5
  192. package/templates/resource-graphs/headless.json +1 -1
  193. package/templates/template/.claude/hooks/post-edit-collection.sh +27 -23
  194. package/templates/template/.cursorrules +2 -2
  195. package/templates/template/.env.example +6 -17
  196. package/templates/template/.github/copilot-instructions.md +2 -2
  197. package/templates/template/.windsurfrules +2 -2
  198. package/templates/template/AGENTS.md +2 -2
  199. package/templates/template/CLAUDE.md +2 -2
  200. package/templates/template/README.md +47 -13
  201. package/templates/template/ai-instructions.md +15 -14
  202. package/templates/template/backend/functions/hello.ts +1 -1
  203. package/templates/template/backend/package.json +0 -2
  204. package/templates/template/{config → backend}/resources.ts +3 -3
  205. package/templates/template/backend/schema/authors.ts +11 -0
  206. package/templates/template/backend/schema/index.ts +29 -0
  207. package/templates/template/backend/schema/posts.ts +29 -0
  208. package/templates/template/backend/schema/tags.ts +9 -0
  209. package/templates/template/backend/schema/users.ts +32 -0
  210. package/templates/template/{config → backend}/storage.ts +4 -4
  211. package/templates/template/backend/tsconfig.json +15 -20
  212. package/templates/template/docker-compose.yml +3 -3
  213. package/templates/template/frontend/package.json +0 -2
  214. package/templates/template/frontend/src/App.tsx +10 -4
  215. package/templates/template/frontend/src/cms/authors.tsx +7 -0
  216. package/templates/template/frontend/src/cms/posts.tsx +27 -0
  217. package/templates/template/frontend/src/cms/tags.tsx +11 -0
  218. package/templates/template/frontend/src/cms/ui-config.json +3 -0
  219. package/templates/template/frontend/src/cms/users.tsx +54 -0
  220. package/templates/template/frontend/src/{virtual.d.ts → vite-env.d.ts} +0 -4
  221. package/templates/template/frontend/vite.config.ts +6 -2
  222. package/templates/template/gitignore +1 -1
  223. package/templates/template/package.json +1 -2
  224. package/templates/template/pnpm-workspace.yaml +0 -1
  225. package/templates/template/scripts/example.ts +3 -3
  226. package/templates/template/tsconfig.json +1 -1
  227. package/templates/views/AppView.tsx.tmpl +4 -4
  228. package/templates/views/EntityView.tsx.tmpl +3 -4
  229. package/dist/api-keys-Dfw5-9s1.js.map +0 -1
  230. package/dist/apps-MKQbgDtN.js.map +0 -1
  231. package/dist/build-BuKTnec8.js.map +0 -1
  232. package/dist/bundle-BAH4FCju.js.map +0 -1
  233. package/dist/cloud-DtADfWwn.js.map +0 -1
  234. package/dist/collection-drift-BKj_BoMq.js +0 -106
  235. package/dist/collection-drift-BKj_BoMq.js.map +0 -1
  236. package/dist/collections-dir-DlvDhime.js +0 -69
  237. package/dist/collections-dir-DlvDhime.js.map +0 -1
  238. package/dist/console-CdwIYOMV.js.map +0 -1
  239. package/dist/context-AXdAh-q8.js.map +0 -1
  240. package/dist/db-DBbKpjYX.js.map +0 -1
  241. package/dist/derive-ae9UOoOB.js.map +0 -1
  242. package/dist/dev-C93d4QIv.js.map +0 -1
  243. package/dist/dev-preflight-Cxv3TiD1.js.map +0 -1
  244. package/dist/doctor-BBPQUO2g.js.map +0 -1
  245. package/dist/eject-DABcDnPN.js.map +0 -1
  246. package/dist/fold-static-BWzxNn06.js.map +0 -1
  247. package/dist/generate-view-IFwCADvb.js.map +0 -1
  248. package/dist/generate_sdk-DNmNuFuW.js.map +0 -1
  249. package/dist/init-vL1DWOeC.js.map +0 -1
  250. package/dist/last-dev-database-DpW5dfoX.js +0 -2
  251. package/dist/manifest-BtzDy7KQ.js.map +0 -1
  252. package/dist/path-flags-DNvtEi2-.js +0 -92
  253. package/dist/path-flags-DNvtEi2-.js.map +0 -1
  254. package/dist/project-CasK56vN.js.map +0 -1
  255. package/dist/pull-DDMpsZ5r.js.map +0 -1
  256. package/dist/resolve-D647F1LA.js +0 -2
  257. package/dist/schema-DtLPsXbT.js.map +0 -1
  258. package/dist/schema-reconcile-DkArN9jF.js +0 -2
  259. package/dist/skills-CbwV6vw_.js.map +0 -1
  260. package/dist/status-BREvtzJm.js.map +0 -1
  261. package/dist/storage-CO9ouK76.js.map +0 -1
  262. package/dist/utils/collection-drift.d.ts +0 -27
  263. package/dist/utils/collections-dir.d.ts +0 -14
  264. package/dist/verify-Y3rWSgfA.js +0 -730
  265. package/dist/verify-Y3rWSgfA.js.map +0 -1
  266. package/templates/overlays/baas/config/index.ts +0 -24
  267. package/templates/overlays/baas/config/package.json +0 -30
  268. package/templates/template/config/cms.d.ts +0 -15
  269. package/templates/template/config/collections/authors.ts +0 -47
  270. package/templates/template/config/collections/index.ts +0 -44
  271. package/templates/template/config/collections/posts.ts +0 -94
  272. package/templates/template/config/collections/presets/blank/index.ts +0 -5
  273. package/templates/template/config/collections/presets/ecommerce/categories.ts +0 -42
  274. package/templates/template/config/collections/presets/ecommerce/index.ts +0 -31
  275. package/templates/template/config/collections/presets/ecommerce/orders.ts +0 -78
  276. package/templates/template/config/collections/presets/ecommerce/products.ts +0 -73
  277. package/templates/template/config/collections/tags.ts +0 -27
  278. package/templates/template/config/collections/users.ts +0 -149
  279. package/templates/template/config/frontend-assets.d.ts +0 -17
  280. package/templates/template/config/index.ts +0 -12
  281. package/templates/template/config/package.json +0 -30
  282. package/templates/template/config/tsconfig.json +0 -35
  283. /package/templates/eject/{config → backend}/resources.ts +0 -0
@@ -1,16 +1,19 @@
1
- import { b as UsageError, p as requireProjectRoot, w as wantsHelp, x as parseCommandArgs } from "./project-CasK56vN.js";
2
- import { l as cmsMountOf, p as loadManifest } from "./manifest-BtzDy7KQ.js";
3
- import { resolveCollectionsDir } from "./collections-dir-DlvDhime.js";
1
+ import { a as wantsHelp, n as parseCommandArgs, t as UsageError } from "./args-CaCcrYE1.js";
2
+ import { p as requireProjectRoot } from "./project-CLcF5i8c.js";
3
+ import { b as loadManifest, h as cmsMountOf } from "./manifest-C3uLDrrJ.js";
4
+ import { n as resolveSchemaDir } from "./schema-dir-Cd1kvYbf.js";
5
+ import { t as declaredTables } from "./schema-text-CpNrsuMe.js";
4
6
  import chalk from "chalk";
5
7
  import fs from "fs";
6
8
  import path from "path";
7
9
  import { fileURLToPath } from "url";
10
+ import { tableIdentifier } from "@rebasepro/common";
8
11
  //#region src/commands/generate-view.ts
9
12
  /**
10
13
  * `rebase generate view <slug>` — scaffold a custom admin screen and register it.
11
14
  *
12
15
  * Most back-office screens are a table, a form or a board, and the admin draws
13
- * those from the collection. The rest — a dispatch board, a reconciliation
16
+ * those from the table. The rest — a dispatch board, a reconciliation
14
17
  * screen, a record's audit trail — are a hundred lines of React. Written inside
15
18
  * the admin they inherit the sign-in, the security rules, the sidebar, the UI
16
19
  * kit and the data layer; written as a separate app they have to rebuild every
@@ -23,11 +26,13 @@ import { fileURLToPath } from "url";
23
26
  * `<frontend>/src/views/index.ts` as an `AppView`, which `App.tsx` hands to
24
27
  * `<RebaseCMS views>`. The first run wires `App.tsx`; later runs only append
25
28
  * to the list.
26
- * - **A record tab** (`--collection <slug>`): the same file location, with a
27
- * component that takes `EntityCustomViewParams`, added to that collection's
28
- * `admin.entityViews` *by path*. The collection file is shared with the
29
- * backend, and a path is the one form of component reference the backend
30
- * never evaluates — the admin's Vite plugin turns it into a lazy import.
29
+ * - **A record tab** (`--collection <slug>`, the slug of a table in
30
+ * `backend/schema`): the same file location, with a component that takes
31
+ * `EntityCustomViewParams`, added to the `entityViews` of that table's
32
+ * `customizeTable(…)` in `<frontend>/src/cms/` — imported directly, because
33
+ * that directory is the admin's own code and the backend never reads it. A
34
+ * table with no customization yet gets one, `<frontend>/src/cms/<slug>.tsx`,
35
+ * listed in `cms/index.ts`'s `tableCustomizations` when there is one.
31
36
  *
32
37
  * The frontend is where `rebase.json` says the CMS is (the static app with a
33
38
  * `cms` mount), which is `frontend/` in everything `rebase init` writes. A
@@ -35,7 +40,7 @@ import { fileURLToPath } from "url";
35
40
  * nowhere for a view to render.
36
41
  *
37
42
  * Edits to existing files are textual and conservative. When `App.tsx` already
38
- * passes its own `views`, or a collection's shape is not one this can read, the
43
+ * passes its own `views`, or a customization's shape is not one this can read, the
39
44
  * view file is still written and the command prints the one line to add by
40
45
  * hand instead of guessing.
41
46
  */
@@ -234,32 +239,36 @@ function resolveFrontendDir(projectRoot) {
234
239
  const fallback = path.join(projectRoot, "frontend");
235
240
  return fs.existsSync(path.join(fallback, "src")) ? fallback : void 0;
236
241
  }
237
- function collectionFiles(dir) {
242
+ /** Every source file under the admin's `src/cms`, sorted: where table customizations live. */
243
+ function customizationFiles(dir) {
238
244
  if (!fs.existsSync(dir)) return [];
239
245
  const out = [];
240
246
  const entries = fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
241
247
  for (const entry of entries) {
242
248
  const full = path.join(dir, entry.name);
243
249
  if (entry.isDirectory()) {
244
- if (entry.name !== "node_modules" && entry.name !== "presets") out.push(...collectionFiles(full));
250
+ if (entry.name !== "node_modules") out.push(...customizationFiles(full));
245
251
  } else if (/\.tsx?$/.test(entry.name) && !/\.(test|spec|d)\.tsx?$/.test(entry.name)) out.push(full);
246
252
  }
247
253
  return out;
248
254
  }
249
- var SLUG_PROPERTY = /(^|[\s,{])slug\s*:\s*(["'])([^"'\n]+)\2/g;
250
- /** Every `slug: "…"` a collection file declares, with where. */
251
- function declaredSlugs(dir) {
255
+ /**
256
+ * Every `customizeTable("<slug>", {` of a table, in code (not in a comment or
257
+ * a string): the file, and where the options object opens. Empty when no file
258
+ * under `cmsDir` customizes the table.
259
+ */
260
+ function findCustomization(cmsDir, slug) {
252
261
  const found = [];
253
- for (const file of collectionFiles(dir)) {
262
+ const call = /\bcustomizeTable\s*(?:<[^>]*>)?\(\s*(["'`])([^"'`\n]+)\1\s*,\s*\{/g;
263
+ for (const file of customizationFiles(cmsDir)) {
254
264
  const source = fs.readFileSync(file, "utf8");
255
265
  const masked = maskCode(source);
256
- for (const match of source.matchAll(SLUG_PROPERTY)) {
257
- const at = (match.index ?? 0) + match[1].length;
258
- if (masked[at] !== "s") continue;
266
+ for (const match of source.matchAll(call)) {
267
+ const at = match.index ?? 0;
268
+ if (match[2] !== slug || masked[at] !== "c") continue;
259
269
  found.push({
260
- slug: match[3],
261
270
  file,
262
- at
271
+ optionsOpen: at + match[0].length - 1
263
272
  });
264
273
  }
265
274
  }
@@ -285,6 +294,16 @@ function findCliRoot(from) {
285
294
  }
286
295
  return null;
287
296
  }
297
+ /** The `{ key, name, Builder }` an entity view is registered as, with `unit` indentation inside. */
298
+ function entityViewEntry(view, unit) {
299
+ return [
300
+ "{",
301
+ `${unit}key: ${JSON.stringify(view.key)},`,
302
+ `${unit}name: ${JSON.stringify(view.name)},`,
303
+ `${unit}Builder: ${view.componentName}`,
304
+ "}"
305
+ ].join("\n");
306
+ }
288
307
  /**
289
308
  * A label as JSX text: written as is when it is plain, as a string expression
290
309
  * when it holds a character JSX reads — `{`, `}`, `<`, `>`, `&`. Pasted raw,
@@ -366,7 +385,7 @@ function planCmsTypesDependency(frontendDir, files, manualSteps) {
366
385
  manualSteps.push(`Run your package manager's install: ${path.basename(frontendDir)}/package.json now depends on @rebasepro/cms-types, which the view imports its types from.`);
367
386
  }
368
387
  function defaultCollectionFor(projectRoot) {
369
- const slugs = declaredSlugs(resolveCollectionsDir(projectRoot)).map((entry) => entry.slug);
388
+ const slugs = declaredTables(resolveSchemaDir(projectRoot)).map((entry) => entry.slug);
370
389
  return slugs.find((slug) => slug !== "users") ?? slugs[0] ?? "users";
371
390
  }
372
391
  /**
@@ -392,38 +411,82 @@ function planGenerateView(options) {
392
411
  const viewAction = viewExists ? "replace" : "create";
393
412
  if (options.collection) {
394
413
  const kind = "entity";
395
- const collectionsDir = resolveCollectionsDir(projectRoot);
396
- const declared = declaredSlugs(collectionsDir);
397
- const matches = declared.filter((entry) => entry.slug === options.collection);
398
- if (matches.length === 0) {
414
+ const table = options.collection;
415
+ const schemaDir = resolveSchemaDir(projectRoot);
416
+ const declared = declaredTables(schemaDir);
417
+ if (!declared.some((entry) => entry.slug === table)) {
399
418
  const known = [...new Set(declared.map((entry) => entry.slug))].sort();
400
- throw new UsageError(`No collection with slug "${options.collection}" under ${path.relative(projectRoot, collectionsDir) || "."}.` + (known.length ? ` Declared: ${known.join(", ")}.` : ""));
419
+ throw new UsageError(`No table with slug "${table}" under ${path.relative(projectRoot, schemaDir) || "."}.` + (known.length ? ` Declared: ${known.join(", ")}.` : ""));
401
420
  }
402
- if (matches.length > 1) throw new UsageError(`More than one collection declares slug "${options.collection}": ${matches.map((entry) => path.relative(projectRoot, entry.file)).join(", ")}.`);
403
- const [{ file: collectionFile, at: slugAt }] = matches;
421
+ const cmsDir = path.join(frontendDir, "src", "cms");
422
+ const customizations = findCustomization(cmsDir, table);
423
+ if (customizations.length > 1) throw new UsageError(`More than one customizeTable("${table}", …) under ${path.relative(projectRoot, cmsDir)}: ${[...new Set(customizations.map((entry) => path.relative(projectRoot, entry.file)))].join(", ")}.`);
404
424
  files.push({
405
425
  path: viewFile,
406
426
  contents: entityViewSource({
407
427
  slug,
408
428
  componentName,
409
429
  label,
410
- collection: options.collection
430
+ collection: table
411
431
  }),
412
432
  action: viewAction
413
433
  });
414
- const builder = relativeImport(path.dirname(collectionFile), viewFile);
415
- const updated = registerEntityView(fs.readFileSync(collectionFile, "utf8"), slugAt, {
434
+ const view = {
416
435
  key: slug,
417
436
  name: label,
418
- builder
419
- });
420
- const where = `${path.relative(projectRoot, collectionFile)}`;
421
- if (updated === "already") {} else if (updated === void 0) manualSteps.push(`Add this to admin.entityViews in ${where}: { key: ${JSON.stringify(slug)}, name: ${JSON.stringify(label)}, Builder: ${JSON.stringify(builder)} }`);
422
- else files.push({
423
- path: collectionFile,
424
- contents: updated,
425
- action: "update"
426
- });
437
+ componentName
438
+ };
439
+ if (customizations.length === 1) {
440
+ const [{ file, optionsOpen }] = customizations;
441
+ const importLine = `import { ${componentName} } from "${relativeImport(path.dirname(file), viewFile)}";`;
442
+ const updated = registerEntityView(fs.readFileSync(file, "utf8"), optionsOpen, view);
443
+ const where = path.relative(projectRoot, file);
444
+ if (updated === "already") {} else if (updated === void 0) manualSteps.push(`Add this to the entityViews of customizeTable("${table}", …) in ${where}: { key: ${JSON.stringify(slug)}, name: ${JSON.stringify(label)}, Builder: ${componentName} }, and ${importLine}`);
445
+ else files.push({
446
+ path: file,
447
+ contents: addImport(updated, importLine),
448
+ action: "update"
449
+ });
450
+ } else {
451
+ const identifier = `${tableIdentifier(table)}Cms`;
452
+ const file = path.join(cmsDir, `${table}.tsx`);
453
+ if (fs.existsSync(file)) throw new UsageError(`${path.relative(projectRoot, file)} exists but holds no customizeTable("${table}", …): add the record tab to the table's customization by hand, or move that file aside.`);
454
+ const unit = " ";
455
+ files.push({
456
+ path: file,
457
+ contents: [
458
+ "import { customizeTable } from \"@rebasepro/cms\";",
459
+ `import { ${componentName} } from "${relativeImport(cmsDir, viewFile)}";`,
460
+ "",
461
+ `export const ${identifier} = customizeTable("${table}", {`,
462
+ `${unit}entityViews: [`,
463
+ reindent(entityViewEntry(view, unit), " "),
464
+ `${unit}]`,
465
+ "});",
466
+ ""
467
+ ].join("\n"),
468
+ action: "create"
469
+ });
470
+ const indexFile = path.join(cmsDir, "index.ts");
471
+ const appFile = path.join(frontendDir, "src", "App.tsx");
472
+ const index = readIfExists(indexFile);
473
+ const app = readIfExists(appFile);
474
+ const listedInIndex = index === void 0 ? void 0 : listCustomization(index, identifier, `./${table}`);
475
+ const listedInApp = listedInIndex === void 0 && app !== void 0 ? listCustomization(app, identifier, `./cms/${table}`) : void 0;
476
+ if (listedInIndex !== void 0) {
477
+ if (listedInIndex !== "already") files.push({
478
+ path: indexFile,
479
+ contents: listedInIndex,
480
+ action: "update"
481
+ });
482
+ } else if (listedInApp !== void 0) {
483
+ if (listedInApp !== "already") files.push({
484
+ path: appFile,
485
+ contents: listedInApp,
486
+ action: "update"
487
+ });
488
+ } else manualSteps.push(`Hand the customization to the admin: import { ${identifier} } from "./cms/${table}" and add it to <RebaseCMS tableCustomizations={[…]}> in ${path.relative(projectRoot, appFile)}.`);
489
+ }
427
490
  planCmsTypesDependency(frontendDir, files, manualSteps);
428
491
  return {
429
492
  kind,
@@ -533,55 +596,63 @@ function wireViewsIntoApp(source) {
533
596
  return addImport(source.slice(0, insertAt) + attribute + source.slice(insertAt), "import { views } from \"./views\";");
534
597
  }
535
598
  /**
536
- * The collection file with a `{ key, name, Builder }` entry in the
537
- * `admin.entityViews` of the collection whose `slug:` is at `slugAt`;
538
- * `"already"` when that key is there; `undefined` when the shape cannot be read.
599
+ * The customization file with a `{ key, name, Builder }` entry in the
600
+ * `entityViews` of the `customizeTable(…)` options object whose `{` is at
601
+ * `optionsOpen`; `"already"` when that key is there; `undefined` when the
602
+ * shape cannot be read. The component's import is the caller's to add.
539
603
  *
540
604
  * Exported for its tests.
541
605
  */
542
- function registerEntityView(source, slugAt, view) {
606
+ function registerEntityView(source, optionsOpen, view) {
543
607
  const masked = maskCode(source);
544
- const collectionOpen = enclosingBrace(masked, slugAt);
545
- if (collectionOpen === -1) return void 0;
608
+ const close = matchClose(masked, optionsOpen);
609
+ if (close === -1) return void 0;
546
610
  const unit = indentUnit(source);
547
- const entry = [
548
- "{",
549
- `${unit}key: ${JSON.stringify(view.key)},`,
550
- `${unit}name: ${JSON.stringify(view.name)},`,
551
- `${unit}Builder: ${JSON.stringify(view.builder)}`,
552
- "}"
553
- ].join("\n");
554
- const admin = directProperty(masked, collectionOpen, "admin", "{");
555
- if (admin) {
556
- const entityViews = directProperty(masked, admin.valueOpen, "entityViews", "[");
557
- if (entityViews) {
558
- const close = matchClose(masked, entityViews.valueOpen);
559
- if (close === -1) return void 0;
560
- const listed = source.slice(entityViews.valueOpen, close);
561
- if (new RegExp(`key\\s*:\\s*["']${view.key}["']|["']${view.key}["']`).test(listed)) return "already";
562
- const indent = indentAt(source, entityViews.keyAt) + unit;
563
- return appendToArray(source, masked, entityViews.valueOpen, reindent(entry, indent));
564
- }
565
- const indent = indentAt(source, admin.keyAt) + unit;
566
- const block = `${indent}entityViews: [\n${reindent(entry, indent + unit)}\n${indent}],`;
567
- const adminClose = matchClose(masked, admin.valueOpen);
568
- const empty = masked.slice(admin.valueOpen + 1, adminClose).trim() === "";
569
- const insertAt = admin.valueOpen + 1;
570
- return empty ? `${source.slice(0, insertAt)}\n${block.replace(/,$/, "")}\n${indentAt(source, admin.keyAt)}${source.slice(adminClose)}` : `${source.slice(0, insertAt)}\n${block}${source.slice(insertAt)}`;
611
+ const entry = entityViewEntry(view, unit);
612
+ const entityViews = directProperty(masked, optionsOpen, "entityViews", "[");
613
+ if (entityViews) {
614
+ const listClose = matchClose(masked, entityViews.valueOpen);
615
+ if (listClose === -1) return void 0;
616
+ const listed = source.slice(entityViews.valueOpen, listClose);
617
+ if (new RegExp(`key\\s*:\\s*["']${view.key}["']|["']${view.key}["']`).test(listed)) return "already";
618
+ const indent = indentAt(source, entityViews.keyAt) + unit;
619
+ return appendToArray(source, masked, entityViews.valueOpen, reindent(entry, indent));
571
620
  }
572
- const slugLineEnd = source.indexOf("\n", slugAt);
573
- if (slugLineEnd === -1) return void 0;
574
- const slugLine = masked.slice(slugAt, slugLineEnd);
575
- if (!/,\s*$/.test(slugLine)) return void 0;
576
- const indent = indentAt(source, slugAt);
577
- const block = [
578
- `${indent}admin: {`,
579
- `${indent}${unit}entityViews: [`,
580
- reindent(entry, indent + unit + unit),
581
- `${indent}${unit}]`,
582
- `${indent}},`
583
- ].join("\n");
584
- return `${source.slice(0, slugLineEnd + 1)}${block}\n${source.slice(slugLineEnd + 1)}`;
621
+ const indent = indentAt(source, optionsOpen) + unit;
622
+ const block = `${indent}entityViews: [\n${reindent(entry, indent + unit)}\n${indent}]`;
623
+ const empty = masked.slice(optionsOpen + 1, close).trim() === "";
624
+ const insertAt = optionsOpen + 1;
625
+ return empty ? `${source.slice(0, insertAt)}\n${block}\n${indentAt(source, optionsOpen)}${source.slice(close)}` : `${source.slice(0, insertAt)}\n${block},${source.slice(insertAt)}`;
626
+ }
627
+ /**
628
+ * A source with `identifier` imported from `importPath` and appended to its
629
+ * list of table customizations — `export const tableCustomizations = [ … ]`
630
+ * (`cms/index.ts`) or `tableCustomizations={[ … ]}` on `<RebaseCMS>`
631
+ * (`App.tsx`); `"already"` when it is listed; `undefined` when the source has
632
+ * no such list.
633
+ *
634
+ * Exported for its tests.
635
+ */
636
+ function listCustomization(source, identifier, importPath) {
637
+ const masked = maskCode(source);
638
+ const declaration = /export\s+const\s+tableCustomizations\b[^=]*=\s*\[/.exec(masked) ?? /\btableCustomizations\s*=\s*\{\s*\[/.exec(masked);
639
+ if (!declaration) return void 0;
640
+ const open = declaration.index + declaration[0].length - 1;
641
+ const close = matchClose(masked, open);
642
+ if (close === -1) return void 0;
643
+ if (new RegExp(`\\b${identifier}\\b`).test(masked.slice(open, close))) return "already";
644
+ const inner = masked.slice(open + 1, close);
645
+ let appended;
646
+ if (inner.trim() !== "" && !inner.includes("\n")) {
647
+ let last = close - 1;
648
+ while (last > open && /\s/.test(masked[last])) last--;
649
+ const comma = masked[last] === "," ? " " : ", ";
650
+ appended = `${source.slice(0, last + 1)}${comma}${identifier}${source.slice(last + 1)}`;
651
+ } else {
652
+ const unit = indentUnit(source);
653
+ appended = appendToArray(source, masked, open, `${indentAt(source, open)}${unit}${identifier}`);
654
+ }
655
+ return addImport(appended, `import { ${identifier} } from "${importPath}";`);
585
656
  }
586
657
  function printHelp() {
587
658
  console.log(`
@@ -589,17 +660,17 @@ ${chalk.bold("rebase generate")} — scaffold code into this project
589
660
 
590
661
  ${chalk.bold("Usage")}
591
662
  rebase generate view <slug> A screen of the admin, in the sidebar
592
- rebase generate view <slug> --collection <slug> A tab on every record of a collection
663
+ rebase generate view <slug> --collection <slug> A tab on every record of a table
593
664
 
594
665
  ${chalk.bold("What it writes")}
595
666
  <frontend>/src/views/<Name>View.tsx The component, drawn with @rebasepro/ui
596
667
  <frontend>/src/views/index.ts The screens list (AppView[]), wired into
597
668
  <RebaseCMS views> in App.tsx on first run
598
- With --collection, the collection file instead gains an admin.entityViews
599
- entry that points at the component by path.
669
+ With --collection, the table's customizeTable(…) in <frontend>/src/cms gains
670
+ an entityViews entry with the component (a new <slug>.tsx when it has none).
600
671
 
601
672
  ${chalk.bold("Options")}
602
- --collection <slug> Register as a record tab of this collection
673
+ --collection <slug> Register as a record tab of the table with this slug
603
674
  --name <label> Sidebar or tab label ${chalk.gray("(default: the slug in sentence case)")}
604
675
  --icon <Lucide name> Sidebar icon for a screen ${chalk.gray("(default: LayoutDashboard)")}
605
676
  --dry-run List what would change, and change nothing
@@ -659,4 +730,4 @@ async function generateViewCommand(rawArgs) {
659
730
  //#endregion
660
731
  export { GENERATE_SUBCOMMANDS, generateCommand };
661
732
 
662
- //# sourceMappingURL=generate-view-IFwCADvb.js.map
733
+ //# sourceMappingURL=generate-view-CTOluXvH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-view-CTOluXvH.js","names":[],"sources":["../src/commands/generate-view.ts"],"sourcesContent":["/**\n * `rebase generate view <slug>` — scaffold a custom admin screen and register it.\n *\n * Most back-office screens are a table, a form or a board, and the admin draws\n * those from the table. The rest — a dispatch board, a reconciliation\n * screen, a record's audit trail — are a hundred lines of React. Written inside\n * the admin they inherit the sign-in, the security rules, the sidebar, the UI\n * kit and the data layer; written as a separate app they have to rebuild every\n * one of those. This command writes the first version of that file where the\n * admin will find it, so the screen starts native and registered.\n *\n * Two places, one file each:\n *\n * - **A screen** (default): `<frontend>/src/views/<Name>View.tsx`, listed in\n * `<frontend>/src/views/index.ts` as an `AppView`, which `App.tsx` hands to\n * `<RebaseCMS views>`. The first run wires `App.tsx`; later runs only append\n * to the list.\n * - **A record tab** (`--collection <slug>`, the slug of a table in\n * `backend/schema`): the same file location, with a component that takes\n * `EntityCustomViewParams`, added to the `entityViews` of that table's\n * `customizeTable(…)` in `<frontend>/src/cms/` — imported directly, because\n * that directory is the admin's own code and the backend never reads it. A\n * table with no customization yet gets one, `<frontend>/src/cms/<slug>.tsx`,\n * listed in `cms/index.ts`'s `tableCustomizations` when there is one.\n *\n * The frontend is where `rebase.json` says the CMS is (the static app with a\n * `cms` mount), which is `frontend/` in everything `rebase init` writes. A\n * project with no admin panel (`rebase init --headless`) is refused: there is\n * nowhere for a view to render.\n *\n * Edits to existing files are textual and conservative. When `App.tsx` already\n * passes its own `views`, or a customization's shape is not one this can read, the\n * view file is still written and the command prints the one line to add by\n * hand instead of guessing.\n */\nimport fs from \"fs\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport chalk from \"chalk\";\n\nimport { tableIdentifier } from \"@rebasepro/common\";\nimport { cmsMountOf, loadManifest } from \"../manifest\";\nimport { resolveSchemaDir } from \"../utils/schema-dir\";\nimport { declaredTables } from \"../utils/schema-text\";\nimport { requireProjectRoot } from \"../utils/project\";\nimport { parseCommandArgs, UsageError, wantsHelp } from \"../utils/args\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\n/** What `rebase generate` dispatches. Read by `cli.ts` to name the subcommand. */\nexport const GENERATE_SUBCOMMANDS = [\"view\"] as const;\n\nconst VIEW_FLAGS = {\n \"--collection\": String,\n \"--name\": String,\n \"--icon\": String,\n \"--dry-run\": Boolean,\n \"--force\": Boolean\n} as const;\n\n/** A slug is a URL segment and an entity view key: kebab-case, starting with a letter. */\nconst SLUG_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n\n/**\n * Top-level paths the admin's own routes answer (`RebaseRouteDefs` in\n * `@rebasepro/cms`): `/c/*` the collections, `/s` Studio, `/settings`. They are\n * declared before custom views, so a screen at one of them was listed in the\n * sidebar and opened the built-in page instead.\n */\nconst RESERVED_SCREEN_SLUGS: readonly string[] = [\"c\", \"s\", \"settings\"];\n\nexport interface GenerateViewOptions {\n projectRoot: string;\n slug: string;\n /** Register as a tab on this table's records (its slug) instead of as a screen. */\n collection?: string;\n /** The label in the sidebar or on the tab. Defaults to the slug in sentence case. */\n name?: string;\n /** A Lucide icon name for the sidebar. Screens only. */\n icon?: string;\n /** Replace an existing view file. Registration is never duplicated. */\n force?: boolean;\n}\n\nexport interface PlannedFile {\n /** Absolute path. */\n path: string;\n contents: string;\n action: \"create\" | \"update\" | \"replace\";\n}\n\nexport interface GenerateViewPlan {\n kind: \"app\" | \"entity\";\n componentName: string;\n viewFile: string;\n files: PlannedFile[];\n /** Steps the command could not take itself, as sentences to print. */\n manualSteps: string[];\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Names\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** `orders-board` → `OrdersBoardView`; `sales-view` → `SalesView`, not `SalesViewView`. */\nexport function viewComponentName(slug: string): string {\n const pascal = slug.split(\"-\").map(part => part.charAt(0).toUpperCase() + part.slice(1)).join(\"\");\n return pascal.endsWith(\"View\") ? pascal : `${pascal}View`;\n}\n\n/** `orders-board` → `Orders board`: labels are sentence case in the admin. */\nexport function viewLabel(slug: string): string {\n const words = slug.split(\"-\").join(\" \");\n return words.charAt(0).toUpperCase() + words.slice(1);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Reading source without a parser\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * The source with every string, template literal, regular expression and\n * comment blanked out, character for character, so brackets and keys can be\n * found by position without being fooled by a `{` inside a string. String\n * contents become `_` (they are still \"something\"), comments become spaces.\n *\n * Exported for its tests.\n */\nexport function maskCode(source: string): string {\n const out = source.split(\"\");\n let i = 0;\n const blank = (from: number, to: number, fill: string) => {\n for (let k = from; k < to; k++) if (out[k] !== \"\\n\") out[k] = fill;\n };\n const previousSignificant = (at: number): string => {\n for (let k = at - 1; k >= 0; k--) {\n const ch = out[k];\n if (ch !== \" \" && ch !== \"\\t\" && ch !== \"\\n\" && ch !== \"\\r\") return ch;\n }\n return \"\";\n };\n while (i < source.length) {\n const ch = source[i];\n const next = source[i + 1];\n if (ch === \"/\" && next === \"/\") {\n const end = source.indexOf(\"\\n\", i);\n const stop = end === -1 ? source.length : end;\n blank(i, stop, \" \");\n i = stop;\n } else if (ch === \"/\" && next === \"*\") {\n const end = source.indexOf(\"*/\", i + 2);\n const stop = end === -1 ? source.length : end + 2;\n blank(i, stop, \" \");\n i = stop;\n } else if (ch === \"\\\"\" || ch === \"'\" || ch === \"`\") {\n let k = i + 1;\n while (k < source.length && source[k] !== ch) {\n if (source[k] === \"\\\\\") k++;\n k++;\n }\n blank(i + 1, k, \"_\");\n i = k + 1;\n } else if (ch === \"/\" && (previousSignificant(i) === \"\" || \"(,=:[!&|?{;\".includes(previousSignificant(i)))) {\n // A regular expression literal: `/` where a value is expected. Not\n // after `}`, which in a .tsx file is far more often `{value}/>`.\n let k = i + 1;\n let inClass = false;\n while (k < source.length && source[k] !== \"\\n\") {\n if (source[k] === \"\\\\\") k++;\n else if (source[k] === \"[\") inClass = true;\n else if (source[k] === \"]\") inClass = false;\n else if (source[k] === \"/\" && !inClass) break;\n k++;\n }\n blank(i + 1, k, \"_\");\n i = k + 1;\n } else {\n i++;\n }\n }\n return out.join(\"\");\n}\n\nconst CLOSERS: Record<string, string> = { \"{\": \"}\", \"[\": \"]\", \"(\": \")\" };\n\n/** The index of the bracket closing the one at `open`, in masked source. */\nfunction matchClose(masked: string, open: number): number {\n const stack: string[] = [];\n for (let i = open; i < masked.length; i++) {\n const ch = masked[i];\n if (ch in CLOSERS) stack.push(CLOSERS[ch]);\n else if (ch === \"}\" || ch === \"]\" || ch === \")\") {\n if (stack.pop() !== ch) return -1;\n if (stack.length === 0) return i;\n }\n }\n return -1;\n}\n\n/** The index of the innermost `{` still open at `at`, in masked source. */\nfunction enclosingBrace(masked: string, at: number): number {\n const stack: number[] = [];\n for (let i = 0; i < at; i++) {\n const ch = masked[i];\n if (ch === \"{\" || ch === \"[\" || ch === \"(\") stack.push(i);\n else if (ch === \"}\" || ch === \"]\" || ch === \")\") stack.pop();\n }\n for (let k = stack.length - 1; k >= 0; k--) {\n if (masked[stack[k]] === \"{\") return stack[k];\n }\n return -1;\n}\n\n/**\n * The position of `key:` as a direct property of the object whose `{` is at\n * `open`, followed by `opener` (`{` or `[`) — or -1.\n */\nfunction directProperty(masked: string, open: number, key: string, opener: \"{\" | \"[\"): { keyAt: number; valueOpen: number } | undefined {\n const close = matchClose(masked, open);\n if (close === -1) return undefined;\n const pattern = new RegExp(`(^|[\\\\s,{])${key}\\\\s*:\\\\s*\\\\${opener}`, \"g\");\n const body = masked.slice(open + 1, close);\n for (const match of body.matchAll(pattern)) {\n const keyAt = open + 1 + (match.index ?? 0) + match[1].length;\n if (enclosingBrace(masked, keyAt) !== open) continue;\n return { keyAt, valueOpen: open + 1 + (match.index ?? 0) + match[0].length - 1 };\n }\n return undefined;\n}\n\nfunction lineStart(source: string, at: number): number {\n return source.lastIndexOf(\"\\n\", at - 1) + 1;\n}\n\nfunction indentAt(source: string, at: number): string {\n const start = lineStart(source, at);\n return /^[ \\t]*/.exec(source.slice(start))?.[0] ?? \"\";\n}\n\n/**\n * The indentation step a file uses: the smallest non-zero leading run of\n * spaces, not counting the ` * ` lines of a block comment.\n */\nfunction indentUnit(source: string): string {\n if (/^\\t/m.test(source)) return \"\\t\";\n let unit = Infinity;\n for (const match of source.matchAll(/^( +)[^\\s*]/gm)) unit = Math.min(unit, match[1].length);\n return \" \".repeat(Number.isFinite(unit) ? unit : 4);\n}\n\nfunction reindent(block: string, indent: string): string {\n return block.split(\"\\n\").map(line => (line ? indent + line : line)).join(\"\\n\");\n}\n\n/**\n * Insert `element` (already indented one level past `indent`) as the last item\n * of the array whose `[` is at `open`.\n */\nfunction appendToArray(source: string, masked: string, open: number, element: string): string {\n const close = matchClose(masked, open);\n const inner = masked.slice(open + 1, close);\n const indent = indentAt(source, open);\n if (inner.trim() === \"\") {\n return `${source.slice(0, open + 1)}\\n${element}\\n${indent}${source.slice(close)}`;\n }\n // After the last non-blank character of the content, keeping any comment\n // after it where it was.\n let last = close - 1;\n while (last > open && /\\s/.test(masked[last])) last--;\n const hasTrailingComma = masked[last] === \",\";\n const insertAt = last + 1;\n return `${source.slice(0, insertAt)}${hasTrailingComma ? \"\" : \",\"}\\n${element}${source.slice(insertAt)}`;\n}\n\n/** Add an import line after the file's last import statement. */\nfunction addImport(source: string, line: string): string {\n const masked = maskCode(source);\n let end = 0;\n for (const match of masked.matchAll(/^import\\b[\\s\\S]*?[\"'][^\"'\\n]*[\"'];?[ \\t]*$/gm)) {\n end = (match.index ?? 0) + match[0].length;\n }\n if (end === 0) return `${line}\\n${source}`;\n return `${source.slice(0, end)}\\n${line}${source.slice(end)}`;\n}\n\n/** A path import from `fromDir` to `toFile`, without extension, always starting with `.`. */\nfunction relativeImport(fromDir: string, toFile: string): string {\n const relative = path.relative(fromDir, toFile).split(path.sep).join(\"/\").replace(/\\.tsx?$/, \"\");\n return relative.startsWith(\".\") ? relative : `./${relative}`;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Where things are\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** The admin's frontend directory: the static app that mounts the CMS, or `frontend/`. */\nexport function resolveFrontendDir(projectRoot: string): string | undefined {\n try {\n const cms = cmsMountOf(loadManifest(projectRoot).manifest);\n if (cms) return path.join(projectRoot, cms.app.root);\n } catch {\n // A malformed rebase.json is reported by the commands that own it.\n }\n const fallback = path.join(projectRoot, \"frontend\");\n return fs.existsSync(path.join(fallback, \"src\")) ? fallback : undefined;\n}\n\n/** The tables directory, as the backend app declares it — one resolver for every command. */\nexport { resolveSchemaDir };\n\n/** Every source file under the admin's `src/cms`, sorted: where table customizations live. */\nfunction customizationFiles(dir: string): string[] {\n if (!fs.existsSync(dir)) return [];\n const out: string[] = [];\n const entries = fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));\n for (const entry of entries) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n if (entry.name !== \"node_modules\") out.push(...customizationFiles(full));\n } else if (/\\.tsx?$/.test(entry.name) && !/\\.(test|spec|d)\\.tsx?$/.test(entry.name)) {\n out.push(full);\n }\n }\n return out;\n}\n\n/**\n * Every `customizeTable(\"<slug>\", {` of a table, in code (not in a comment or\n * a string): the file, and where the options object opens. Empty when no file\n * under `cmsDir` customizes the table.\n */\nfunction findCustomization(cmsDir: string, slug: string): { file: string; optionsOpen: number }[] {\n const found: { file: string; optionsOpen: number }[] = [];\n const call = /\\bcustomizeTable\\s*(?:<[^>]*>)?\\(\\s*([\"'`])([^\"'`\\n]+)\\1\\s*,\\s*\\{/g;\n for (const file of customizationFiles(cmsDir)) {\n const source = fs.readFileSync(file, \"utf8\");\n const masked = maskCode(source);\n for (const match of source.matchAll(call)) {\n const at = match.index ?? 0;\n if (match[2] !== slug || masked[at] !== \"c\") continue;\n found.push({ file, optionsOpen: at + match[0].length - 1 });\n }\n }\n return found;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// The files\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * The scaffolds live in `templates/views/` rather than in template literals\n * here: they import React and the admin packages, and this package's sources\n * must not name those, even inside a string (`pnpm check:types-headless`).\n */\nfunction viewTemplate(name: string): string {\n const cliRoot = findCliRoot(__dirname);\n if (!cliRoot) throw new Error(`The CLI's templates/views folder is missing from ${__dirname}.`);\n return fs.readFileSync(path.join(cliRoot, \"templates\", \"views\", name), \"utf8\");\n}\n\n/** Walk up to the package root, which holds `templates/views`. */\nfunction findCliRoot(from: string): string | null {\n const root = path.parse(from).root;\n let dir = from;\n while (dir && dir !== root) {\n if (fs.existsSync(path.join(dir, \"templates\", \"views\"))) return dir;\n dir = path.dirname(dir);\n }\n return null;\n}\n\ntype ViewTemplateOptions = { slug: string; componentName: string; label: string; collection: string };\n\n/** The `{ key, name, Builder }` an entity view is registered as, with `unit` indentation inside. */\nfunction entityViewEntry(view: { key: string; name: string; componentName: string }, unit: string): string {\n return [\n \"{\",\n `${unit}key: ${JSON.stringify(view.key)},`,\n `${unit}name: ${JSON.stringify(view.name)},`,\n `${unit}Builder: ${view.componentName}`,\n \"}\"\n ].join(\"\\n\");\n}\n\n/**\n * A label as JSX text: written as is when it is plain, as a string expression\n * when it holds a character JSX reads — `{`, `}`, `<`, `>`, `&`. Pasted raw,\n * `--name \"KPIs {beta}\"` wrote `<Typography>KPIs {beta}</Typography>`, and the\n * view did not compile (\"Cannot find name 'beta'\").\n */\nfunction jsxText(text: string): string {\n return /[{}<>&]/.test(text) ? `{${JSON.stringify(text)}}` : text;\n}\n\n/** A label inside the leading `/** … *\\/` comment: one line, and no `*\\/` to close it early. */\nfunction commentText(text: string): string {\n return text.replace(/[\\r\\n]+/g, \" \").replaceAll(\"*/\", \"*\\\\/\");\n}\n\nfunction fillViewTemplate(template: string, options: ViewTemplateOptions): string {\n const { slug, componentName, label, collection } = options;\n return template\n .replaceAll(\"\\\"__COLLECTION__\\\"\", JSON.stringify(collection))\n .replaceAll(\"__COLLECTION__\", collection)\n .replaceAll(\"__COMPONENT__\", componentName)\n .replaceAll(\"__label_jsx__\", jsxText(label.toLowerCase()))\n .replaceAll(\"__LABEL_JSX__\", jsxText(label))\n .replaceAll(\"__label__\", commentText(label.toLowerCase()))\n .replaceAll(\"__LABEL__\", commentText(label))\n .replaceAll(\"__SLUG__\", slug);\n}\n\nexport function appViewSource(options: ViewTemplateOptions): string {\n return fillViewTemplate(viewTemplate(\"AppView.tsx.tmpl\"), options);\n}\n\nexport function entityViewSource(options: ViewTemplateOptions): string {\n return fillViewTemplate(viewTemplate(\"EntityView.tsx.tmpl\"), options);\n}\n\nfunction viewsIndexHeader(): string {\n return viewTemplate(\"index.ts.tmpl\");\n}\n\nfunction appViewEntry(options: { slug: string; label: string; icon: string; componentName: string }, unit: string): string {\n return [\n \"{\",\n `${unit}slug: ${JSON.stringify(options.slug)},`,\n `${unit}name: ${JSON.stringify(options.label)},`,\n `${unit}icon: ${JSON.stringify(options.icon)},`,\n `${unit}view: ${options.componentName}`,\n \"}\"\n ].join(\"\\n\");\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Planning\n// ─────────────────────────────────────────────────────────────────────────────\n\nfunction readIfExists(file: string): string | undefined {\n return fs.existsSync(file) ? fs.readFileSync(file, \"utf8\") : undefined;\n}\n\n/**\n * The frontend's package.json gains `@rebasepro/cms-types` when it lacks it.\n *\n * The view files import their prop types from it, and under pnpm a package the\n * frontend does not declare does not resolve from the frontend — the frontend's\n * `tsc` would fail on the first generated view. The version is the one the\n * frontend already uses for `@rebasepro/cms`, so the two cannot drift.\n */\nfunction planCmsTypesDependency(frontendDir: string, files: PlannedFile[], manualSteps: string[]): void {\n const manifestFile = path.join(frontendDir, \"package.json\");\n const raw = readIfExists(manifestFile);\n if (raw === undefined) return;\n let manifest: { dependencies?: Record<string, string>; devDependencies?: Record<string, string> };\n try {\n manifest = JSON.parse(raw);\n } catch {\n return;\n }\n const declared = { ...manifest.devDependencies, ...manifest.dependencies };\n if (declared[\"@rebasepro/cms-types\"]) return;\n const version = declared[\"@rebasepro/cms\"] ?? declared[\"@rebasepro/app\"];\n if (!version) return;\n const dependencies = { ...manifest.dependencies, \"@rebasepro/cms-types\": version };\n const sorted = Object.fromEntries(Object.entries(dependencies).sort(([a], [b]) => a.localeCompare(b)));\n const indent = /^(\\s+)\"/m.exec(raw)?.[1] ?? \" \";\n files.push({\n path: manifestFile,\n contents: `${JSON.stringify({ ...manifest, dependencies: sorted }, null, indent)}\\n`,\n action: \"update\"\n });\n manualSteps.push(`Run your package manager's install: ${path.basename(frontendDir)}/package.json now depends on @rebasepro/cms-types, which the view imports its types from.`);\n}\n\nfunction defaultCollectionFor(projectRoot: string): string {\n const slugs = declaredTables(resolveSchemaDir(projectRoot)).map(entry => entry.slug);\n return slugs.find(slug => slug !== \"users\") ?? slugs[0] ?? \"users\";\n}\n\n/**\n * Everything `rebase generate view` would write, without writing it.\n *\n * @throws UsageError when the slug is not a slug, there is no admin panel, the\n * view already exists (without `force`), or `--collection` names nothing.\n */\nexport function planGenerateView(options: GenerateViewOptions): GenerateViewPlan {\n const { projectRoot, slug } = options;\n if (!SLUG_PATTERN.test(slug)) {\n throw new UsageError(\n `\"${slug}\" is not a view slug: use lowercase letters, digits and dashes, starting with a letter (e.g. orders-board).`\n );\n }\n if (!options.collection && RESERVED_SCREEN_SLUGS.includes(slug)) {\n throw new UsageError(\n `\"${slug}\" is reserved: the admin's own routes answer /${slug}, so a screen there would never show. ` +\n `Pick another slug (e.g. ${slug === \"settings\" ? \"app-settings\" : `${slug}-view`}).`\n );\n }\n const frontendDir = resolveFrontendDir(projectRoot);\n if (!frontendDir) {\n throw new UsageError(\n \"This project has no admin panel to add a view to: rebase.json declares no app with a `cms` mount, and there is no frontend/src. \" +\n \"A project created with `rebase init --headless` has no admin.\"\n );\n }\n\n const componentName = viewComponentName(slug);\n const label = options.name?.trim() || viewLabel(slug);\n const viewsDir = path.join(frontendDir, \"src\", \"views\");\n const viewFile = path.join(viewsDir, `${componentName}.tsx`);\n const files: PlannedFile[] = [];\n const manualSteps: string[] = [];\n\n const viewExists = fs.existsSync(viewFile);\n if (viewExists && !options.force) {\n throw new UsageError(\n `${path.relative(projectRoot, viewFile)} already exists. Pass --force to replace it; its registration is kept.`\n );\n }\n const viewAction: PlannedFile[\"action\"] = viewExists ? \"replace\" : \"create\";\n\n if (options.collection) {\n const kind = \"entity\" as const;\n const table = options.collection;\n const schemaDir = resolveSchemaDir(projectRoot);\n const declared = declaredTables(schemaDir);\n if (!declared.some(entry => entry.slug === table)) {\n const known = [...new Set(declared.map(entry => entry.slug))].sort();\n throw new UsageError(\n `No table with slug \"${table}\" under ${path.relative(projectRoot, schemaDir) || \".\"}.` +\n (known.length ? ` Declared: ${known.join(\", \")}.` : \"\")\n );\n }\n const cmsDir = path.join(frontendDir, \"src\", \"cms\");\n const customizations = findCustomization(cmsDir, table);\n if (customizations.length > 1) {\n throw new UsageError(\n `More than one customizeTable(\"${table}\", …) under ${path.relative(projectRoot, cmsDir)}: ` +\n `${[...new Set(customizations.map(entry => path.relative(projectRoot, entry.file)))].join(\", \")}.`\n );\n }\n\n files.push({\n path: viewFile,\n contents: entityViewSource({ slug, componentName, label, collection: table }),\n action: viewAction\n });\n\n const view = { key: slug, name: label, componentName };\n if (customizations.length === 1) {\n const [{ file, optionsOpen }] = customizations;\n const importLine = `import { ${componentName} } from \"${relativeImport(path.dirname(file), viewFile)}\";`;\n const source = fs.readFileSync(file, \"utf8\");\n const updated = registerEntityView(source, optionsOpen, view);\n const where = path.relative(projectRoot, file);\n if (updated === \"already\") {\n // Registered on an earlier run: --force replaced the file only.\n } else if (updated === undefined) {\n manualSteps.push(\n `Add this to the entityViews of customizeTable(\"${table}\", …) in ${where}: ` +\n `{ key: ${JSON.stringify(slug)}, name: ${JSON.stringify(label)}, Builder: ${componentName} }, and ${importLine}`\n );\n } else {\n files.push({ path: file, contents: addImport(updated, importLine), action: \"update\" });\n }\n } else {\n const identifier = `${tableIdentifier(table)}Cms`;\n const file = path.join(cmsDir, `${table}.tsx`);\n if (fs.existsSync(file)) {\n throw new UsageError(\n `${path.relative(projectRoot, file)} exists but holds no customizeTable(\"${table}\", …): ` +\n \"add the record tab to the table's customization by hand, or move that file aside.\"\n );\n }\n const unit = \" \";\n files.push({\n path: file,\n contents: [\n \"import { customizeTable } from \\\"@rebasepro/cms\\\";\",\n `import { ${componentName} } from \"${relativeImport(cmsDir, viewFile)}\";`,\n \"\",\n `export const ${identifier} = customizeTable(\"${table}\", {`,\n `${unit}entityViews: [`,\n reindent(entityViewEntry(view, unit), unit + unit),\n `${unit}]`,\n \"});\",\n \"\"\n ].join(\"\\n\"),\n action: \"create\"\n });\n // Handed to the admin where the project lists its customizations:\n // a `tableCustomizations` list exported by `cms/index.ts`, else\n // the one `App.tsx` passes to `<RebaseCMS>`.\n const indexFile = path.join(cmsDir, \"index.ts\");\n const appFile = path.join(frontendDir, \"src\", \"App.tsx\");\n const index = readIfExists(indexFile);\n const app = readIfExists(appFile);\n const listedInIndex = index === undefined ? undefined : listCustomization(index, identifier, `./${table}`);\n const listedInApp = listedInIndex === undefined && app !== undefined\n ? listCustomization(app, identifier, `./cms/${table}`)\n : undefined;\n if (listedInIndex !== undefined) {\n if (listedInIndex !== \"already\") files.push({ path: indexFile, contents: listedInIndex, action: \"update\" });\n } else if (listedInApp !== undefined) {\n if (listedInApp !== \"already\") files.push({ path: appFile, contents: listedInApp, action: \"update\" });\n } else {\n manualSteps.push(\n `Hand the customization to the admin: import { ${identifier} } from \"./cms/${table}\" and add it to ` +\n `<RebaseCMS tableCustomizations={[…]}> in ${path.relative(projectRoot, appFile)}.`\n );\n }\n }\n planCmsTypesDependency(frontendDir, files, manualSteps);\n return { kind, componentName, viewFile, files, manualSteps };\n }\n\n files.push({\n path: viewFile,\n contents: appViewSource({ slug, componentName, label, collection: defaultCollectionFor(projectRoot) }),\n action: viewAction\n });\n\n // The list of screens.\n const indexFile = path.join(viewsDir, \"index.ts\");\n const existingIndex = readIfExists(indexFile);\n const icon = options.icon ?? \"LayoutDashboard\";\n if (existingIndex === undefined) {\n const unit = \" \";\n files.push({\n path: indexFile,\n contents: `${viewsIndexHeader()}import { ${componentName} } from \"./${componentName}\";\\n\\n` +\n `export const views: AppView[] = [\\n${reindent(appViewEntry({ slug, label, icon, componentName }, unit), unit)}\\n];\\n`,\n action: \"create\"\n });\n } else {\n const updated = registerAppView(existingIndex, { slug, label, icon, componentName });\n if (updated === undefined) {\n manualSteps.push(\n `Add { slug: ${JSON.stringify(slug)}, name: ${JSON.stringify(label)}, view: ${componentName} } to the views in ${path.relative(projectRoot, indexFile)}.`\n );\n } else if (updated !== \"already\") {\n files.push({ path: indexFile, contents: updated, action: \"update\" });\n }\n }\n\n // App.tsx hands the list to <RebaseCMS>, once.\n const appFile = path.join(frontendDir, \"src\", \"App.tsx\");\n const app = readIfExists(appFile);\n const wired = app === undefined ? undefined : wireViewsIntoApp(app);\n if (wired === undefined) {\n manualSteps.push(\n `Pass the screens to the admin: import { views } from \"./views\" and add views={views} to <RebaseCMS> in ${path.relative(projectRoot, appFile)}` +\n \" (or spread ...views into the views it already passes).\"\n );\n } else if (wired !== \"already\") {\n files.push({ path: appFile, contents: wired, action: \"update\" });\n }\n\n planCmsTypesDependency(frontendDir, files, manualSteps);\n return { kind: \"app\", componentName, viewFile, files, manualSteps };\n}\n\n/**\n * `views/index.ts` with one more entry, `\"already\"` when the slug is listed, or\n * `undefined` when the file has no `export const views … = [`.\n *\n * Exported for its tests.\n */\nexport function registerAppView(\n source: string,\n options: { slug: string; label: string; icon: string; componentName: string }\n): string | \"already\" | undefined {\n const masked = maskCode(source);\n const declaration = /export\\s+const\\s+views\\b[^=]*=\\s*\\[/.exec(masked);\n if (!declaration) return undefined;\n const open = declaration.index + declaration[0].length - 1;\n if (matchClose(masked, open) === -1) return undefined;\n const close = matchClose(masked, open);\n const listed = source.slice(open, close);\n if (new RegExp(`slug\\\\s*:\\\\s*[\"']${options.slug}[\"']`).test(listed)) return \"already\";\n\n const unit = indentUnit(source);\n const indent = indentAt(source, open) + unit;\n const element = reindent(appViewEntry(options, unit), indent);\n const appended = appendToArray(source, masked, open, element);\n return addImport(appended, `import { ${options.componentName} } from \"./${options.componentName}\";`);\n}\n\n/**\n * `App.tsx` with `views={views}` on `<RebaseCMS>` and its import, `\"already\"`\n * when it passes exactly that, or `undefined` when it cannot be done safely:\n * no `<RebaseCMS`, a `views` prop of its own, or a `views` name already in scope.\n *\n * Exported for its tests.\n */\nexport function wireViewsIntoApp(source: string): string | \"already\" | undefined {\n const masked = maskCode(source);\n const tag = /<RebaseCMS\\b/.exec(masked);\n if (!tag) return undefined;\n const tagEnd = masked.indexOf(\">\", tag.index);\n if (tagEnd === -1) return undefined;\n const attributes = masked.slice(tag.index, tagEnd);\n const importsViews = /import\\s*\\{\\s*views\\s*\\}\\s*from\\s*[\"']\\.\\/views(?:\\/index)?[\"']/.test(source);\n if (/\\sviews\\s*=/.test(attributes)) {\n return importsViews && /\\sviews\\s*=\\s*\\{\\s*views\\s*\\}/.test(attributes) ? \"already\" : undefined;\n }\n if (/\\bviews\\b/.test(masked)) return undefined;\n\n const insertAt = tag.index + \"<RebaseCMS\".length;\n const afterTag = source.slice(insertAt);\n const nextLine = /^[ \\t]*\\r?\\n([ \\t]*)\\S/.exec(afterTag);\n const attribute = nextLine ? `\\n${nextLine[1]}views={views}` : \" views={views}\";\n const withProp = source.slice(0, insertAt) + attribute + source.slice(insertAt);\n return addImport(withProp, \"import { views } from \\\"./views\\\";\");\n}\n\n/**\n * The customization file with a `{ key, name, Builder }` entry in the\n * `entityViews` of the `customizeTable(…)` options object whose `{` is at\n * `optionsOpen`; `\"already\"` when that key is there; `undefined` when the\n * shape cannot be read. The component's import is the caller's to add.\n *\n * Exported for its tests.\n */\nexport function registerEntityView(\n source: string,\n optionsOpen: number,\n view: { key: string; name: string; componentName: string }\n): string | \"already\" | undefined {\n const masked = maskCode(source);\n const close = matchClose(masked, optionsOpen);\n if (close === -1) return undefined;\n const unit = indentUnit(source);\n const entry = entityViewEntry(view, unit);\n\n const entityViews = directProperty(masked, optionsOpen, \"entityViews\", \"[\");\n if (entityViews) {\n const listClose = matchClose(masked, entityViews.valueOpen);\n if (listClose === -1) return undefined;\n const listed = source.slice(entityViews.valueOpen, listClose);\n if (new RegExp(`key\\\\s*:\\\\s*[\"']${view.key}[\"']|[\"']${view.key}[\"']`).test(listed)) return \"already\";\n const indent = indentAt(source, entityViews.keyAt) + unit;\n return appendToArray(source, masked, entityViews.valueOpen, reindent(entry, indent));\n }\n\n // `entityViews` as the first property of the options.\n const indent = indentAt(source, optionsOpen) + unit;\n const block = `${indent}entityViews: [\\n${reindent(entry, indent + unit)}\\n${indent}]`;\n const empty = masked.slice(optionsOpen + 1, close).trim() === \"\";\n const insertAt = optionsOpen + 1;\n return empty\n ? `${source.slice(0, insertAt)}\\n${block}\\n${indentAt(source, optionsOpen)}${source.slice(close)}`\n : `${source.slice(0, insertAt)}\\n${block},${source.slice(insertAt)}`;\n}\n\n/**\n * A source with `identifier` imported from `importPath` and appended to its\n * list of table customizations — `export const tableCustomizations = [ … ]`\n * (`cms/index.ts`) or `tableCustomizations={[ … ]}` on `<RebaseCMS>`\n * (`App.tsx`); `\"already\"` when it is listed; `undefined` when the source has\n * no such list.\n *\n * Exported for its tests.\n */\nexport function listCustomization(source: string, identifier: string, importPath: string): string | \"already\" | undefined {\n const masked = maskCode(source);\n const declaration = /export\\s+const\\s+tableCustomizations\\b[^=]*=\\s*\\[/.exec(masked)\n ?? /\\btableCustomizations\\s*=\\s*\\{\\s*\\[/.exec(masked);\n if (!declaration) return undefined;\n const open = declaration.index + declaration[0].length - 1;\n const close = matchClose(masked, open);\n if (close === -1) return undefined;\n if (new RegExp(`\\\\b${identifier}\\\\b`).test(masked.slice(open, close))) return \"already\";\n const inner = masked.slice(open + 1, close);\n let appended: string;\n if (inner.trim() !== \"\" && !inner.includes(\"\\n\")) {\n // A list written on one line stays on one line.\n let last = close - 1;\n while (last > open && /\\s/.test(masked[last])) last--;\n const comma = masked[last] === \",\" ? \" \" : \", \";\n appended = `${source.slice(0, last + 1)}${comma}${identifier}${source.slice(last + 1)}`;\n } else {\n const unit = indentUnit(source);\n appended = appendToArray(source, masked, open, `${indentAt(source, open)}${unit}${identifier}`);\n }\n return addImport(appended, `import { ${identifier} } from \"${importPath}\";`);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// The command\n// ─────────────────────────────────────────────────────────────────────────────\n\nfunction printHelp(): void {\n console.log(`\n${chalk.bold(\"rebase generate\")} — scaffold code into this project\n\n${chalk.bold(\"Usage\")}\n rebase generate view <slug> A screen of the admin, in the sidebar\n rebase generate view <slug> --collection <slug> A tab on every record of a table\n\n${chalk.bold(\"What it writes\")}\n <frontend>/src/views/<Name>View.tsx The component, drawn with @rebasepro/ui\n <frontend>/src/views/index.ts The screens list (AppView[]), wired into\n <RebaseCMS views> in App.tsx on first run\n With --collection, the table's customizeTable(…) in <frontend>/src/cms gains\n an entityViews entry with the component (a new <slug>.tsx when it has none).\n\n${chalk.bold(\"Options\")}\n --collection <slug> Register as a record tab of the table with this slug\n --name <label> Sidebar or tab label ${chalk.gray(\"(default: the slug in sentence case)\")}\n --icon <Lucide name> Sidebar icon for a screen ${chalk.gray(\"(default: LayoutDashboard)\")}\n --dry-run List what would change, and change nothing\n --force Replace an existing view file\n -h, --help Show this help\n`.trim());\n}\n\nexport async function generateCommand(subcommand: string | undefined, rawArgs: string[] = []): Promise<void> {\n if (subcommand === undefined || subcommand === \"--help\" || (subcommand !== \"view\" && wantsHelp(rawArgs))) {\n printHelp();\n return;\n }\n switch (subcommand) {\n case \"view\":\n await generateViewCommand(rawArgs);\n return;\n default:\n throw new UsageError(`Unknown generate command \"${subcommand}\". Available: ${GENERATE_SUBCOMMANDS.join(\", \")}. See \\`rebase generate --help\\`.`);\n }\n}\n\nasync function generateViewCommand(rawArgs: string[]): Promise<void> {\n if (wantsHelp(rawArgs)) {\n printHelp();\n return;\n }\n const { flags, positionals } = parseCommandArgs({\n spec: VIEW_FLAGS,\n rawArgs,\n commandWords: 2,\n command: \"generate view\",\n maxPositionals: 1\n });\n const slug = positionals[0];\n if (!slug) {\n throw new UsageError(\"Name the view: `rebase generate view <slug>`, e.g. `rebase generate view orders-board`.\");\n }\n if (flags[\"--icon\"] && flags[\"--collection\"]) {\n throw new UsageError(\"--icon is for a screen in the sidebar; a record tab (--collection) has no icon here.\");\n }\n\n const projectRoot = requireProjectRoot();\n const plan = planGenerateView({\n projectRoot,\n slug,\n collection: flags[\"--collection\"],\n name: flags[\"--name\"],\n icon: flags[\"--icon\"],\n force: Boolean(flags[\"--force\"])\n });\n const dryRun = Boolean(flags[\"--dry-run\"]);\n\n for (const file of plan.files) {\n if (!dryRun) {\n fs.mkdirSync(path.dirname(file.path), { recursive: true });\n fs.writeFileSync(file.path, file.contents);\n }\n const verb = file.action === \"create\" ? \"created\" : file.action === \"replace\" ? \"replaced\" : \"updated\";\n console.log(`${chalk.green(\"✓\")} ${dryRun ? `would be ${verb}` : verb} ${path.relative(projectRoot, file.path)}`);\n }\n for (const step of plan.manualSteps) {\n console.log(`${chalk.yellow(\"!\")} ${step}`);\n }\n const where = plan.kind === \"app\" ? `/${slug} in the admin` : `a \"${flags[\"--name\"]?.trim() || viewLabel(slug)}\" tab on each ${flags[\"--collection\"]} record`;\n console.log(chalk.gray(` ${plan.componentName} renders at ${where}. Edit ${path.relative(projectRoot, plan.viewFile)} to build the screen.`));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;;AAG7D,IAAa,uBAAuB,CAAC,MAAM;AAE3C,IAAM,aAAa;CACf,gBAAgB;CAChB,UAAU;CACV,UAAU;CACV,aAAa;CACb,WAAW;AACf;;AAGA,IAAM,eAAe;;;;;;;AAQrB,IAAM,wBAA2C;CAAC;CAAK;CAAK;AAAU;;AAoCtE,SAAgB,kBAAkB,MAAsB;CACpD,MAAM,SAAS,KAAK,MAAM,GAAG,CAAC,CAAC,KAAI,SAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;CAChG,OAAO,OAAO,SAAS,MAAM,IAAI,SAAS,GAAG,OAAO;AACxD;;AAGA,SAAgB,UAAU,MAAsB;CAC5C,MAAM,QAAQ,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;CACtC,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,MAAM,CAAC;AACxD;;;;;;;;;AAcA,SAAgB,SAAS,QAAwB;CAC7C,MAAM,MAAM,OAA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