@codapult/cli 0.15.3 → 0.16.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/README.md +107 -3
- package/dist/commands/config-show.js +6 -32
- package/dist/commands/db.d.ts +2 -0
- package/dist/commands/db.js +81 -2
- package/dist/commands/deploy.js +44 -17
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.js +9 -234
- package/dist/commands/env.js +21 -17
- package/dist/commands/mcp.d.ts +5 -0
- package/dist/commands/mcp.js +98 -0
- package/dist/commands/plugins.js +40 -5
- package/dist/commands/setup.js +2 -2
- package/dist/index.js +24 -5
- package/dist/mcp/resources.js +34 -3
- package/dist/mcp/server.js +4 -1
- package/dist/mcp/tools/db.js +185 -49
- package/dist/mcp/tools/db.test.js +59 -7
- package/dist/mcp/tools/env.d.ts +7 -0
- package/dist/mcp/tools/env.js +96 -2
- package/dist/mcp/tools/env.test.js +4 -2
- package/dist/mcp/tools/generate.js +64 -10
- package/dist/mcp/tools/plugins.js +125 -13
- package/dist/mcp/tools/project.js +59 -46
- package/dist/mcp/tools/project.test.js +20 -8
- package/dist/utils/check-report.d.ts +18 -0
- package/dist/utils/check-report.js +30 -0
- package/dist/utils/command.d.ts +18 -0
- package/dist/utils/command.js +29 -0
- package/dist/utils/config-report.d.ts +12 -0
- package/dist/utils/config-report.js +41 -0
- package/dist/utils/config-report.test.d.ts +1 -0
- package/dist/utils/config-report.test.js +20 -0
- package/dist/utils/db-diff.d.ts +11 -0
- package/dist/utils/db-diff.js +37 -0
- package/dist/utils/env-compatibility.d.ts +10 -0
- package/dist/utils/env-compatibility.js +52 -0
- package/dist/utils/env-compatibility.test.d.ts +1 -0
- package/dist/utils/env-compatibility.test.js +23 -0
- package/dist/utils/env-config.d.ts +9 -0
- package/dist/utils/env-config.js +116 -4
- package/dist/utils/env-schema-parser.d.ts +2 -0
- package/dist/utils/env-schema-parser.js +32 -0
- package/dist/utils/env-schema-parser.test.d.ts +1 -0
- package/dist/utils/env-schema-parser.test.js +11 -0
- package/dist/utils/health-render.d.ts +3 -0
- package/dist/utils/health-render.js +28 -0
- package/dist/utils/health-render.test.d.ts +1 -0
- package/dist/utils/health-render.test.js +18 -0
- package/dist/utils/health.d.ts +26 -0
- package/dist/utils/health.js +249 -0
- package/dist/utils/live-db-diff.d.ts +17 -0
- package/dist/utils/live-db-diff.js +131 -0
- package/dist/utils/live-db-diff.test.d.ts +1 -0
- package/dist/utils/live-db-diff.test.js +29 -0
- package/dist/utils/manifest.d.ts +1 -0
- package/dist/utils/patchers.d.ts +2 -0
- package/dist/utils/patchers.js +25 -13
- package/dist/utils/patchers.test.js +41 -7
- package/dist/utils/schema-parity.d.ts +15 -0
- package/dist/utils/schema-parity.js +91 -0
- package/dist/utils/schema-parity.test.d.ts +1 -0
- package/dist/utils/schema-parity.test.js +27 -0
- package/dist/utils/schema-parser.d.ts +12 -0
- package/dist/utils/schema-parser.js +130 -0
- package/dist/utils/schema-parser.test.d.ts +1 -0
- package/dist/utils/schema-parser.test.js +59 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ CLI tool for managing [Codapult](https://codapult.dev) SaaS projects.
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
+
This is the maintained CLI package used by Codapult projects. Buyers normally invoke the published package through `npx` or the generated MCP configuration; they do not clone or build this repository. The development and release sections below are for Codapult maintainers.
|
|
8
|
+
|
|
7
9
|
```shell
|
|
8
10
|
npm install -g @codapult/cli
|
|
9
11
|
```
|
|
@@ -14,18 +16,20 @@ Or run directly with npx:
|
|
|
14
16
|
npx @codapult/cli <command>
|
|
15
17
|
```
|
|
16
18
|
|
|
19
|
+
The command reference below uses the installed `codapult` binary. Project users who do not install the CLI globally should prefix commands with `npx @codapult/cli`, for example `npx @codapult/cli db schema-diff`.
|
|
20
|
+
|
|
17
21
|
## Commands
|
|
18
22
|
|
|
19
23
|
### Project
|
|
20
24
|
|
|
21
25
|
- `codapult setup` — interactive project setup wizard (or non-interactive with `--preset`)
|
|
22
26
|
- `codapult update [version]` — update from upstream Codapult releases
|
|
23
|
-
- `codapult doctor` — check project health and configuration
|
|
27
|
+
- `codapult doctor` — check project health and configuration (exit code 1 on failures for CI)
|
|
24
28
|
- `codapult config` — show current project configuration
|
|
25
29
|
|
|
26
30
|
### Plugins
|
|
27
31
|
|
|
28
|
-
- `codapult plugins add <name>` — install a plugin from a local directory
|
|
32
|
+
- `codapult plugins add <name>` — install a plugin from a local directory or remote Git URL
|
|
29
33
|
- `codapult plugins remove <name>` — uninstall a plugin
|
|
30
34
|
- `codapult plugins migrate [name]` — update plugin schema and generate DB migration (`--push` for dev mode)
|
|
31
35
|
- `codapult plugins list` — list installed plugins
|
|
@@ -44,6 +48,8 @@ npx @codapult/cli <command>
|
|
|
44
48
|
- `codapult db seed` — seed sample data
|
|
45
49
|
- `codapult db studio` — open Drizzle Studio
|
|
46
50
|
- `codapult db status` — show schema info and migration count
|
|
51
|
+
- `codapult db schema-diff` — compare SQLite and PostgreSQL schema files
|
|
52
|
+
- `codapult db live-diff` — read-only compare active schema with the live database
|
|
47
53
|
|
|
48
54
|
### Environment
|
|
49
55
|
|
|
@@ -58,11 +64,109 @@ npx @codapult/cli <command>
|
|
|
58
64
|
|
|
59
65
|
### AI Integration
|
|
60
66
|
|
|
67
|
+
- `codapult mcp update [version]` — pin or update the MCP version in `.cursor/mcp.json`
|
|
68
|
+
- `codapult mcp doctor` — run shared project health checks plus validate `.cursor/mcp.json`
|
|
69
|
+
- `codapult mcp contract-check` — fail CI when `env-schema.ts` drifts from the MCP compatibility contract
|
|
61
70
|
- `codapult mcp-server` — start MCP server for AI assistant integration (Cursor, Claude, Codex)
|
|
62
71
|
|
|
72
|
+
Global options available on every command include `--help` and `--version`. Commands that read project configuration accept `--no-env-file` where applicable. Use `--dry-run` on commands that document it to preview a change without applying it.
|
|
73
|
+
|
|
74
|
+
Mutation commands (`db push`, `db generate`, `plugins add/remove`, env sync, and code generation) can change project files or databases. Use their dry-run options where available, review the returned plan, and keep them behind an explicit developer/CI step. Diagnostic commands (`doctor`, `env check`, `deploy status`, `mcp contract-check`, `db schema-diff`, and `db live-diff`) are read-only and return non-zero exit codes on failures, except type-only schema parity warnings.
|
|
75
|
+
|
|
63
76
|
## MCP Server
|
|
64
77
|
|
|
65
|
-
The CLI includes an MCP (Model Context Protocol) server with
|
|
78
|
+
The CLI includes an MCP (Model Context Protocol) server with 29 tools, 8 resources, and 2 prompt templates for AI-assisted development. The following is the complete MCP surface exposed by the current CLI.
|
|
79
|
+
|
|
80
|
+
### MCP Tools
|
|
81
|
+
|
|
82
|
+
#### Project
|
|
83
|
+
|
|
84
|
+
| Tool | Description |
|
|
85
|
+
| -------------------------- | ------------------------------------------------------------------------------- |
|
|
86
|
+
| `codapult_project_status` | Report adapters, plugins, enabled features, and git status. |
|
|
87
|
+
| `codapult_project_config` | Read the application configuration from `src/config/app.ts`. |
|
|
88
|
+
| `codapult_project_context` | Return a compact project overview for AI-assisted work. |
|
|
89
|
+
| `codapult_run_checks` | Run lint, typecheck, and/or tests. |
|
|
90
|
+
| `codapult_build` | Run the production build. |
|
|
91
|
+
| `codapult_doctor` | Check project files, TypeScript, environment, schema parity, and configuration. |
|
|
92
|
+
|
|
93
|
+
#### Database
|
|
94
|
+
|
|
95
|
+
| Tool | Description |
|
|
96
|
+
| ---------------------------- | ------------------------------------------------------------------------ |
|
|
97
|
+
| `codapult_db_get_tables` | List database tables with column counts. |
|
|
98
|
+
| `codapult_db_get_table_info` | Inspect columns, types, and constraints for a table. |
|
|
99
|
+
| `codapult_db_status` | Report the database provider, table count, and migration status. |
|
|
100
|
+
| `codapult_db_schema_diff` | Compare the SQLite and PostgreSQL host schema files. |
|
|
101
|
+
| `codapult_db_migration_diff` | Preview pending SQL in a temporary migration directory. |
|
|
102
|
+
| `codapult_db_live_diff` | Read-only comparison of the active source schema with the live database. |
|
|
103
|
+
| `codapult_db_generate` | Generate a Drizzle migration. |
|
|
104
|
+
| `codapult_db_push` | Apply the source schema to the database. |
|
|
105
|
+
| `codapult_db_seed` | Run the project's database seed script. |
|
|
106
|
+
|
|
107
|
+
#### Environment
|
|
108
|
+
|
|
109
|
+
| Tool | Description |
|
|
110
|
+
| --------------------- | ------------------------------------------------------------------------------------ |
|
|
111
|
+
| `codapult_env_schema` | Read documented variables and descriptions from `.env.example`. |
|
|
112
|
+
| `codapult_env_read` | Read and validate local environment values with secrets masked by default. |
|
|
113
|
+
| `codapult_env_update` | Set one environment variable in the project env file. |
|
|
114
|
+
| `codapult_env_check` | Validate local variables against `.env.example` and effective provider requirements. |
|
|
115
|
+
| `codapult_env_sync` | Add missing variables from `.env.example` to the local env file. |
|
|
116
|
+
|
|
117
|
+
#### Plugins
|
|
118
|
+
|
|
119
|
+
| Tool | Description |
|
|
120
|
+
| -------------------------- | -------------------------------------------------------------- |
|
|
121
|
+
| `codapult_plugins_list` | List installed plugins. |
|
|
122
|
+
| `codapult_plugins_add` | Install a plugin and patch its config and schema declarations. |
|
|
123
|
+
| `codapult_plugins_remove` | Uninstall a plugin. |
|
|
124
|
+
| `codapult_plugins_migrate` | Update a plugin schema and prepare a database migration. |
|
|
125
|
+
|
|
126
|
+
#### Code Generation
|
|
127
|
+
|
|
128
|
+
| Tool | Description |
|
|
129
|
+
| -------------------------- | ------------------------------------------------------------------- |
|
|
130
|
+
| `codapult_generate_page` | Generate a dashboard page with the project conventions. |
|
|
131
|
+
| `codapult_generate_api` | Generate an API route with auth, rate limiting, and Zod validation. |
|
|
132
|
+
| `codapult_generate_action` | Generate a server action with auth and validation. |
|
|
133
|
+
| `codapult_generate_plugin` | Scaffold a complete plugin repository. |
|
|
134
|
+
|
|
135
|
+
#### Deployment
|
|
136
|
+
|
|
137
|
+
| Tool | Description |
|
|
138
|
+
| ------------------------ | --------------------------------------------------------------- |
|
|
139
|
+
| `codapult_deploy_status` | Check Docker, Helm, Terraform, and Pulumi deployment readiness. |
|
|
140
|
+
|
|
141
|
+
Mutating MCP tools support `dry_run` where applicable. The tool returns the planned operations without writing project files, changing environment files, running migrations, or applying database changes. `codapult_env_read` masks sensitive values by default; `show_secrets: true` is optional and returns a security warning.
|
|
142
|
+
|
|
143
|
+
### MCP Resources
|
|
144
|
+
|
|
145
|
+
Resources are read-only project files or computed context that MCP clients can load automatically.
|
|
146
|
+
|
|
147
|
+
| Resource | URI | Description |
|
|
148
|
+
| ----------------------- | ------------------------------ | --------------------------------------------------------------------------------- |
|
|
149
|
+
| `codapult_schema` | `codapult://schema` | Active Drizzle schema selected by the database provider. |
|
|
150
|
+
| `codapult_app_config` | `codapult://config/app` | Application identity, brand, and AI configuration. |
|
|
151
|
+
| `codapult_env_config` | `codapult://config/env` | Typed environment access, feature flags, providers, and checkout resolution. |
|
|
152
|
+
| `codapult_agents_md` | `codapult://agents` | Project structure, conventions, and AI-agent rules from `AGENTS.md`. |
|
|
153
|
+
| `codapult_env_example` | `codapult://env-example` | Environment variable template with descriptions and defaults. |
|
|
154
|
+
| `codapult_validation` | `codapult://validation` | Project Zod validation schemas. |
|
|
155
|
+
| `codapult_navigation` | `codapult://config/navigation` | Dashboard and admin navigation configuration. |
|
|
156
|
+
| `codapult_config_files` | `codapult://config/files` | All non-test TypeScript files in `src/config`, including marketing configuration. |
|
|
157
|
+
|
|
158
|
+
### MCP Prompt Templates
|
|
159
|
+
|
|
160
|
+
| Prompt | Description |
|
|
161
|
+
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
162
|
+
| `codapult_code_review` | Review code against Codapult API, adapter, TypeScript, React, security, and database conventions; includes current project context. |
|
|
163
|
+
| `codapult_schema_design` | Design matching SQLite and PostgreSQL Drizzle tables using the project's naming, key, timestamp, and relation conventions. |
|
|
164
|
+
|
|
165
|
+
`codapult doctor` and MCP use the same health/report core. The regular command is project-focused; `codapult mcp doctor` additionally verifies that the editor configuration points to the Codapult MCP server. Doctor also checks parity between `src/lib/db/schema.ts` and `src/lib/db/schema-pg.ts`; missing tables/columns fail the check and incompatible provider types are warnings. Environment schema drift is detected by parsing `src/config/env-schema.ts` with the TypeScript AST.
|
|
166
|
+
|
|
167
|
+
The environment, deployment-readiness, doctor, and MCP contract commands expose structured checks internally and render them for the terminal. MCP clients receive the same data as JSON. This keeps CI exit codes and interactive output aligned.
|
|
168
|
+
|
|
169
|
+
Database live-diff checks only the active schema of the project: `src/lib/db/schema.ts` for Turso/SQLite or `src/lib/db/schema-pg.ts` for PostgreSQL. `plugins add` and `plugins migrate` keep both schema files in sync with the plugin manifest when PostgreSQL tables are provided. A live table that is absent from the active host schema is reported as `missing_in_schema`; review it as a legacy table or install/integrate the plugin before changing the database. The checker does not scan sibling plugin repositories or plugin source files.
|
|
66
170
|
|
|
67
171
|
## Development
|
|
68
172
|
|
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
1
|
import { resolve } from 'node:path';
|
|
3
2
|
import { findProjectRoot, readJsonFile } from '../utils/project.js';
|
|
4
3
|
import { ENV_FILE_NAME, loadProjectEnv } from '../utils/project-env.js';
|
|
5
4
|
import { getAdapters, getAuthMethods, getFeatures, getOauthProviders, FEATURE_ENV, } from '../utils/env-config.js';
|
|
6
5
|
import { heading, success, fail, info, dim, label } from '../utils/ui.js';
|
|
7
|
-
|
|
8
|
-
function extractTsObjectField(content, field) {
|
|
9
|
-
const regex = new RegExp(`\\b${field}\\s*:\\s*['"\`]([^'"\`]+)['"\`]`);
|
|
10
|
-
const match = regex.exec(content);
|
|
11
|
-
return match?.[1] ?? undefined;
|
|
12
|
-
}
|
|
13
|
-
/** Extracts a numeric literal: `field: 123` or `field: 0.5`. */
|
|
14
|
-
function extractTsNumericField(content, field) {
|
|
15
|
-
const regex = new RegExp(`\\b${field}\\s*:\\s*([\\d.]+)`);
|
|
16
|
-
const match = regex.exec(content);
|
|
17
|
-
return match?.[1] ?? undefined;
|
|
18
|
-
}
|
|
19
|
-
/** Extracts a boolean literal: `field: true|false`. */
|
|
20
|
-
function extractTsBoolField(content, field) {
|
|
21
|
-
const regex = new RegExp(`\\b${field}\\s*:\\s*(true|false)`);
|
|
22
|
-
const match = regex.exec(content);
|
|
23
|
-
return match ? match[1] === 'true' : undefined;
|
|
24
|
-
}
|
|
6
|
+
import { collectAppConfigSummary } from '../utils/config-report.js';
|
|
25
7
|
export function configShowCommand(options = {}) {
|
|
26
8
|
const root = findProjectRoot();
|
|
27
9
|
if (!root) {
|
|
@@ -40,14 +22,10 @@ export function configShowCommand(options = {}) {
|
|
|
40
22
|
const env = loadProjectEnv(root, options);
|
|
41
23
|
const envContent = env.content;
|
|
42
24
|
// --- App config (src/config/app.ts) ---
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
const content = readFileSync(appConfigPath, 'utf-8');
|
|
25
|
+
const appConfig = collectAppConfigSummary(root);
|
|
26
|
+
if (appConfig) {
|
|
46
27
|
info('Brand');
|
|
47
|
-
const name
|
|
48
|
-
const description = extractTsObjectField(content, 'description');
|
|
49
|
-
const logo = extractTsObjectField(content, 'logo');
|
|
50
|
-
const favicon = extractTsObjectField(content, 'favicon');
|
|
28
|
+
const { name, description, logo, favicon } = appConfig.brand;
|
|
51
29
|
if (name)
|
|
52
30
|
label(' Name', name);
|
|
53
31
|
if (description)
|
|
@@ -58,18 +36,14 @@ export function configShowCommand(options = {}) {
|
|
|
58
36
|
label(' Favicon', favicon);
|
|
59
37
|
console.log();
|
|
60
38
|
info('Company');
|
|
61
|
-
const contactEmail =
|
|
62
|
-
const githubUrl = extractTsObjectField(content, 'githubUrl');
|
|
39
|
+
const { contactEmail, githubUrl } = appConfig.company;
|
|
63
40
|
if (contactEmail)
|
|
64
41
|
label(' Contact email', contactEmail);
|
|
65
42
|
if (githubUrl)
|
|
66
43
|
label(' GitHub', githubUrl);
|
|
67
44
|
console.log();
|
|
68
45
|
info('AI');
|
|
69
|
-
const defaultModel
|
|
70
|
-
const ragEnabled = extractTsBoolField(content, 'ragEnabled');
|
|
71
|
-
const ragMaxChunks = extractTsNumericField(content, 'ragMaxChunks');
|
|
72
|
-
const ragMinScore = extractTsNumericField(content, 'ragMinScore');
|
|
46
|
+
const { defaultModel, ragEnabled, ragMaxChunks, ragMinScore } = appConfig.ai;
|
|
73
47
|
if (defaultModel)
|
|
74
48
|
label(' Default model', defaultModel);
|
|
75
49
|
if (ragEnabled != null)
|
package/dist/commands/db.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export declare function dbGenerateCommand(options?: ProjectEnvOptions): void;
|
|
|
4
4
|
export declare function dbSeedCommand(_options?: ProjectEnvOptions): void;
|
|
5
5
|
export declare function dbStudioCommand(options?: ProjectEnvOptions): void;
|
|
6
6
|
export declare function dbStatusCommand(options?: ProjectEnvOptions): Promise<void>;
|
|
7
|
+
export declare function dbLiveDiffCommand(options?: ProjectEnvOptions): void;
|
|
8
|
+
export declare function dbSchemaDiffCommand(): void;
|
package/dist/commands/db.js
CHANGED
|
@@ -4,6 +4,10 @@ import { resolve } from 'node:path';
|
|
|
4
4
|
import { findProjectRoot } from '../utils/project.js';
|
|
5
5
|
import { loadProjectEnv } from '../utils/project-env.js';
|
|
6
6
|
import { heading, success, fail, info, dim, warn } from '../utils/ui.js';
|
|
7
|
+
import { parseDatabaseSchema } from '../utils/schema-parser.js';
|
|
8
|
+
import { compareSchemaFiles } from '../utils/schema-parity.js';
|
|
9
|
+
import { renderStructuredReport, summarizeChecks } from '../utils/check-report.js';
|
|
10
|
+
import { diffSchemaWithLiveDatabase, inspectLiveDatabase } from '../utils/live-db-diff.js';
|
|
7
11
|
function run(cmd, cwd) {
|
|
8
12
|
info(`Running: ${cmd}`);
|
|
9
13
|
try {
|
|
@@ -18,8 +22,8 @@ function run(cmd, cwd) {
|
|
|
18
22
|
function getDbProvider(root, options) {
|
|
19
23
|
const { content } = loadProjectEnv(root, options);
|
|
20
24
|
const match = /^DB_PROVIDER\s*=\s*"?(\w+)"?/m.exec(content);
|
|
21
|
-
if (match)
|
|
22
|
-
return
|
|
25
|
+
if (match?.[1] === 'postgres')
|
|
26
|
+
return 'postgres';
|
|
23
27
|
return 'turso';
|
|
24
28
|
}
|
|
25
29
|
export function dbPushCommand(options = {}) {
|
|
@@ -110,3 +114,78 @@ export async function dbStatusCommand(options = {}) {
|
|
|
110
114
|
}
|
|
111
115
|
console.log();
|
|
112
116
|
}
|
|
117
|
+
export function dbLiveDiffCommand(options = {}) {
|
|
118
|
+
const root = findProjectRoot();
|
|
119
|
+
if (!root) {
|
|
120
|
+
fail('Not inside a Codapult project.');
|
|
121
|
+
process.exitCode = 1;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const env = loadProjectEnv(root, options);
|
|
125
|
+
const provider = getDbProvider(root, options);
|
|
126
|
+
const schemaPath = provider === 'postgres' ? 'src/lib/db/schema-pg.ts' : 'src/lib/db/schema.ts';
|
|
127
|
+
heading('Live Database Diff');
|
|
128
|
+
info('Read-only: querying database metadata; no DDL or migrations will run.');
|
|
129
|
+
const absoluteSchemaPath = resolve(root, schemaPath);
|
|
130
|
+
if (!existsSync(absoluteSchemaPath)) {
|
|
131
|
+
fail(`Active schema file is missing: ${schemaPath}`);
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const schema = parseDatabaseSchema(readFileSync(absoluteSchemaPath, 'utf-8'));
|
|
136
|
+
try {
|
|
137
|
+
const differences = diffSchemaWithLiveDatabase(schema, inspectLiveDatabase(root, env.content));
|
|
138
|
+
if (differences.length === 0)
|
|
139
|
+
success('Live database matches the active schema.');
|
|
140
|
+
else {
|
|
141
|
+
warn(`${differences.length} schema difference(s) found:`);
|
|
142
|
+
for (const difference of differences)
|
|
143
|
+
dim(` ${difference.table}: ${difference.issue} ${JSON.stringify(difference.details ?? '')}`);
|
|
144
|
+
process.exitCode = 1;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
fail(error instanceof Error ? error.message : 'Live database inspection failed.');
|
|
149
|
+
process.exitCode = 1;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export function dbSchemaDiffCommand() {
|
|
153
|
+
const root = findProjectRoot();
|
|
154
|
+
if (!root) {
|
|
155
|
+
fail('Not inside a Codapult project.');
|
|
156
|
+
process.exitCode = 1;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const sqlitePath = 'src/lib/db/schema.ts';
|
|
160
|
+
const postgresPath = 'src/lib/db/schema-pg.ts';
|
|
161
|
+
const sqliteAbsolutePath = resolve(root, sqlitePath);
|
|
162
|
+
const postgresAbsolutePath = resolve(root, postgresPath);
|
|
163
|
+
if (!existsSync(sqliteAbsolutePath) || !existsSync(postgresAbsolutePath)) {
|
|
164
|
+
const missing = [
|
|
165
|
+
!existsSync(sqliteAbsolutePath) ? sqlitePath : undefined,
|
|
166
|
+
!existsSync(postgresAbsolutePath) ? postgresPath : undefined,
|
|
167
|
+
].filter((path) => path !== undefined);
|
|
168
|
+
const report = summarizeChecks([
|
|
169
|
+
{
|
|
170
|
+
id: 'schema-files',
|
|
171
|
+
status: 'fail',
|
|
172
|
+
message: `Schema file(s) missing: ${missing.join(', ')}`,
|
|
173
|
+
path: root,
|
|
174
|
+
},
|
|
175
|
+
]);
|
|
176
|
+
renderStructuredReport('Schema Parity', report);
|
|
177
|
+
process.exitCode = 1;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const report = compareSchemaFiles(parseDatabaseSchema(readFileSync(sqliteAbsolutePath, 'utf-8')), parseDatabaseSchema(readFileSync(postgresAbsolutePath, 'utf-8')));
|
|
181
|
+
const checks = report.differences.map((difference, index) => ({
|
|
182
|
+
id: `schema-parity-${index + 1}`,
|
|
183
|
+
status: difference.severity,
|
|
184
|
+
message: `${difference.table}: ${difference.issue}${difference.details !== undefined ? ` ${JSON.stringify(difference.details)}` : ''}`,
|
|
185
|
+
path: `${sqlitePath} ↔ ${postgresPath}`,
|
|
186
|
+
}));
|
|
187
|
+
renderStructuredReport('Schema Parity', summarizeChecks(checks.length > 0
|
|
188
|
+
? checks
|
|
189
|
+
: [{ id: 'schema-parity', status: 'ok', message: 'SQLite and PostgreSQL schemas match.' }]));
|
|
190
|
+
process.exitCode = report.status === 'fail' ? 1 : 0;
|
|
191
|
+
}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -4,6 +4,7 @@ import { resolve } from 'node:path';
|
|
|
4
4
|
import { findProjectRoot } from '../utils/project.js';
|
|
5
5
|
import { ENV_FILE_NAME, getProjectEnvSource, loadProjectEnv, } from '../utils/project-env.js';
|
|
6
6
|
import { heading, success, fail, info, dim, warn, confirm } from '../utils/ui.js';
|
|
7
|
+
import { renderStructuredReport, summarizeChecks, } from '../utils/check-report.js';
|
|
7
8
|
function hasCommand(cmd) {
|
|
8
9
|
return spawnSync(cmd, ['--version'], { stdio: 'ignore' }).status === 0;
|
|
9
10
|
}
|
|
@@ -160,7 +161,6 @@ export function deployStatusCommand(options = {}) {
|
|
|
160
161
|
fail('Not inside a Codapult project.');
|
|
161
162
|
process.exit(1);
|
|
162
163
|
}
|
|
163
|
-
heading('Deploy Readiness');
|
|
164
164
|
const checks = [
|
|
165
165
|
{ name: 'Dockerfile', path: 'Dockerfile' },
|
|
166
166
|
{ name: 'docker-compose.yml', path: 'docker-compose.yml' },
|
|
@@ -169,43 +169,70 @@ export function deployStatusCommand(options = {}) {
|
|
|
169
169
|
{ name: 'Pulumi (AWS)', path: 'infra/pulumi/index.ts' },
|
|
170
170
|
{ name: 'Helm chart', path: 'infra/helm/codapult/Chart.yaml' },
|
|
171
171
|
];
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
}
|
|
172
|
+
const reportChecks = checks.map(({ name, path }) => ({
|
|
173
|
+
id: path,
|
|
174
|
+
status: existsSync(resolve(root, path)) ? 'ok' : 'warn',
|
|
175
|
+
message: existsSync(resolve(root, path)) ? `${name} exists` : `${name} not found`,
|
|
176
|
+
path,
|
|
177
|
+
}));
|
|
180
178
|
if (getProjectEnvSource(options) === 'process') {
|
|
181
|
-
|
|
179
|
+
reportChecks.push({
|
|
180
|
+
id: 'env-source',
|
|
181
|
+
status: 'ok',
|
|
182
|
+
message: 'Environment source: process.env',
|
|
183
|
+
});
|
|
182
184
|
}
|
|
183
185
|
else if (existsSync(resolve(root, ENV_FILE_NAME))) {
|
|
184
|
-
|
|
186
|
+
reportChecks.push({
|
|
187
|
+
id: 'env-file',
|
|
188
|
+
status: 'ok',
|
|
189
|
+
message: `${ENV_FILE_NAME} exists`,
|
|
190
|
+
path: ENV_FILE_NAME,
|
|
191
|
+
});
|
|
185
192
|
}
|
|
186
193
|
else {
|
|
187
|
-
|
|
194
|
+
reportChecks.push({
|
|
195
|
+
id: 'env-file',
|
|
196
|
+
status: 'warn',
|
|
197
|
+
message: `${ENV_FILE_NAME} not found`,
|
|
198
|
+
path: ENV_FILE_NAME,
|
|
199
|
+
});
|
|
188
200
|
}
|
|
189
201
|
// Check if standalone output is enabled
|
|
190
202
|
const nextConfig = resolve(root, 'next.config.ts');
|
|
191
203
|
if (existsSync(nextConfig)) {
|
|
192
204
|
const content = readFileSync(nextConfig, 'utf-8');
|
|
193
205
|
if (content.includes("output: 'standalone'")) {
|
|
194
|
-
|
|
206
|
+
reportChecks.push({
|
|
207
|
+
id: 'next-standalone',
|
|
208
|
+
status: 'ok',
|
|
209
|
+
message: 'Next.js standalone output enabled',
|
|
210
|
+
});
|
|
195
211
|
}
|
|
196
212
|
else {
|
|
197
|
-
|
|
213
|
+
reportChecks.push({
|
|
214
|
+
id: 'next-standalone',
|
|
215
|
+
status: 'warn',
|
|
216
|
+
message: 'Next.js standalone output not enabled (required for Docker)',
|
|
217
|
+
});
|
|
198
218
|
}
|
|
199
219
|
}
|
|
200
220
|
// Check engines
|
|
201
221
|
const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf-8'));
|
|
202
222
|
const engines = pkg.engines;
|
|
203
223
|
if (engines?.node) {
|
|
204
|
-
|
|
224
|
+
reportChecks.push({ id: 'node-engine', status: 'ok', message: `Node engine: ${engines.node}` });
|
|
205
225
|
}
|
|
206
226
|
else {
|
|
207
|
-
|
|
208
|
-
|
|
227
|
+
reportChecks.push({
|
|
228
|
+
id: 'node-engine',
|
|
229
|
+
status: 'warn',
|
|
230
|
+
message: 'No Node engine constraint in package.json',
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
const report = summarizeChecks(reportChecks);
|
|
234
|
+
renderStructuredReport('Deploy Readiness', report);
|
|
235
|
+
process.exitCode = report.summary.failures > 0 ? 1 : 0;
|
|
209
236
|
console.log();
|
|
210
237
|
dim('Deploy targets:');
|
|
211
238
|
dim(' codapult deploy vercel — Vercel (recommended)');
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ProjectEnvOptions } from '../utils/project-env.js';
|
|
2
2
|
export declare function doctorCommand(options?: ProjectEnvOptions): void;
|