@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.
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +353 -0
- package/CHANGELOG.md +404 -0
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/__tests__/db-init.test.d.ts +2 -0
- package/dist/__tests__/db-init.test.d.ts.map +1 -0
- package/dist/__tests__/db-init.test.js +127 -0
- package/dist/__tests__/db-init.test.js.map +1 -0
- package/dist/__tests__/db-sync-resolver.test.d.ts +2 -0
- package/dist/__tests__/db-sync-resolver.test.d.ts.map +1 -0
- package/dist/__tests__/db-sync-resolver.test.js +25 -0
- package/dist/__tests__/db-sync-resolver.test.js.map +1 -0
- package/dist/__tests__/db-sync.test.d.ts +2 -0
- package/dist/__tests__/db-sync.test.d.ts.map +1 -0
- package/dist/__tests__/db-sync.test.js +167 -0
- package/dist/__tests__/db-sync.test.js.map +1 -0
- package/dist/__tests__/deployment-diagnostics.test.d.ts +2 -0
- package/dist/__tests__/deployment-diagnostics.test.d.ts.map +1 -0
- package/dist/__tests__/deployment-diagnostics.test.js +401 -0
- package/dist/__tests__/deployment-diagnostics.test.js.map +1 -0
- package/dist/__tests__/form-seed.test.d.ts +2 -0
- package/dist/__tests__/form-seed.test.d.ts.map +1 -0
- package/dist/__tests__/form-seed.test.js +79 -0
- package/dist/__tests__/form-seed.test.js.map +1 -0
- package/dist/__tests__/init.test.d.ts +2 -0
- package/dist/__tests__/init.test.d.ts.map +1 -0
- package/dist/__tests__/init.test.js +25 -0
- package/dist/__tests__/init.test.js.map +1 -0
- package/dist/__tests__/load-dotenv.test.d.ts +2 -0
- package/dist/__tests__/load-dotenv.test.d.ts.map +1 -0
- package/dist/__tests__/load-dotenv.test.js +40 -0
- package/dist/__tests__/load-dotenv.test.js.map +1 -0
- package/dist/__tests__/mcp-init.test.d.ts +2 -0
- package/dist/__tests__/mcp-init.test.d.ts.map +1 -0
- package/dist/__tests__/mcp-init.test.js +100 -0
- package/dist/__tests__/mcp-init.test.js.map +1 -0
- package/dist/__tests__/prisma-client-path.test.d.ts +2 -0
- package/dist/__tests__/prisma-client-path.test.d.ts.map +1 -0
- package/dist/__tests__/prisma-client-path.test.js +66 -0
- package/dist/__tests__/prisma-client-path.test.js.map +1 -0
- package/dist/__tests__/schema-fragment.test.d.ts +2 -0
- package/dist/__tests__/schema-fragment.test.d.ts.map +1 -0
- package/dist/__tests__/schema-fragment.test.js +40 -0
- package/dist/__tests__/schema-fragment.test.js.map +1 -0
- package/dist/__tests__/seed.test.d.ts +2 -0
- package/dist/__tests__/seed.test.d.ts.map +1 -0
- package/dist/__tests__/seed.test.js +207 -0
- package/dist/__tests__/seed.test.js.map +1 -0
- package/dist/__tests__/upgrade.test.d.ts +2 -0
- package/dist/__tests__/upgrade.test.d.ts.map +1 -0
- package/dist/__tests__/upgrade.test.js +41 -0
- package/dist/__tests__/upgrade.test.js.map +1 -0
- package/dist/__tests__/vercel-env-matrix.test.d.ts +2 -0
- package/dist/__tests__/vercel-env-matrix.test.d.ts.map +1 -0
- package/dist/__tests__/vercel-env-matrix.test.js +56 -0
- package/dist/__tests__/vercel-env-matrix.test.js.map +1 -0
- package/dist/commands/db-init.d.ts +24 -0
- package/dist/commands/db-init.d.ts.map +1 -0
- package/dist/commands/db-init.js +195 -0
- package/dist/commands/db-init.js.map +1 -0
- package/dist/commands/db-status.d.ts +3 -0
- package/dist/commands/db-status.d.ts.map +1 -0
- package/dist/commands/db-status.js +108 -0
- package/dist/commands/db-status.js.map +1 -0
- package/dist/commands/db-sync.d.ts +66 -0
- package/dist/commands/db-sync.d.ts.map +1 -0
- package/dist/commands/db-sync.js +310 -0
- package/dist/commands/db-sync.js.map +1 -0
- package/dist/commands/doctor.d.ts +5 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +282 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/export.d.ts +3 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +99 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/generate.d.ts +3 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +24 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/import.d.ts +3 -0
- package/dist/commands/import.d.ts.map +1 -0
- package/dist/commands/import.js +201 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +31 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +126 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/migrate-media-usage.d.ts +3 -0
- package/dist/commands/migrate-media-usage.d.ts.map +1 -0
- package/dist/commands/migrate-media-usage.js +52 -0
- package/dist/commands/migrate-media-usage.js.map +1 -0
- package/dist/commands/migrate-meta.d.ts +3 -0
- package/dist/commands/migrate-meta.d.ts.map +1 -0
- package/dist/commands/migrate-meta.js +81 -0
- package/dist/commands/migrate-meta.js.map +1 -0
- package/dist/commands/migrate-schema.d.ts +3 -0
- package/dist/commands/migrate-schema.d.ts.map +1 -0
- package/dist/commands/migrate-schema.js +84 -0
- package/dist/commands/migrate-schema.js.map +1 -0
- package/dist/commands/migrate-sections.d.ts +3 -0
- package/dist/commands/migrate-sections.d.ts.map +1 -0
- package/dist/commands/migrate-sections.js +56 -0
- package/dist/commands/migrate-sections.js.map +1 -0
- package/dist/commands/migrate.d.ts +3 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +51 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/seed.d.ts +60 -0
- package/dist/commands/seed.d.ts.map +1 -0
- package/dist/commands/seed.js +585 -0
- package/dist/commands/seed.js.map +1 -0
- package/dist/commands/update-check.d.ts +3 -0
- package/dist/commands/update-check.d.ts.map +1 -0
- package/dist/commands/update-check.js +132 -0
- package/dist/commands/update-check.js.map +1 -0
- package/dist/commands/upgrade.d.ts +4 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +175 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/commands/vercel-blob-link.d.ts +3 -0
- package/dist/commands/vercel-blob-link.d.ts.map +1 -0
- package/dist/commands/vercel-blob-link.js +83 -0
- package/dist/commands/vercel-blob-link.js.map +1 -0
- package/dist/deployment/diagnostics.d.ts +136 -0
- package/dist/deployment/diagnostics.d.ts.map +1 -0
- package/dist/deployment/diagnostics.js +575 -0
- package/dist/deployment/diagnostics.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/database.d.ts +21 -0
- package/dist/utils/database.d.ts.map +1 -0
- package/dist/utils/database.js +98 -0
- package/dist/utils/database.js.map +1 -0
- package/dist/utils/form-seed.d.ts +15 -0
- package/dist/utils/form-seed.d.ts.map +1 -0
- package/dist/utils/form-seed.js +97 -0
- package/dist/utils/form-seed.js.map +1 -0
- package/dist/utils/load-dotenv.d.ts +11 -0
- package/dist/utils/load-dotenv.d.ts.map +1 -0
- package/dist/utils/load-dotenv.js +47 -0
- package/dist/utils/load-dotenv.js.map +1 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +16 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/prisma-client-path.d.ts +20 -0
- package/dist/utils/prisma-client-path.d.ts.map +1 -0
- package/dist/utils/prisma-client-path.js +77 -0
- package/dist/utils/prisma-client-path.js.map +1 -0
- package/dist/vercel/client.d.ts +32 -0
- package/dist/vercel/client.d.ts.map +1 -0
- package/dist/vercel/client.js +74 -0
- package/dist/vercel/client.js.map +1 -0
- package/dist/vercel/env-matrix.d.ts +35 -0
- package/dist/vercel/env-matrix.d.ts.map +1 -0
- package/dist/vercel/env-matrix.js +66 -0
- package/dist/vercel/env-matrix.js.map +1 -0
- package/package.json +41 -0
- package/src/__tests__/db-init.test.ts +155 -0
- package/src/__tests__/db-sync-resolver.test.ts +29 -0
- package/src/__tests__/db-sync.test.ts +221 -0
- package/src/__tests__/deployment-diagnostics.test.ts +474 -0
- package/src/__tests__/form-seed.test.ts +91 -0
- package/src/__tests__/init.test.ts +30 -0
- package/src/__tests__/load-dotenv.test.ts +53 -0
- package/src/__tests__/mcp-init.test.ts +125 -0
- package/src/__tests__/prisma-client-path.test.ts +87 -0
- package/src/__tests__/schema-fragment.test.ts +51 -0
- package/src/__tests__/seed.test.ts +249 -0
- package/src/__tests__/upgrade.test.ts +44 -0
- package/src/__tests__/vercel-env-matrix.test.ts +65 -0
- package/src/commands/db-init.ts +211 -0
- package/src/commands/db-status.ts +122 -0
- package/src/commands/db-sync.ts +367 -0
- package/src/commands/doctor.ts +354 -0
- package/src/commands/export.ts +118 -0
- package/src/commands/generate.ts +26 -0
- package/src/commands/import.ts +228 -0
- package/src/commands/init.ts +36 -0
- package/src/commands/mcp.ts +181 -0
- package/src/commands/migrate-media-usage.ts +68 -0
- package/src/commands/migrate-meta.ts +107 -0
- package/src/commands/migrate-schema.ts +110 -0
- package/src/commands/migrate-sections.ts +73 -0
- package/src/commands/migrate.ts +56 -0
- package/src/commands/seed.ts +693 -0
- package/src/commands/update-check.ts +152 -0
- package/src/commands/upgrade.ts +202 -0
- package/src/commands/vercel-blob-link.ts +116 -0
- package/src/deployment/diagnostics.ts +735 -0
- package/src/index.ts +54 -0
- package/src/utils/database.ts +126 -0
- package/src/utils/form-seed.ts +137 -0
- package/src/utils/load-dotenv.ts +52 -0
- package/src/utils/logger.ts +26 -0
- package/src/utils/prisma-client-path.ts +81 -0
- package/src/vercel/client.ts +112 -0
- package/src/vercel/env-matrix.ts +112 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { access, readdir, readFile } from 'node:fs/promises'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import {
|
|
6
|
+
buildDeploymentManifest,
|
|
7
|
+
createDiagnosticReport,
|
|
8
|
+
detectPackageManager,
|
|
9
|
+
type ProjectFileSignals,
|
|
10
|
+
VERCEL_MATRIX_OPTIONAL,
|
|
11
|
+
VERCEL_MATRIX_REQUIRED,
|
|
12
|
+
type DiagnosticReport,
|
|
13
|
+
} from '../deployment/diagnostics.js'
|
|
14
|
+
import {
|
|
15
|
+
createVercelClient,
|
|
16
|
+
readVercelLink,
|
|
17
|
+
resolveVercelToken,
|
|
18
|
+
VercelApiError,
|
|
19
|
+
VERCEL_TARGETS,
|
|
20
|
+
} from '../vercel/client.js'
|
|
21
|
+
import { buildEnvMatrix, type EnvMatrix } from '../vercel/env-matrix.js'
|
|
22
|
+
import { loadProjectEnv } from '../utils/load-dotenv.js'
|
|
23
|
+
import { logger } from '../utils/logger.js'
|
|
24
|
+
|
|
25
|
+
async function fileExists(path: string): Promise<boolean> {
|
|
26
|
+
try {
|
|
27
|
+
await access(path)
|
|
28
|
+
return true
|
|
29
|
+
} catch {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function readSchemaModels(schemaPath: string): Promise<Set<string>> {
|
|
35
|
+
if (!(await fileExists(schemaPath))) return new Set()
|
|
36
|
+
const schema = await readFile(schemaPath, 'utf-8')
|
|
37
|
+
const models = new Set<string>()
|
|
38
|
+
const modelRegex = /^model\s+(\w+)\s*\{/gm
|
|
39
|
+
let match
|
|
40
|
+
while ((match = modelRegex.exec(schema)) !== null) {
|
|
41
|
+
models.add(match[1]!)
|
|
42
|
+
}
|
|
43
|
+
return models
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function readSchemaContent(schemaPath: string): Promise<string> {
|
|
47
|
+
if (!(await fileExists(schemaPath))) return ''
|
|
48
|
+
return readFile(schemaPath, 'utf-8')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function readOptionalFile(path: string): Promise<string> {
|
|
52
|
+
if (!(await fileExists(path))) return ''
|
|
53
|
+
return readFile(path, 'utf-8')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function readFirstExistingFile(cwd: string, candidates: string[]): Promise<string> {
|
|
57
|
+
for (const relative of candidates) {
|
|
58
|
+
const content = await readOptionalFile(resolve(cwd, relative))
|
|
59
|
+
if (content) return content
|
|
60
|
+
}
|
|
61
|
+
return ''
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function readProjectFileSignals(cwd: string): Promise<ProjectFileSignals> {
|
|
65
|
+
const [
|
|
66
|
+
catchAllPage,
|
|
67
|
+
cmsLib,
|
|
68
|
+
apiRoute,
|
|
69
|
+
nextConfig,
|
|
70
|
+
llmsRoute,
|
|
71
|
+
robotsRoute,
|
|
72
|
+
sitemapRoute,
|
|
73
|
+
seedFile,
|
|
74
|
+
astroCmsLib,
|
|
75
|
+
astroCatchAll,
|
|
76
|
+
astroConfigMjs,
|
|
77
|
+
astroConfigTs,
|
|
78
|
+
] = await Promise.all([
|
|
79
|
+
readFirstExistingFile(cwd, ['app/(site)/[[...path]]/page.tsx', 'app/[[...path]]/page.tsx']),
|
|
80
|
+
readOptionalFile(resolve(cwd, 'lib/cms.ts')),
|
|
81
|
+
readOptionalFile(resolve(cwd, 'app/api/cms/[[...cms]]/route.ts')),
|
|
82
|
+
readFirstExistingFile(cwd, ['next.config.ts', 'next.config.mjs', 'next.config.js']),
|
|
83
|
+
readOptionalFile(resolve(cwd, 'app/llms.txt/route.ts')),
|
|
84
|
+
readOptionalFile(resolve(cwd, 'app/robots.txt/route.ts')),
|
|
85
|
+
readOptionalFile(resolve(cwd, 'app/sitemap.xml/route.ts')),
|
|
86
|
+
readOptionalFile(resolve(cwd, 'prenta.seed.json')),
|
|
87
|
+
readOptionalFile(resolve(cwd, 'site/src/lib/cms.ts')),
|
|
88
|
+
readFirstExistingFile(cwd, [
|
|
89
|
+
'site/src/pages/[...path].astro',
|
|
90
|
+
'site/src/pages/[...slug].astro',
|
|
91
|
+
]),
|
|
92
|
+
readOptionalFile(resolve(cwd, 'site/astro.config.mjs')),
|
|
93
|
+
readOptionalFile(resolve(cwd, 'site/astro.config.ts')),
|
|
94
|
+
])
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
catchAllPage,
|
|
98
|
+
cmsLib,
|
|
99
|
+
apiRoute,
|
|
100
|
+
nextConfig,
|
|
101
|
+
llmsRoute,
|
|
102
|
+
robotsRoute,
|
|
103
|
+
sitemapRoute,
|
|
104
|
+
seedFile,
|
|
105
|
+
astroCmsLib,
|
|
106
|
+
astroCatchAll,
|
|
107
|
+
astroConfigPresent: Boolean(astroConfigMjs || astroConfigTs),
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function detectProjectPackageManager(): Promise<string> {
|
|
112
|
+
const entries = new Set(await readdir(process.cwd()))
|
|
113
|
+
return detectPackageManager(entries)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function printReport(title: string, report: DiagnosticReport): void {
|
|
117
|
+
console.log()
|
|
118
|
+
console.log(chalk.bold(title))
|
|
119
|
+
console.log(chalk.dim('─────────────────────────────────'))
|
|
120
|
+
for (const check of report.checks) {
|
|
121
|
+
const icon =
|
|
122
|
+
check.status === 'pass'
|
|
123
|
+
? chalk.green('PASS')
|
|
124
|
+
: check.status === 'warn'
|
|
125
|
+
? chalk.yellow('WARN')
|
|
126
|
+
: chalk.red('FAIL')
|
|
127
|
+
console.log(`${icon} ${check.label}: ${check.message}`)
|
|
128
|
+
if (check.fix) console.log(chalk.dim(` Fix: ${check.fix}`))
|
|
129
|
+
if (check.docs) console.log(chalk.dim(` Docs: ${check.docs}`))
|
|
130
|
+
}
|
|
131
|
+
console.log(chalk.dim('─────────────────────────────────'))
|
|
132
|
+
console.log(`Status: ${report.status.toUpperCase()}`)
|
|
133
|
+
console.log()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function buildReport(
|
|
137
|
+
schemaPath: string,
|
|
138
|
+
configPath: string,
|
|
139
|
+
mode: 'doctor' | 'deploy' = 'doctor',
|
|
140
|
+
) {
|
|
141
|
+
const resolvedSchema = resolve(process.cwd(), schemaPath)
|
|
142
|
+
const resolvedConfig = resolve(process.cwd(), configPath)
|
|
143
|
+
const cwd = process.cwd()
|
|
144
|
+
const [schemaModels, schemaContent, configContent, packageManager, projectFiles] =
|
|
145
|
+
await Promise.all([
|
|
146
|
+
readSchemaModels(resolvedSchema),
|
|
147
|
+
readSchemaContent(resolvedSchema),
|
|
148
|
+
readOptionalFile(resolvedConfig),
|
|
149
|
+
detectProjectPackageManager(),
|
|
150
|
+
readProjectFileSignals(cwd),
|
|
151
|
+
])
|
|
152
|
+
|
|
153
|
+
const env = await loadProjectEnv(process.cwd())
|
|
154
|
+
|
|
155
|
+
return createDiagnosticReport({
|
|
156
|
+
schemaModels,
|
|
157
|
+
schemaContent,
|
|
158
|
+
configContent,
|
|
159
|
+
env,
|
|
160
|
+
packageManager,
|
|
161
|
+
schemaPath,
|
|
162
|
+
mode,
|
|
163
|
+
projectFiles,
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function registerDoctorCommand(program: Command): void {
|
|
168
|
+
program
|
|
169
|
+
.command('doctor')
|
|
170
|
+
.description('Run AI-friendly preflight checks for an Prenta CMS project')
|
|
171
|
+
.option('--schema <path>', 'Path to schema.prisma', 'prisma/schema.prisma')
|
|
172
|
+
.option('--config <path>', 'Path to prenta.config.ts', 'prenta.config.ts')
|
|
173
|
+
.option('--json', 'Print machine-readable JSON')
|
|
174
|
+
.action(async (opts: { schema: string; config: string; json?: boolean }) => {
|
|
175
|
+
const report = await buildReport(opts.schema, opts.config, 'doctor')
|
|
176
|
+
if (opts.json) {
|
|
177
|
+
console.log(JSON.stringify(report, null, 2))
|
|
178
|
+
} else {
|
|
179
|
+
printReport('Prenta Doctor', report)
|
|
180
|
+
}
|
|
181
|
+
if (report.status === 'fail') process.exitCode = 1
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function printEnvMatrix(matrix: EnvMatrix): void {
|
|
186
|
+
const cell = (present: boolean): string => (present ? chalk.green(' Y ') : chalk.red(' . '))
|
|
187
|
+
const keyWidth = Math.max(24, ...matrix.rows.map((r) => `${r.key} (optional)`.length + 1))
|
|
188
|
+
|
|
189
|
+
console.log()
|
|
190
|
+
console.log(chalk.bold('Environment variable matrix (Vercel)'))
|
|
191
|
+
console.log(chalk.dim('─────────────────────────────────'))
|
|
192
|
+
console.log(`${'Variable'.padEnd(keyWidth)} Prod Prev Dev`)
|
|
193
|
+
for (const row of matrix.rows) {
|
|
194
|
+
const labelPlain = row.required ? row.key : `${row.key} (optional)`
|
|
195
|
+
const label = row.required ? row.key : chalk.dim(labelPlain)
|
|
196
|
+
console.log(
|
|
197
|
+
`${label}${' '.repeat(Math.max(1, keyWidth - labelPlain.length))}` +
|
|
198
|
+
`${cell(row.presence.production)} ${cell(row.presence.preview)} ${cell(row.presence.development)}`,
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
console.log(chalk.dim('─────────────────────────────────'))
|
|
202
|
+
console.log(chalk.dim('Y = set for that environment, . = missing'))
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function runVercelMatrix(opts: {
|
|
206
|
+
token?: string
|
|
207
|
+
project?: string
|
|
208
|
+
org?: string
|
|
209
|
+
json?: boolean
|
|
210
|
+
}): Promise<{ ok: boolean; matrix?: EnvMatrix }> {
|
|
211
|
+
const token = resolveVercelToken(opts.token)
|
|
212
|
+
if (!token) {
|
|
213
|
+
logger.error('No Vercel token found. Pass --token or set VERCEL_TOKEN to use --vercel.')
|
|
214
|
+
return { ok: false }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const link = opts.project
|
|
218
|
+
? { projectId: opts.project, orgId: opts.org }
|
|
219
|
+
: await readVercelLink(process.cwd())
|
|
220
|
+
if (!link?.projectId) {
|
|
221
|
+
logger.error('No linked Vercel project. Run `vercel link` or pass --project <id>.')
|
|
222
|
+
return { ok: false }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const client = createVercelClient({ token, teamId: link.orgId ?? opts.org })
|
|
226
|
+
try {
|
|
227
|
+
const envVars = await client.listProjectEnv(link.projectId)
|
|
228
|
+
const matrix = buildEnvMatrix(envVars, VERCEL_MATRIX_REQUIRED, VERCEL_MATRIX_OPTIONAL)
|
|
229
|
+
if (!opts.json) {
|
|
230
|
+
printEnvMatrix(matrix)
|
|
231
|
+
if (matrix.missingCritical.length > 0) {
|
|
232
|
+
for (const m of matrix.missingCritical) {
|
|
233
|
+
logger.error(`${m.key} missing on: ${m.targets.join(', ')}`)
|
|
234
|
+
}
|
|
235
|
+
logger.info(
|
|
236
|
+
`Add the missing variables in the Vercel dashboard (include Development for local \`vercel env pull\`). Targets checked: ${VERCEL_TARGETS.join(', ')}.`,
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return { ok: matrix.missingCritical.length === 0, matrix }
|
|
241
|
+
} catch (error) {
|
|
242
|
+
const message =
|
|
243
|
+
error instanceof VercelApiError
|
|
244
|
+
? error.message
|
|
245
|
+
: error instanceof Error
|
|
246
|
+
? error.message
|
|
247
|
+
: String(error)
|
|
248
|
+
logger.error(`Could not read project environment from Vercel: ${message}`)
|
|
249
|
+
return { ok: false }
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function registerDeployCheckCommand(program: Command): void {
|
|
254
|
+
program
|
|
255
|
+
.command('deploy:check')
|
|
256
|
+
.description('Check production deployment readiness for Prenta CMS')
|
|
257
|
+
.option('--schema <path>', 'Path to schema.prisma', 'prisma/schema.prisma')
|
|
258
|
+
.option('--config <path>', 'Path to prenta.config.ts', 'prenta.config.ts')
|
|
259
|
+
.option('--vercel', 'Read the linked Vercel project and print a per-environment matrix')
|
|
260
|
+
.option('--token <token>', 'Vercel access token (with --vercel; defaults to $VERCEL_TOKEN)')
|
|
261
|
+
.option('--project <id>', 'Vercel project id (with --vercel; defaults to .vercel/project.json)')
|
|
262
|
+
.option('--org <id>', 'Vercel team/org id (with --vercel)')
|
|
263
|
+
.option('--json', 'Print machine-readable JSON')
|
|
264
|
+
.action(
|
|
265
|
+
async (opts: {
|
|
266
|
+
schema: string
|
|
267
|
+
config: string
|
|
268
|
+
vercel?: boolean
|
|
269
|
+
token?: string
|
|
270
|
+
project?: string
|
|
271
|
+
org?: string
|
|
272
|
+
json?: boolean
|
|
273
|
+
}) => {
|
|
274
|
+
const report = await buildReport(opts.schema, opts.config, 'deploy')
|
|
275
|
+
const vercelResult = opts.vercel ? await runVercelMatrix(opts) : null
|
|
276
|
+
|
|
277
|
+
if (opts.json) {
|
|
278
|
+
console.log(
|
|
279
|
+
JSON.stringify(
|
|
280
|
+
{
|
|
281
|
+
...report,
|
|
282
|
+
manifest: buildDeploymentManifest(),
|
|
283
|
+
...(vercelResult ? { vercelMatrix: vercelResult.matrix ?? null } : {}),
|
|
284
|
+
},
|
|
285
|
+
null,
|
|
286
|
+
2,
|
|
287
|
+
),
|
|
288
|
+
)
|
|
289
|
+
} else {
|
|
290
|
+
printReport('Prenta Deploy Check', report)
|
|
291
|
+
console.log(chalk.dim('Run `prenta verify --full` after deployment succeeds.'))
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (report.status === 'fail' || (vercelResult && !vercelResult.ok)) {
|
|
295
|
+
process.exitCode = 1
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function registerVerifyCommand(program: Command): void {
|
|
302
|
+
program
|
|
303
|
+
.command('verify')
|
|
304
|
+
.description('Verify an installed or deployed Prenta CMS project')
|
|
305
|
+
.option('--full', 'Run the full verification checklist')
|
|
306
|
+
.option('--url <origin>', 'Deployed site origin to verify, for example https://example.com')
|
|
307
|
+
.option('--json', 'Print the deployment manifest as JSON')
|
|
308
|
+
.action(async (opts: { full?: boolean; url?: string; json?: boolean }) => {
|
|
309
|
+
const manifest = buildDeploymentManifest()
|
|
310
|
+
if (opts.json) {
|
|
311
|
+
console.log(JSON.stringify(manifest, null, 2))
|
|
312
|
+
return
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
console.log()
|
|
316
|
+
console.log(chalk.bold(opts.full ? 'Prenta Full Verification' : 'Prenta Verification'))
|
|
317
|
+
console.log(chalk.dim('─────────────────────────────────'))
|
|
318
|
+
console.log(`PASS Manifest generated for ${manifest.packageScope} packages.`)
|
|
319
|
+
if (!opts.url) {
|
|
320
|
+
console.log('WARN No --url provided, so remote health/admin endpoints were not checked.')
|
|
321
|
+
console.log(
|
|
322
|
+
chalk.dim('Run `prenta verify --full --url https://your-site.com` after deployment.'),
|
|
323
|
+
)
|
|
324
|
+
console.log()
|
|
325
|
+
return
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const origin = opts.url.replace(/\/$/, '')
|
|
329
|
+
const healthUrl = `${origin}${manifest.routes.apiHealth}`
|
|
330
|
+
const adminUrl = `${origin}${manifest.routes.adminDefault}`
|
|
331
|
+
let failed = false
|
|
332
|
+
|
|
333
|
+
for (const [label, url] of [
|
|
334
|
+
['Health', healthUrl],
|
|
335
|
+
['Admin', adminUrl],
|
|
336
|
+
] as const) {
|
|
337
|
+
try {
|
|
338
|
+
const response = await fetch(url, { method: 'GET' })
|
|
339
|
+
if (response.ok || response.status === 302 || response.status === 401) {
|
|
340
|
+
console.log(`PASS ${label} route responded at ${url}.`)
|
|
341
|
+
} else {
|
|
342
|
+
failed = true
|
|
343
|
+
console.log(`FAIL ${label} route returned HTTP ${response.status} at ${url}.`)
|
|
344
|
+
}
|
|
345
|
+
} catch (error) {
|
|
346
|
+
failed = true
|
|
347
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
348
|
+
console.log(`FAIL ${label} route could not be reached at ${url}: ${message}`)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
console.log()
|
|
352
|
+
if (failed) process.exitCode = 1
|
|
353
|
+
})
|
|
354
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { writeFile } from 'node:fs/promises'
|
|
3
|
+
import ora from 'ora'
|
|
4
|
+
import { logger } from '../utils/logger.js'
|
|
5
|
+
|
|
6
|
+
interface ExportOptions {
|
|
7
|
+
collection?: string
|
|
8
|
+
format: string
|
|
9
|
+
output?: string
|
|
10
|
+
includeDrafts?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function buildOutputPath(options: ExportOptions): string {
|
|
14
|
+
if (options.output) return options.output
|
|
15
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)
|
|
16
|
+
const ext = options.format === 'csv' ? 'csv' : 'json'
|
|
17
|
+
return `prenta-export-${timestamp}.${ext}`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function jsonToCsv(docs: any[]): string {
|
|
21
|
+
if (docs.length === 0) return ''
|
|
22
|
+
|
|
23
|
+
const keySet = new Set<string>()
|
|
24
|
+
for (const doc of docs) {
|
|
25
|
+
keySet.add('id')
|
|
26
|
+
keySet.add('collection')
|
|
27
|
+
keySet.add('status')
|
|
28
|
+
keySet.add('createdAt')
|
|
29
|
+
keySet.add('updatedAt')
|
|
30
|
+
if (doc.data && typeof doc.data === 'object') {
|
|
31
|
+
for (const key of Object.keys(doc.data)) {
|
|
32
|
+
keySet.add(`data.${key}`)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const headers = Array.from(keySet)
|
|
37
|
+
|
|
38
|
+
const escapeCsvValue = (val: unknown): string => {
|
|
39
|
+
if (val === null || val === undefined) return ''
|
|
40
|
+
const str = typeof val === 'object' ? JSON.stringify(val) : String(val)
|
|
41
|
+
if (str.includes(',') || str.includes('"') || str.includes('\n')) {
|
|
42
|
+
return `"${str.replace(/"/g, '""')}"`
|
|
43
|
+
}
|
|
44
|
+
return str
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const rows = docs.map((doc) => {
|
|
48
|
+
return headers
|
|
49
|
+
.map((header) => {
|
|
50
|
+
if (header.startsWith('data.')) {
|
|
51
|
+
const field = header.slice(5)
|
|
52
|
+
return escapeCsvValue(doc.data?.[field])
|
|
53
|
+
}
|
|
54
|
+
return escapeCsvValue(doc[header])
|
|
55
|
+
})
|
|
56
|
+
.join(',')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
return [headers.join(','), ...rows].join('\n')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function runExport(options: ExportOptions): Promise<void> {
|
|
63
|
+
const target = options.collection ?? 'all collections'
|
|
64
|
+
const spinner = ora(`Exporting ${target}…`).start()
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const { getDB } = await import('@prenta/core')
|
|
68
|
+
const db = getDB<any>()
|
|
69
|
+
|
|
70
|
+
const where: any = { deletedAt: null }
|
|
71
|
+
|
|
72
|
+
if (options.collection) {
|
|
73
|
+
where.collection = options.collection
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!options.includeDrafts) {
|
|
77
|
+
where.status = 'PUBLISHED'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const docs = await db.document.findMany({
|
|
81
|
+
where,
|
|
82
|
+
orderBy: { createdAt: 'desc' },
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
if (docs.length === 0) {
|
|
86
|
+
spinner.warn('No documents found matching the criteria.')
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const outputPath = buildOutputPath(options)
|
|
91
|
+
let content: string
|
|
92
|
+
|
|
93
|
+
if (options.format === 'csv') {
|
|
94
|
+
content = jsonToCsv(docs)
|
|
95
|
+
} else {
|
|
96
|
+
content = JSON.stringify(docs, null, 2)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
await writeFile(outputPath, content, 'utf-8')
|
|
100
|
+
spinner.succeed(`Exported ${docs.length} documents to ${outputPath}`)
|
|
101
|
+
} catch (err) {
|
|
102
|
+
spinner.fail('Export failed.')
|
|
103
|
+
const message = err instanceof Error ? err.message : String(err)
|
|
104
|
+
logger.error(message)
|
|
105
|
+
process.exit(1)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function registerExportCommand(program: Command): void {
|
|
110
|
+
program
|
|
111
|
+
.command('export')
|
|
112
|
+
.description('Export content to JSON or CSV files')
|
|
113
|
+
.option('-c, --collection <slug>', 'Export only the specified collection (default: all)')
|
|
114
|
+
.option('-f, --format <type>', 'Output format: json or csv', 'json')
|
|
115
|
+
.option('-o, --output <path>', 'Output file path (default: prenta-export-{timestamp}.{format})')
|
|
116
|
+
.option('--include-drafts', 'Include draft documents (default: published only)')
|
|
117
|
+
.action(runExport)
|
|
118
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import ora from 'ora'
|
|
3
|
+
import { logger } from '../utils/logger.js'
|
|
4
|
+
|
|
5
|
+
async function runGenerate(): Promise<void> {
|
|
6
|
+
const spinner = ora('Generating TypeScript types from schema…').start()
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
// Dynamically import the codegen module from cms-core
|
|
10
|
+
const { runCodegen } = await import('@prenta/core/codegen')
|
|
11
|
+
await runCodegen()
|
|
12
|
+
spinner.succeed('Type generation complete.')
|
|
13
|
+
} catch (err) {
|
|
14
|
+
spinner.fail('Type generation failed.')
|
|
15
|
+
const message = err instanceof Error ? err.message : String(err)
|
|
16
|
+
logger.error(message)
|
|
17
|
+
process.exitCode = 1
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function registerGenerateCommand(program: Command): void {
|
|
22
|
+
program
|
|
23
|
+
.command('generate')
|
|
24
|
+
.description('Run the TypeScript type generator from the cms-core codegen module')
|
|
25
|
+
.action(runGenerate)
|
|
26
|
+
}
|