@prenta/cli 0.14.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 (207) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-test.log +353 -0
  3. package/CHANGELOG.md +404 -0
  4. package/LICENSE +21 -0
  5. package/README.md +30 -0
  6. package/dist/__tests__/db-init.test.d.ts +2 -0
  7. package/dist/__tests__/db-init.test.d.ts.map +1 -0
  8. package/dist/__tests__/db-init.test.js +127 -0
  9. package/dist/__tests__/db-init.test.js.map +1 -0
  10. package/dist/__tests__/db-sync-resolver.test.d.ts +2 -0
  11. package/dist/__tests__/db-sync-resolver.test.d.ts.map +1 -0
  12. package/dist/__tests__/db-sync-resolver.test.js +25 -0
  13. package/dist/__tests__/db-sync-resolver.test.js.map +1 -0
  14. package/dist/__tests__/db-sync.test.d.ts +2 -0
  15. package/dist/__tests__/db-sync.test.d.ts.map +1 -0
  16. package/dist/__tests__/db-sync.test.js +167 -0
  17. package/dist/__tests__/db-sync.test.js.map +1 -0
  18. package/dist/__tests__/deployment-diagnostics.test.d.ts +2 -0
  19. package/dist/__tests__/deployment-diagnostics.test.d.ts.map +1 -0
  20. package/dist/__tests__/deployment-diagnostics.test.js +401 -0
  21. package/dist/__tests__/deployment-diagnostics.test.js.map +1 -0
  22. package/dist/__tests__/form-seed.test.d.ts +2 -0
  23. package/dist/__tests__/form-seed.test.d.ts.map +1 -0
  24. package/dist/__tests__/form-seed.test.js +79 -0
  25. package/dist/__tests__/form-seed.test.js.map +1 -0
  26. package/dist/__tests__/init.test.d.ts +2 -0
  27. package/dist/__tests__/init.test.d.ts.map +1 -0
  28. package/dist/__tests__/init.test.js +25 -0
  29. package/dist/__tests__/init.test.js.map +1 -0
  30. package/dist/__tests__/load-dotenv.test.d.ts +2 -0
  31. package/dist/__tests__/load-dotenv.test.d.ts.map +1 -0
  32. package/dist/__tests__/load-dotenv.test.js +40 -0
  33. package/dist/__tests__/load-dotenv.test.js.map +1 -0
  34. package/dist/__tests__/mcp-init.test.d.ts +2 -0
  35. package/dist/__tests__/mcp-init.test.d.ts.map +1 -0
  36. package/dist/__tests__/mcp-init.test.js +100 -0
  37. package/dist/__tests__/mcp-init.test.js.map +1 -0
  38. package/dist/__tests__/prisma-client-path.test.d.ts +2 -0
  39. package/dist/__tests__/prisma-client-path.test.d.ts.map +1 -0
  40. package/dist/__tests__/prisma-client-path.test.js +66 -0
  41. package/dist/__tests__/prisma-client-path.test.js.map +1 -0
  42. package/dist/__tests__/schema-fragment.test.d.ts +2 -0
  43. package/dist/__tests__/schema-fragment.test.d.ts.map +1 -0
  44. package/dist/__tests__/schema-fragment.test.js +40 -0
  45. package/dist/__tests__/schema-fragment.test.js.map +1 -0
  46. package/dist/__tests__/seed.test.d.ts +2 -0
  47. package/dist/__tests__/seed.test.d.ts.map +1 -0
  48. package/dist/__tests__/seed.test.js +207 -0
  49. package/dist/__tests__/seed.test.js.map +1 -0
  50. package/dist/__tests__/upgrade.test.d.ts +2 -0
  51. package/dist/__tests__/upgrade.test.d.ts.map +1 -0
  52. package/dist/__tests__/upgrade.test.js +41 -0
  53. package/dist/__tests__/upgrade.test.js.map +1 -0
  54. package/dist/__tests__/vercel-env-matrix.test.d.ts +2 -0
  55. package/dist/__tests__/vercel-env-matrix.test.d.ts.map +1 -0
  56. package/dist/__tests__/vercel-env-matrix.test.js +56 -0
  57. package/dist/__tests__/vercel-env-matrix.test.js.map +1 -0
  58. package/dist/commands/db-init.d.ts +24 -0
  59. package/dist/commands/db-init.d.ts.map +1 -0
  60. package/dist/commands/db-init.js +195 -0
  61. package/dist/commands/db-init.js.map +1 -0
  62. package/dist/commands/db-status.d.ts +3 -0
  63. package/dist/commands/db-status.d.ts.map +1 -0
  64. package/dist/commands/db-status.js +108 -0
  65. package/dist/commands/db-status.js.map +1 -0
  66. package/dist/commands/db-sync.d.ts +66 -0
  67. package/dist/commands/db-sync.d.ts.map +1 -0
  68. package/dist/commands/db-sync.js +310 -0
  69. package/dist/commands/db-sync.js.map +1 -0
  70. package/dist/commands/doctor.d.ts +5 -0
  71. package/dist/commands/doctor.d.ts.map +1 -0
  72. package/dist/commands/doctor.js +282 -0
  73. package/dist/commands/doctor.js.map +1 -0
  74. package/dist/commands/export.d.ts +3 -0
  75. package/dist/commands/export.d.ts.map +1 -0
  76. package/dist/commands/export.js +99 -0
  77. package/dist/commands/export.js.map +1 -0
  78. package/dist/commands/generate.d.ts +3 -0
  79. package/dist/commands/generate.d.ts.map +1 -0
  80. package/dist/commands/generate.js +24 -0
  81. package/dist/commands/generate.js.map +1 -0
  82. package/dist/commands/import.d.ts +3 -0
  83. package/dist/commands/import.d.ts.map +1 -0
  84. package/dist/commands/import.js +201 -0
  85. package/dist/commands/import.js.map +1 -0
  86. package/dist/commands/init.d.ts +4 -0
  87. package/dist/commands/init.d.ts.map +1 -0
  88. package/dist/commands/init.js +31 -0
  89. package/dist/commands/init.js.map +1 -0
  90. package/dist/commands/mcp.d.ts +3 -0
  91. package/dist/commands/mcp.d.ts.map +1 -0
  92. package/dist/commands/mcp.js +126 -0
  93. package/dist/commands/mcp.js.map +1 -0
  94. package/dist/commands/migrate-media-usage.d.ts +3 -0
  95. package/dist/commands/migrate-media-usage.d.ts.map +1 -0
  96. package/dist/commands/migrate-media-usage.js +52 -0
  97. package/dist/commands/migrate-media-usage.js.map +1 -0
  98. package/dist/commands/migrate-meta.d.ts +3 -0
  99. package/dist/commands/migrate-meta.d.ts.map +1 -0
  100. package/dist/commands/migrate-meta.js +81 -0
  101. package/dist/commands/migrate-meta.js.map +1 -0
  102. package/dist/commands/migrate-schema.d.ts +3 -0
  103. package/dist/commands/migrate-schema.d.ts.map +1 -0
  104. package/dist/commands/migrate-schema.js +84 -0
  105. package/dist/commands/migrate-schema.js.map +1 -0
  106. package/dist/commands/migrate-sections.d.ts +3 -0
  107. package/dist/commands/migrate-sections.d.ts.map +1 -0
  108. package/dist/commands/migrate-sections.js +56 -0
  109. package/dist/commands/migrate-sections.js.map +1 -0
  110. package/dist/commands/migrate.d.ts +3 -0
  111. package/dist/commands/migrate.d.ts.map +1 -0
  112. package/dist/commands/migrate.js +51 -0
  113. package/dist/commands/migrate.js.map +1 -0
  114. package/dist/commands/seed.d.ts +60 -0
  115. package/dist/commands/seed.d.ts.map +1 -0
  116. package/dist/commands/seed.js +585 -0
  117. package/dist/commands/seed.js.map +1 -0
  118. package/dist/commands/update-check.d.ts +3 -0
  119. package/dist/commands/update-check.d.ts.map +1 -0
  120. package/dist/commands/update-check.js +132 -0
  121. package/dist/commands/update-check.js.map +1 -0
  122. package/dist/commands/upgrade.d.ts +4 -0
  123. package/dist/commands/upgrade.d.ts.map +1 -0
  124. package/dist/commands/upgrade.js +175 -0
  125. package/dist/commands/upgrade.js.map +1 -0
  126. package/dist/commands/vercel-blob-link.d.ts +3 -0
  127. package/dist/commands/vercel-blob-link.d.ts.map +1 -0
  128. package/dist/commands/vercel-blob-link.js +83 -0
  129. package/dist/commands/vercel-blob-link.js.map +1 -0
  130. package/dist/deployment/diagnostics.d.ts +136 -0
  131. package/dist/deployment/diagnostics.d.ts.map +1 -0
  132. package/dist/deployment/diagnostics.js +575 -0
  133. package/dist/deployment/diagnostics.js.map +1 -0
  134. package/dist/index.d.ts +3 -0
  135. package/dist/index.d.ts.map +1 -0
  136. package/dist/index.js +47 -0
  137. package/dist/index.js.map +1 -0
  138. package/dist/utils/database.d.ts +21 -0
  139. package/dist/utils/database.d.ts.map +1 -0
  140. package/dist/utils/database.js +98 -0
  141. package/dist/utils/database.js.map +1 -0
  142. package/dist/utils/form-seed.d.ts +15 -0
  143. package/dist/utils/form-seed.d.ts.map +1 -0
  144. package/dist/utils/form-seed.js +97 -0
  145. package/dist/utils/form-seed.js.map +1 -0
  146. package/dist/utils/load-dotenv.d.ts +11 -0
  147. package/dist/utils/load-dotenv.d.ts.map +1 -0
  148. package/dist/utils/load-dotenv.js +47 -0
  149. package/dist/utils/load-dotenv.js.map +1 -0
  150. package/dist/utils/logger.d.ts +8 -0
  151. package/dist/utils/logger.d.ts.map +1 -0
  152. package/dist/utils/logger.js +16 -0
  153. package/dist/utils/logger.js.map +1 -0
  154. package/dist/utils/prisma-client-path.d.ts +20 -0
  155. package/dist/utils/prisma-client-path.d.ts.map +1 -0
  156. package/dist/utils/prisma-client-path.js +77 -0
  157. package/dist/utils/prisma-client-path.js.map +1 -0
  158. package/dist/vercel/client.d.ts +32 -0
  159. package/dist/vercel/client.d.ts.map +1 -0
  160. package/dist/vercel/client.js +74 -0
  161. package/dist/vercel/client.js.map +1 -0
  162. package/dist/vercel/env-matrix.d.ts +35 -0
  163. package/dist/vercel/env-matrix.d.ts.map +1 -0
  164. package/dist/vercel/env-matrix.js +66 -0
  165. package/dist/vercel/env-matrix.js.map +1 -0
  166. package/package.json +41 -0
  167. package/src/__tests__/db-init.test.ts +155 -0
  168. package/src/__tests__/db-sync-resolver.test.ts +29 -0
  169. package/src/__tests__/db-sync.test.ts +221 -0
  170. package/src/__tests__/deployment-diagnostics.test.ts +474 -0
  171. package/src/__tests__/form-seed.test.ts +91 -0
  172. package/src/__tests__/init.test.ts +30 -0
  173. package/src/__tests__/load-dotenv.test.ts +53 -0
  174. package/src/__tests__/mcp-init.test.ts +125 -0
  175. package/src/__tests__/prisma-client-path.test.ts +87 -0
  176. package/src/__tests__/schema-fragment.test.ts +51 -0
  177. package/src/__tests__/seed.test.ts +249 -0
  178. package/src/__tests__/upgrade.test.ts +44 -0
  179. package/src/__tests__/vercel-env-matrix.test.ts +65 -0
  180. package/src/commands/db-init.ts +211 -0
  181. package/src/commands/db-status.ts +122 -0
  182. package/src/commands/db-sync.ts +367 -0
  183. package/src/commands/doctor.ts +354 -0
  184. package/src/commands/export.ts +118 -0
  185. package/src/commands/generate.ts +26 -0
  186. package/src/commands/import.ts +228 -0
  187. package/src/commands/init.ts +36 -0
  188. package/src/commands/mcp.ts +181 -0
  189. package/src/commands/migrate-media-usage.ts +68 -0
  190. package/src/commands/migrate-meta.ts +107 -0
  191. package/src/commands/migrate-schema.ts +110 -0
  192. package/src/commands/migrate-sections.ts +73 -0
  193. package/src/commands/migrate.ts +56 -0
  194. package/src/commands/seed.ts +693 -0
  195. package/src/commands/update-check.ts +152 -0
  196. package/src/commands/upgrade.ts +202 -0
  197. package/src/commands/vercel-blob-link.ts +116 -0
  198. package/src/deployment/diagnostics.ts +735 -0
  199. package/src/index.ts +54 -0
  200. package/src/utils/database.ts +126 -0
  201. package/src/utils/form-seed.ts +137 -0
  202. package/src/utils/load-dotenv.ts +52 -0
  203. package/src/utils/logger.ts +26 -0
  204. package/src/utils/prisma-client-path.ts +81 -0
  205. package/src/vercel/client.ts +112 -0
  206. package/src/vercel/env-matrix.ts +112 -0
  207. package/tsconfig.json +9 -0
@@ -0,0 +1,735 @@
1
+ export type DiagnosticStatus = 'pass' | 'warn' | 'fail'
2
+
3
+ export interface DiagnosticCheck {
4
+ id: string
5
+ label: string
6
+ status: DiagnosticStatus
7
+ message: string
8
+ fix?: string
9
+ docs?: string
10
+ }
11
+
12
+ export interface DiagnosticReport {
13
+ status: DiagnosticStatus
14
+ checks: DiagnosticCheck[]
15
+ }
16
+
17
+ export const REQUIRED_CMS_MODELS = [
18
+ 'User',
19
+ 'Session',
20
+ 'Document',
21
+ 'Media',
22
+ 'Version',
23
+ 'Folder',
24
+ 'Redirect',
25
+ 'FormSubmission',
26
+ 'AuditLog',
27
+ 'PasswordResetToken',
28
+ 'MediaUsage',
29
+ 'ScriptTag',
30
+ 'PageTemplate',
31
+ 'SavedSection',
32
+ ] as const
33
+
34
+ export const REQUIRED_ENV_VARS = [
35
+ 'DATABASE_URL',
36
+ 'CMS_SECRET',
37
+ 'CMS_ENCRYPTION_KEY',
38
+ 'NEXT_PUBLIC_SITE_URL',
39
+ ] as const
40
+
41
+ /** Vars the per-environment Vercel matrix treats as deploy-blocking. */
42
+ export const VERCEL_MATRIX_REQUIRED = [
43
+ 'DATABASE_URL',
44
+ 'DIRECT_DATABASE_URL',
45
+ 'CMS_SECRET',
46
+ 'CMS_ENCRYPTION_KEY',
47
+ 'NEXT_PUBLIC_SITE_URL',
48
+ 'CRON_SECRET',
49
+ ] as const
50
+
51
+ /** Vars the matrix surfaces as advisory (feature-gated, not deploy-blocking). */
52
+ export const VERCEL_MATRIX_OPTIONAL = [
53
+ 'BLOB_READ_WRITE_TOKEN',
54
+ 'UPSTASH_REDIS_REST_URL',
55
+ 'UPSTASH_REDIS_REST_TOKEN',
56
+ 'RESEND_API_KEY',
57
+ ] as const
58
+
59
+ export interface DiagnosticInput {
60
+ schemaModels: Set<string>
61
+ schemaContent?: string
62
+ configContent?: string
63
+ env: Record<string, string | undefined>
64
+ packageManager: string
65
+ schemaPath: string
66
+ mode?: 'doctor' | 'deploy'
67
+ projectFiles?: ProjectFileSignals
68
+ }
69
+
70
+ /** Optional on-disk project signals for site-launch checks. */
71
+ export interface ProjectFileSignals {
72
+ catchAllPage?: string
73
+ cmsLib?: string
74
+ apiRoute?: string
75
+ nextConfig?: string
76
+ llmsRoute?: string
77
+ robotsRoute?: string
78
+ sitemapRoute?: string
79
+ /** Raw `prenta.seed.json` when present (forms launch kit checks). */
80
+ seedFile?: string
81
+ /** Astro public site `src/lib/cms.ts` (split deploy). */
82
+ astroCmsLib?: string
83
+ /** Astro catch-all page source. */
84
+ astroCatchAll?: string
85
+ /** True when `site/astro.config.*` exists (astro-split scaffold). */
86
+ astroConfigPresent?: boolean
87
+ }
88
+
89
+ export const RECOMMENDED_PRODUCTION_PLUGINS = [
90
+ { id: 'seo', importPattern: /seoPlugin\s*\(/ },
91
+ { id: 'forms', importPattern: /formsPlugin\s*\(/ },
92
+ { id: 'redirects', importPattern: /redirectsPlugin\s*\(/ },
93
+ { id: 'media', importPattern: /mediaPlugin\s*\(/ },
94
+ { id: 'email', importPattern: /emailPlugin\s*\(/ },
95
+ ] as const
96
+
97
+ export function missingModels(schemaModels: Set<string>): string[] {
98
+ return REQUIRED_CMS_MODELS.filter((model) => !schemaModels.has(model))
99
+ }
100
+
101
+ export function missingEnvVars(env: Record<string, string | undefined>): string[] {
102
+ return REQUIRED_ENV_VARS.filter((name) => !env[name])
103
+ }
104
+
105
+ export type BlobLinkState = 'ok' | 'partial' | 'token-format' | 'none'
106
+
107
+ /**
108
+ * Classify the local Vercel Blob wiring.
109
+ *
110
+ * Marketplace Blob provisioning injects `BLOB_STORE_ID` (+ webhook key). On Vercel,
111
+ * `VERCEL_OIDC_TOKEN` is injected at runtime — no `BLOB_READ_WRITE_TOKEN` in project
112
+ * env. Legacy stores still use the read-write token.
113
+ */
114
+ export function detectBlobLinkState(
115
+ env: Record<string, string | undefined>,
116
+ configContent?: string,
117
+ ): BlobLinkState {
118
+ const token = env.BLOB_READ_WRITE_TOKEN
119
+ if (token) {
120
+ return token.startsWith('vercel_blob_') ? 'ok' : 'token-format'
121
+ }
122
+
123
+ if (env.BLOB_STORE_ID?.trim()) {
124
+ return 'ok'
125
+ }
126
+
127
+ const hasPartialSignals =
128
+ Boolean(env.BLOB_WEBHOOK_PUBLIC_KEY) ||
129
+ (configContent ? /vercel-blob|platform-vercel|vercelBlob/i.test(configContent) : false)
130
+
131
+ return hasPartialSignals ? 'partial' : 'none'
132
+ }
133
+
134
+ export function detectPackageManager(lockfiles: Set<string>): string {
135
+ if (lockfiles.has('pnpm-lock.yaml')) return 'pnpm'
136
+ if (lockfiles.has('yarn.lock')) return 'yarn'
137
+ if (lockfiles.has('package-lock.json')) return 'npm'
138
+ return 'npm'
139
+ }
140
+
141
+ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport {
142
+ const checks: DiagnosticCheck[] = []
143
+ const models = missingModels(input.schemaModels)
144
+ const envVars =
145
+ input.mode === 'deploy'
146
+ ? [
147
+ ...missingEnvVars(input.env),
148
+ ...(!input.env.DIRECT_DATABASE_URL ? ['DIRECT_DATABASE_URL'] : []),
149
+ ]
150
+ : missingEnvVars(input.env)
151
+ const fieldProblems = input.schemaContent ? missingCriticalFields(input.schemaContent) : []
152
+ const pageBuilderRisk = input.configContent
153
+ ? detectsFlatMarketingPageModel(input.configContent)
154
+ : false
155
+
156
+ checks.push({
157
+ id: 'schema-models',
158
+ label: 'Prisma schema models',
159
+ status: models.length === 0 ? 'pass' : 'fail',
160
+ message:
161
+ models.length === 0
162
+ ? 'All deploy-critical Prenta models are present.'
163
+ : `Missing deploy-critical Prenta models: ${models.join(', ')}.`,
164
+ fix:
165
+ models.length === 0
166
+ ? undefined
167
+ : `Run \`prenta db:init --schema ${input.schemaPath}\` for new schemas, or update the existing Prenta block from the database setup docs, then create and apply a Prisma migration.`,
168
+ docs: 'https://prentacms.dev/docs/database-setup',
169
+ })
170
+
171
+ checks.push({
172
+ id: 'schema-fields',
173
+ label: 'Prisma schema fields',
174
+ status: fieldProblems.length === 0 ? 'pass' : 'fail',
175
+ message:
176
+ fieldProblems.length === 0
177
+ ? 'Deploy-critical model fields are present.'
178
+ : `Missing deploy-critical model fields: ${fieldProblems.join(', ')}.`,
179
+ fix:
180
+ fieldProblems.length === 0
181
+ ? undefined
182
+ : 'Update the Prenta Prisma models from the database setup docs, then create and apply a Prisma migration.',
183
+ docs: 'https://prentacms.dev/docs/database-setup',
184
+ })
185
+
186
+ checks.push({
187
+ id: 'environment',
188
+ label: 'Required environment variables',
189
+ status: envVars.length === 0 ? 'pass' : 'fail',
190
+ message:
191
+ envVars.length === 0
192
+ ? 'Required deployment environment variables are set.'
193
+ : `Missing required environment variables: ${envVars.join(', ')}.`,
194
+ fix:
195
+ envVars.length === 0
196
+ ? undefined
197
+ : `Set missing environment variables before deploying: ${envVars.join(', ')}.`,
198
+ docs: 'https://prentacms.dev/docs/environment-variables',
199
+ })
200
+
201
+ const blobState = detectBlobLinkState(input.env, input.configContent)
202
+ checks.push({
203
+ id: 'blob-storage',
204
+ label: 'Vercel Blob storage',
205
+ status: blobState === 'partial' ? 'fail' : blobState === 'token-format' ? 'warn' : 'pass',
206
+ message:
207
+ blobState === 'partial'
208
+ ? 'Vercel Blob appears configured (vercel-blob / webhook key) but BLOB_STORE_ID is missing. Media uploads will fail until the store is connected to this project.'
209
+ : blobState === 'token-format'
210
+ ? 'BLOB_READ_WRITE_TOKEN does not start with `vercel_blob_` — verify it is a real Vercel Blob read-write token.'
211
+ : blobState === 'ok'
212
+ ? input.env.BLOB_READ_WRITE_TOKEN
213
+ ? 'BLOB_READ_WRITE_TOKEN is configured.'
214
+ : 'Vercel Marketplace Blob is linked (BLOB_STORE_ID). Uploads use OIDC on Vercel; no read-write token required.'
215
+ : 'No Vercel Blob storage configured (skipped).',
216
+ fix:
217
+ blobState === 'partial'
218
+ ? 'Connect a Vercel Blob store to the project from the Storage tab, then `vercel env pull`. Validate with `prenta vercel:blob-link`.'
219
+ : blobState === 'token-format'
220
+ ? 'Re-copy the read-write token from the Vercel Blob store (Storage tab) and re-pull your environment.'
221
+ : undefined,
222
+ docs:
223
+ blobState === 'partial' || blobState === 'token-format'
224
+ ? 'https://prentacms.dev/docs/deployment'
225
+ : undefined,
226
+ })
227
+
228
+ checks.push({
229
+ id: 'package-manager',
230
+ label: 'Package manager',
231
+ status: 'pass',
232
+ message: `Detected ${input.packageManager}. Use the same package manager for install, build, and deploy checks.`,
233
+ })
234
+
235
+ checks.push({
236
+ id: 'design-first-page-builder',
237
+ label: 'Design-first page builder fit',
238
+ status: pageBuilderRisk ? 'warn' : 'pass',
239
+ message: pageBuilderRisk
240
+ ? 'A pages collection appears to model a designed marketing page as flat hero/body/CTA fields. For marketing, service, location, landing, and homepage routes, prefer a page-builder template with blocks, saved sections, forms, media, and seeded layout content unless field-mapped mode was explicitly approved.'
241
+ : 'No obvious flat marketing-page model detected in the Prenta config.',
242
+ fix: pageBuilderRisk
243
+ ? 'Create a design inventory and block coverage plan, then model section-based pages with page-builder content or document why field-mapped mode is intentional.'
244
+ : undefined,
245
+ docs: pageBuilderRisk ? 'https://prentacms.dev/docs/design-first-page-builder' : undefined,
246
+ })
247
+
248
+ const missingPlugins = input.configContent
249
+ ? detectMissingProductionPlugins(input.configContent)
250
+ : []
251
+ checks.push({
252
+ id: 'production-plugins',
253
+ label: 'Production plugin bundle',
254
+ status: missingPlugins.length === 0 ? 'pass' : 'warn',
255
+ message:
256
+ missingPlugins.length === 0
257
+ ? 'Recommended production plugins (SEO, forms, redirects, media, email) are registered.'
258
+ : `Missing recommended production plugins in prenta.config.ts: ${missingPlugins.join(', ')}.`,
259
+ fix:
260
+ missingPlugins.length === 0
261
+ ? undefined
262
+ : 'Register seoPlugin(), formsPlugin(), redirectsPlugin(), mediaPlugin(), and emailPlugin() in prenta.config.ts (new scaffolds include them by default).',
263
+ docs:
264
+ missingPlugins.length === 0
265
+ ? undefined
266
+ : 'https://prentacms.dev/docs/prototype-to-production',
267
+ })
268
+
269
+ const seoSiteUrlOk = detectSeoSiteUrl(input.configContent, input.env)
270
+ checks.push({
271
+ id: 'seo-site-url',
272
+ label: 'SEO site URL',
273
+ status: seoSiteUrlOk ? 'pass' : 'warn',
274
+ message: seoSiteUrlOk
275
+ ? 'Production site URL is configured via NEXT_PUBLIC_SITE_URL and/or prenta.config.ts seo.siteUrl.'
276
+ : 'Neither NEXT_PUBLIC_SITE_URL nor prenta.config.ts seo.siteUrl appears configured — canonical URLs, sitemaps, and JSON-LD may be wrong.',
277
+ fix: seoSiteUrlOk
278
+ ? undefined
279
+ : 'Set NEXT_PUBLIC_SITE_URL to your production origin (no trailing slash) and align prenta.config.ts seo.siteUrl.',
280
+ docs: seoSiteUrlOk ? undefined : 'https://prentacms.dev/docs/environment-variables',
281
+ })
282
+
283
+ if (input.projectFiles) {
284
+ const astroSplit = detectsAstroSplitSite(input.projectFiles)
285
+ if (astroSplit) {
286
+ checks.push({
287
+ id: 'astro-split-site',
288
+ label: 'Astro public site (split)',
289
+ status: 'pass',
290
+ message:
291
+ 'Detected an Astro public site (site/) using Prenta site helpers — CMS host should serve admin + /api/cms only.',
292
+ docs: 'https://prentacms.dev/docs/astro-public-site',
293
+ })
294
+
295
+ const astroCmsOk = detectsAstroCmsHelpers(input.projectFiles)
296
+ checks.push({
297
+ id: 'astro-cms-helpers',
298
+ label: 'Astro site client',
299
+ status: astroCmsOk ? 'pass' : 'warn',
300
+ message: astroCmsOk
301
+ ? 'Astro site uses createAstroSiteHelpers / PRENTA_CMS_URL.'
302
+ : 'Astro site/ is present but src/lib/cms.ts does not use createAstroSiteHelpers or PRENTA_CMS_URL.',
303
+ fix: astroCmsOk
304
+ ? undefined
305
+ : 'In site/src/lib/cms.ts import createAstroSiteHelpers from @prenta/core/astro/site and set PRENTA_CMS_URL.',
306
+ docs: 'https://prentacms.dev/docs/astro-public-site',
307
+ })
308
+ }
309
+
310
+ const seoRoutes = detectSeoPublicRoutes(input.projectFiles)
311
+ // Astro-split moves SEO proxies under site/; missing Next root routes are expected.
312
+ const seoOk = seoRoutes.ok || astroSplit
313
+ checks.push({
314
+ id: 'seo-public-routes',
315
+ label: 'Root SEO routes',
316
+ status: seoOk ? 'pass' : 'warn',
317
+ message: seoOk
318
+ ? astroSplit && !seoRoutes.ok
319
+ ? 'SEO routes live on the Astro public site (split deploy) — Next root proxies are optional.'
320
+ : 'Root /llms.txt, /robots.txt, and /sitemap.xml routes (or equivalent rewrites) are present.'
321
+ : `Missing root SEO routes: ${seoRoutes.missing.join(', ')}.`,
322
+ fix: seoOk
323
+ ? undefined
324
+ : 'Add app/llms.txt/route.ts, app/robots.txt/route.ts, and app/sitemap.xml/route.ts (or next.config rewrites) — see create-prenta scaffold. For Astro split, add site/src/pages proxies instead.',
325
+ docs: seoOk ? undefined : 'https://prentacms.dev/docs/prototype-to-production',
326
+ })
327
+
328
+ const uncachedResolve = !astroSplit && detectsUncachedResolvePattern(input.projectFiles)
329
+ checks.push({
330
+ id: 'cached-resolve',
331
+ label: 'Cached /resolve for ISR',
332
+ status: uncachedResolve ? 'warn' : 'pass',
333
+ message: uncachedResolve
334
+ ? 'The public catch-all appears to call resolveDocument() directly for metadata and page renders without createNextSiteHelpers() caching — ISR may be blocked and /resolve may be hit twice per request.'
335
+ : astroSplit
336
+ ? 'Astro split deploy: use CMS CDN/runtime cache (layers 1–2); Next ISR helpers are optional on the CMS host.'
337
+ : 'Published pages use cached /resolve helpers suitable for ISR.',
338
+ fix: uncachedResolve
339
+ ? 'Adopt createNextSiteHelpers() from @prenta/core/next/site in lib/cms.ts and use getCachedPageMetadata / getCachedPublishedDocument in the catch-all (keep resolveDocument only for ?preview= drafts).'
340
+ : undefined,
341
+ docs: uncachedResolve ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
342
+ })
343
+
344
+ const clientSections = !astroSplit && detectsClientWrappedPublicSections(input.projectFiles)
345
+ checks.push({
346
+ id: 'public-sections-ssr',
347
+ label: 'Public sections SSR',
348
+ status: clientSections ? 'warn' : 'pass',
349
+ message: clientSections
350
+ ? "The public catch-all or its sections wrapper is marked 'use client' — keep <Sections> in a Server Component so HTML ships in the initial response."
351
+ : astroSplit
352
+ ? 'Astro split: render sections via @astrojs/react SSR (no client-only catch-all).'
353
+ : 'Public page sections render from a Server Component catch-all.',
354
+ fix: clientSections
355
+ ? "Remove 'use client' from the catch-all and any PageSections wrapper; register section renderers via a side-effect import in the site layout instead."
356
+ : undefined,
357
+ docs: clientSections ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
358
+ })
359
+
360
+ const missingJsonLd =
361
+ !astroSplit && detectsMissingJsonLdInCatchAll(input.projectFiles.catchAllPage)
362
+ checks.push({
363
+ id: 'structured-data-html',
364
+ label: 'JSON-LD in page HTML',
365
+ status: missingJsonLd ? 'warn' : 'pass',
366
+ message: missingJsonLd
367
+ ? 'The public catch-all does not render JSON-LD from /resolve — Rich Results and some AI crawlers expect structured data in the HTML body.'
368
+ : 'Published pages inject JSON-LD from cms-core into the server-rendered HTML.',
369
+ fix: missingJsonLd
370
+ ? 'Render result.jsonLd as a <script type="application/ld+json"> in the catch-all (see create-prenta scaffold).'
371
+ : undefined,
372
+ docs: missingJsonLd ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
373
+ })
374
+
375
+ const missingApiCache = detectsMissingApiCacheWiring(input.projectFiles.apiRoute)
376
+ checks.push({
377
+ id: 'api-cache-invalidation',
378
+ label: 'CMS API cache + invalidation',
379
+ status: missingApiCache ? 'warn' : 'pass',
380
+ message: missingApiCache
381
+ ? 'The CMS API route is missing publicReads caching and/or onInvalidate → revalidateTag wiring — /resolve may hit Postgres every request and ISR may stay stale after publish.'
382
+ : 'CMS public reads are CDN-cacheable and writes drain Next ISR via onInvalidate.',
383
+ fix: missingApiCache
384
+ ? 'Adopt the cache block from create-prenta app/api/cms/[[...cms]]/route.ts (publicReads + onInvalidate with revalidateTag).'
385
+ : undefined,
386
+ docs: missingApiCache ? 'https://prentacms.dev/docs/caching' : undefined,
387
+ })
388
+
389
+ const formsLaunch = detectFormsLaunchReadiness(input.configContent, input.projectFiles.seedFile)
390
+ if (formsLaunch.hasFormsPlugin) {
391
+ const contactReady = formsLaunch.hasContactForm && formsLaunch.hasContactPageWithForm
392
+ checks.push({
393
+ id: 'forms-contact-seed',
394
+ label: 'Contact form seed',
395
+ status: contactReady ? 'pass' : 'warn',
396
+ message: contactReady
397
+ ? 'Seed includes an active contact form and a /contact page with a form section.'
398
+ : formsLaunch.hasSeedFile
399
+ ? 'Forms plugin is enabled but prenta.seed.json is missing a contact form and/or a /contact page with a form section.'
400
+ : 'Forms plugin is enabled but no prenta.seed.json was found — add a contact form document and a page with a form section (or run populate from a seed that includes them).',
401
+ fix: contactReady
402
+ ? undefined
403
+ : 'Add a `forms` entry (slug `contact`, status `active`) and a published `/contact` page whose form section sets `formSlug: "contact"`. Marketing-custom scaffolds include this by default.',
404
+ docs: contactReady ? undefined : 'https://prentacms.dev/docs/forms-and-integrations',
405
+ })
406
+
407
+ checks.push({
408
+ id: 'forms-crm-webhook',
409
+ label: 'CRM webhook (Zapier)',
410
+ status: 'warn',
411
+ message:
412
+ 'Form webhooks are stored in the database — after populate, open Admin → Forms → Integrations and paste your Zapier Catch Hook URL (or enable email notifications).',
413
+ fix: 'Create a Zap with Webhooks by Zapier → Catch Hook, add the URL under Admin → Forms → Integrations, then send a test submission.',
414
+ docs: 'https://prentacms.dev/docs/forms-and-integrations',
415
+ })
416
+
417
+ const webmcp = detectFormsWebMcpReadiness(
418
+ input.configContent,
419
+ input.projectFiles.catchAllPage || input.projectFiles.astroCatchAll,
420
+ )
421
+ checks.push({
422
+ id: 'forms-webmcp',
423
+ label: 'Agent-ready forms (WebMCP)',
424
+ status: webmcp.status,
425
+ message: webmcp.message,
426
+ fix: webmcp.fix,
427
+ docs: webmcp.docs,
428
+ })
429
+ }
430
+ }
431
+
432
+ const status: DiagnosticStatus = checks.some((check) => check.status === 'fail')
433
+ ? 'fail'
434
+ : checks.some((check) => check.status === 'warn')
435
+ ? 'warn'
436
+ : 'pass'
437
+
438
+ return { status, checks }
439
+ }
440
+
441
+ export function buildDeploymentManifest() {
442
+ return {
443
+ schemaVersion: 1,
444
+ packageScope: '@prenta',
445
+ registry: 'https://registry.npmjs.org',
446
+ requiredModels: [...REQUIRED_CMS_MODELS],
447
+ requiredEnv: [...REQUIRED_ENV_VARS],
448
+ optionalEnv: [
449
+ 'DIRECT_DATABASE_URL',
450
+ 'CMS_ADMIN_EMAIL',
451
+ 'CMS_ADMIN_PASSWORD',
452
+ 'CRON_SECRET',
453
+ 'BLOB_READ_WRITE_TOKEN',
454
+ 'UPSTASH_REDIS_REST_URL',
455
+ 'UPSTASH_REDIS_REST_TOKEN',
456
+ 'RESEND_API_KEY',
457
+ ],
458
+ routes: {
459
+ apiHealth: '/api/cms/health',
460
+ apiBase: '/api/cms',
461
+ adminDefault: '/admin',
462
+ },
463
+ crons: {
464
+ scheduledPublish: '/api/cms/cron/publish',
465
+ cleanup: '/api/cms/cron/cleanup',
466
+ seoScan: '/api/cms/cron/seo-scan',
467
+ },
468
+ verification: {
469
+ preflight: 'prenta doctor',
470
+ production: 'prenta deploy:check',
471
+ postDeploy: 'prenta verify --full',
472
+ },
473
+ docs: {
474
+ deployment: 'https://prentacms.dev/docs/deployment',
475
+ databaseSetup: 'https://prentacms.dev/docs/database-setup',
476
+ environmentVariables: 'https://prentacms.dev/docs/environment-variables',
477
+ aiRunbook: 'https://prentacms.dev/docs/ai-runbook',
478
+ },
479
+ }
480
+ }
481
+
482
+ export function missingCriticalFields(schemaContent: string): string[] {
483
+ const requiredFields: Record<string, string[]> = {
484
+ ScriptTag: ['targetPaths', 'priority', 'enabled'],
485
+ PageTemplate: ['tree', 'builtIn', 'category'],
486
+ SavedSection: ['tree', 'usageCount', 'category'],
487
+ PasswordResetToken: ['tokenHash', 'expiresAt', 'usedAt'],
488
+ MediaUsage: ['mediaId', 'documentId', 'fieldPath'],
489
+ }
490
+ const missing: string[] = []
491
+
492
+ for (const [model, fields] of Object.entries(requiredFields)) {
493
+ const body =
494
+ schemaContent.match(new RegExp(`model\\s+${model}\\s+\\{([\\s\\S]*?)\\n\\}`))?.[1] ?? ''
495
+ if (!body) continue
496
+ for (const field of fields) {
497
+ if (!new RegExp(`^\\s*${field}\\s+`, 'm').test(body)) {
498
+ missing.push(`${model}.${field}`)
499
+ }
500
+ }
501
+ }
502
+
503
+ return missing
504
+ }
505
+
506
+ export function detectsFlatMarketingPageModel(configContent: string): boolean {
507
+ const normalized = configContent.toLowerCase()
508
+ const hasPagesCollection =
509
+ /\bpages\b/.test(normalized) || /slug\s*:\s*['"]pages['"]/.test(normalized)
510
+ if (!hasPagesCollection) return false
511
+
512
+ const hasPageBuilderSignals = [
513
+ 'pagebuilder',
514
+ 'page-builder',
515
+ "type: 'blocks'",
516
+ 'type: "blocks"',
517
+ 'layout:',
518
+ 'savedsections',
519
+ 'pagetemplate',
520
+ ].some((signal) => normalized.includes(signal.toLowerCase()))
521
+
522
+ if (hasPageBuilderSignals) return false
523
+
524
+ const flatMarketingSignals = [
525
+ 'heroheadline',
526
+ 'herosubheadline',
527
+ 'herotitle',
528
+ 'heroimage',
529
+ 'bodycontent',
530
+ 'ctabuttontext',
531
+ 'ctabuttonurl',
532
+ 'servicecards',
533
+ 'testimonial',
534
+ 'reviews',
535
+ ]
536
+
537
+ const signalCount = flatMarketingSignals.filter((signal) => normalized.includes(signal)).length
538
+ return signalCount >= 3
539
+ }
540
+
541
+ export function detectMissingProductionPlugins(configContent: string): string[] {
542
+ return RECOMMENDED_PRODUCTION_PLUGINS.filter(
543
+ ({ importPattern }) => !importPattern.test(configContent),
544
+ ).map(({ id }) => id)
545
+ }
546
+
547
+ export function detectSeoSiteUrl(
548
+ configContent: string | undefined,
549
+ env: Record<string, string | undefined>,
550
+ ): boolean {
551
+ const envUrl = env.NEXT_PUBLIC_SITE_URL?.trim()
552
+ if (envUrl) return true
553
+ if (!configContent) return false
554
+ return /seo\s*:\s*\{[\s\S]*?siteUrl\s*:/.test(configContent)
555
+ }
556
+
557
+ export function detectSeoPublicRoutes(files: ProjectFileSignals): {
558
+ ok: boolean
559
+ missing: string[]
560
+ } {
561
+ const missing: string[] = []
562
+ const hasLlms =
563
+ Boolean(files.llmsRoute?.trim()) || /llms\.txt|llms-full\.txt/.test(files.nextConfig ?? '')
564
+ const hasRobots = Boolean(files.robotsRoute?.trim()) || /robots\.txt/.test(files.nextConfig ?? '')
565
+ const hasSitemap =
566
+ Boolean(files.sitemapRoute?.trim()) || /sitemap\.xml|sitemaps\//.test(files.nextConfig ?? '')
567
+
568
+ if (!hasLlms) missing.push('/llms.txt')
569
+ if (!hasRobots) missing.push('/robots.txt')
570
+ if (!hasSitemap) missing.push('/sitemap.xml')
571
+ return { ok: missing.length === 0, missing }
572
+ }
573
+
574
+ export function detectsUncachedResolvePattern(files: ProjectFileSignals): boolean {
575
+ const catchAll = files.catchAllPage ?? ''
576
+ const cmsLib = files.cmsLib ?? ''
577
+ if (!catchAll.trim()) return false
578
+
579
+ const usesCachedHelpers =
580
+ /createNextSiteHelpers\s*\(/.test(cmsLib) ||
581
+ (/getCachedPublishedDocument/.test(cmsLib) && /getCachedPageMetadata/.test(cmsLib))
582
+
583
+ if (usesCachedHelpers && /getCachedPageMetadata/.test(catchAll)) {
584
+ return false
585
+ }
586
+
587
+ const metadataCallsResolve =
588
+ /generateMetadata[\s\S]*resolveDocument\s*\(/.test(catchAll) &&
589
+ !/getCachedPageMetadata/.test(catchAll)
590
+ const pageCallsResolve =
591
+ /resolveDocument\s*\(\s*urlPath\s*\)/.test(catchAll) &&
592
+ !/getCachedPublishedDocument/.test(catchAll)
593
+
594
+ return metadataCallsResolve || pageCallsResolve
595
+ }
596
+
597
+ export function detectsClientWrappedPublicSections(files: ProjectFileSignals): boolean {
598
+ const catchAll = files.catchAllPage ?? ''
599
+ if (!catchAll.trim()) return false
600
+ if (/^['"]use client['"]/m.test(catchAll.trimStart())) return true
601
+ if (/['"]use client['"][\s\S]*<Sections\b/.test(catchAll)) return true
602
+ return false
603
+ }
604
+
605
+ export function detectsMissingJsonLdInCatchAll(catchAllPage: string | undefined): boolean {
606
+ const catchAll = catchAllPage ?? ''
607
+ if (!catchAll.trim()) return false
608
+ return !/result\.jsonLd|jsonLdHtml/.test(catchAll)
609
+ }
610
+
611
+ /** True when the project has an Astro public site under `site/` (astro-split). */
612
+ export function detectsAstroSplitSite(files: ProjectFileSignals): boolean {
613
+ return Boolean(
614
+ files.astroConfigPresent || files.astroCmsLib?.trim() || files.astroCatchAll?.trim(),
615
+ )
616
+ }
617
+
618
+ /** True when Astro cms lib uses the official helpers / PRENTA_CMS_URL. */
619
+ export function detectsAstroCmsHelpers(files: ProjectFileSignals): boolean {
620
+ const lib = files.astroCmsLib ?? ''
621
+ if (!lib.trim()) return false
622
+ return (
623
+ /createAstroSiteHelpers/.test(lib) ||
624
+ /@prenta\/core\/astro\/site/.test(lib) ||
625
+ /PRENTA_CMS_URL/.test(lib)
626
+ )
627
+ }
628
+
629
+ export function detectsMissingApiCacheWiring(apiRoute: string | undefined): boolean {
630
+ const route = apiRoute ?? ''
631
+ if (!route.trim()) return false
632
+ const hasInvalidate = /onInvalidate/.test(route)
633
+ const hasPublicReads = /publicReads/.test(route) && /enabled:\s*true/.test(route)
634
+ return !hasInvalidate || !hasPublicReads
635
+ }
636
+
637
+ export interface FormsLaunchReadiness {
638
+ hasFormsPlugin: boolean
639
+ hasSeedFile: boolean
640
+ hasContactForm: boolean
641
+ hasContactPageWithForm: boolean
642
+ }
643
+
644
+ /** Static signals for the forms launch kit (seed shape + forms plugin registration). */
645
+ export function detectFormsLaunchReadiness(
646
+ configContent: string | undefined,
647
+ seedFile: string | undefined,
648
+ ): FormsLaunchReadiness {
649
+ const hasFormsPlugin = /formsPlugin\s*\(/.test(configContent ?? '')
650
+ const seed = seedFile?.trim() ?? ''
651
+ const hasSeedFile = seed.length > 0
652
+
653
+ if (!hasFormsPlugin) {
654
+ return {
655
+ hasFormsPlugin: false,
656
+ hasSeedFile,
657
+ hasContactForm: false,
658
+ hasContactPageWithForm: false,
659
+ }
660
+ }
661
+
662
+ let hasContactForm = false
663
+ let hasContactPageWithForm = false
664
+
665
+ if (hasSeedFile) {
666
+ try {
667
+ const parsed = JSON.parse(seed) as {
668
+ collections?: {
669
+ forms?: Array<{ data?: { slug?: string }; slug?: string }>
670
+ pages?: Array<{
671
+ data?: {
672
+ slug?: string
673
+ path?: string
674
+ sections?: Array<{ sectionType?: string; content?: { formSlug?: string } }>
675
+ }
676
+ }>
677
+ }
678
+ }
679
+ const forms = parsed.collections?.forms ?? []
680
+ hasContactForm = forms.some((row) => {
681
+ const slug = row.data?.slug ?? row.slug
682
+ return slug === 'contact' || slug === 'contact-form'
683
+ })
684
+ const pages = parsed.collections?.pages ?? []
685
+ hasContactPageWithForm = pages.some((row) => {
686
+ const data = row.data
687
+ if (!data) return false
688
+ const isContact = data.path === '/contact' || data.slug === 'contact'
689
+ if (!isContact) return false
690
+ return (data.sections ?? []).some(
691
+ (section) => section.sectionType === 'form' && Boolean(section.content?.formSlug),
692
+ )
693
+ })
694
+ } catch {
695
+ // Invalid seed JSON — treat as missing contact kit.
696
+ }
697
+ }
698
+
699
+ return { hasFormsPlugin, hasSeedFile, hasContactForm, hasContactPageWithForm }
700
+ }
701
+
702
+ export function detectFormsWebMcpReadiness(
703
+ configContent: string | undefined,
704
+ catchAllPage: string | undefined,
705
+ ): { status: DiagnosticStatus; message: string; fix?: string; docs?: string } {
706
+ const disabled = /webmcp\s*:\s*\{[^}]*enabled\s*:\s*false/.test(configContent ?? '')
707
+ if (disabled) {
708
+ return {
709
+ status: 'warn',
710
+ message:
711
+ 'WebMCP agent-ready form annotations are disabled in prenta.config.ts — public forms will not expose declarative tools to AI browsers.',
712
+ fix: 'Remove `forms.webmcp.enabled: false` or set it to true (default). See Agent-Ready Forms docs.',
713
+ docs: 'https://prentacms.dev/docs/agent-ready-forms',
714
+ }
715
+ }
716
+
717
+ const catchAll = catchAllPage ?? ''
718
+ const prefetches = /prefetchPublicForms/.test(catchAll) && /prefetchedForms/.test(catchAll)
719
+ if (catchAll.trim() && !prefetches) {
720
+ return {
721
+ status: 'warn',
722
+ message:
723
+ 'Public catch-all does not prefetch form schemas for WebMCP HTML rendering — form sections may fall back to the client PrentaForm island.',
724
+ fix: 'Prefetch forms with collectFormSlugsFromSections() + prefetchPublicForms(getPublicForm, slugs) and pass prefetchedForms to <Sections> (see create-prenta scaffold).',
725
+ docs: 'https://prentacms.dev/docs/agent-ready-forms',
726
+ }
727
+ }
728
+
729
+ return {
730
+ status: 'pass',
731
+ message:
732
+ 'Public forms expose WebMCP declarative metadata by default; scaffold prefetches schemas for zero-JS PrentaFormHtml rendering.',
733
+ docs: 'https://prentacms.dev/docs/agent-ready-forms',
734
+ }
735
+ }