@codapult/cli 0.17.1 → 0.18.1
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 +60 -4
- package/dist/commands/config-show.js +6 -9
- package/dist/commands/db.js +10 -36
- package/dist/commands/deploy.js +8 -19
- package/dist/commands/doctor.js +2 -7
- package/dist/commands/env.js +3 -11
- package/dist/commands/generate.js +5 -21
- package/dist/commands/generate.test.js +13 -11
- package/dist/commands/guard.d.ts +5 -0
- package/dist/commands/guard.js +5 -0
- package/dist/commands/mcp.js +5 -16
- package/dist/commands/plugins.js +5 -21
- package/dist/commands/setup.js +2 -6
- package/dist/commands/update.js +2 -6
- package/dist/index.js +115 -6
- package/dist/mcp/resources.js +15 -15
- package/dist/mcp/server.js +6 -0
- package/dist/mcp/tools/db.js +11 -16
- package/dist/mcp/tools/db.test.js +3 -3
- package/dist/mcp/tools/deploy.js +2 -8
- package/dist/mcp/tools/env.js +6 -12
- package/dist/mcp/tools/env.test.js +4 -4
- package/dist/mcp/tools/generate.js +10 -15
- package/dist/mcp/tools/plugins.js +5 -11
- package/dist/mcp/tools/project.js +9 -30
- package/dist/mcp/tools/project.test.js +4 -4
- package/dist/utils/command.d.ts +3 -0
- package/dist/utils/command.js +35 -4
- package/dist/utils/config.d.ts +5 -0
- package/dist/utils/config.js +5 -0
- package/dist/utils/project-checks.d.ts +2 -0
- package/dist/utils/project-checks.js +2 -0
- package/dist/utils/project.d.ts +1 -0
- package/dist/utils/project.js +16 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# @codapult/cli
|
|
2
2
|
|
|
3
|
-
CLI tool for managing [Codapult](https://codapult.dev) SaaS projects
|
|
3
|
+
CLI tool for managing [Codapult](https://codapult.dev) SaaS projects, with the universal
|
|
4
|
+
`@codapult/guard` architecture guard built in for AI-assisted development.
|
|
4
5
|
|
|
5
6
|
## Installation
|
|
6
7
|
|
|
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
|
+
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 CLI also powers Codapult MCP, exposing project-aware tools, resources, and prompt templates to compatible AI coding clients. The development and release sections below are for Codapult maintainers.
|
|
8
9
|
|
|
9
10
|
```shell
|
|
10
11
|
npm install -g @codapult/cli
|
|
@@ -16,7 +17,15 @@ Or run directly with npx:
|
|
|
16
17
|
npx @codapult/cli <command>
|
|
17
18
|
```
|
|
18
19
|
|
|
19
|
-
The command reference below uses the installed `codapult` binary.
|
|
20
|
+
The command reference below uses the installed `codapult` binary. For reproducible project and CI
|
|
21
|
+
usage, install and pin it as a dev dependency:
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
pnpm add -D @codapult/cli
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Project users who do not install the CLI globally should prefix commands with `npx @codapult/cli`,
|
|
28
|
+
for example `npx @codapult/cli db schema-diff`.
|
|
20
29
|
|
|
21
30
|
## Commands
|
|
22
31
|
|
|
@@ -62,6 +71,37 @@ The command reference below uses the installed `codapult` binary. Project users
|
|
|
62
71
|
- `codapult deploy docker` — build Docker image
|
|
63
72
|
- `codapult deploy status` — check deploy readiness
|
|
64
73
|
|
|
74
|
+
### Architecture Guard
|
|
75
|
+
|
|
76
|
+
Codapult CLI includes the standalone [`@codapult/guard`](https://github.com/codapult/codapult-guard)
|
|
77
|
+
engine and keeps the `codapult guard ...` command surface as a Codapult-friendly entrypoint.
|
|
78
|
+
Guard is responsible for project architecture memory, approved contracts, baselines, changed-file
|
|
79
|
+
regressions, impact context, and AI-agent review packets. It does not replace ESLint, TypeScript,
|
|
80
|
+
tests, SAST, or a general PR-review service.
|
|
81
|
+
|
|
82
|
+
- `codapult guard init` — discover the project and create `.codapult/guard/` state and baseline
|
|
83
|
+
- `codapult guard analyze` — refresh project facts without changing the baseline
|
|
84
|
+
- `codapult guard propose` — generate evidence-based rules and contract proposals
|
|
85
|
+
- `codapult guard check --changed` — check new architecture violations
|
|
86
|
+
- `codapult guard audit` — inspect the complete current state, including baseline findings
|
|
87
|
+
- `codapult guard review` — prepare a bounded diff and project-context packet for an AI reviewer
|
|
88
|
+
- `codapult guard verify` — run Guard verification and configured project checks
|
|
89
|
+
- `codapult guard doctor` — diagnose missing or invalid Guard artifacts
|
|
90
|
+
- `codapult guard rules ...` — approve proposed rules
|
|
91
|
+
- `codapult guard contracts ...` — approve or reject proposed contracts
|
|
92
|
+
- `codapult guard baseline ...` — inspect or intentionally update accepted findings
|
|
93
|
+
|
|
94
|
+
For any JavaScript or TypeScript project, install the standalone package directly:
|
|
95
|
+
|
|
96
|
+
```shell
|
|
97
|
+
pnpm add -D @codapult/guard
|
|
98
|
+
pnpm exec codapult-guard init
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The Codapult CLI adapter and the standalone Guard package share the same implementation; Guard
|
|
102
|
+
logic is not duplicated in this repository. See the [Guard documentation](https://github.com/codapult/codapult-guard/tree/main/docs)
|
|
103
|
+
for the full lifecycle, contracts, AI-agent workflow, MCP tools, and CI example.
|
|
104
|
+
|
|
65
105
|
### AI Integration
|
|
66
106
|
|
|
67
107
|
- `codapult mcp update [version]` — pin or update the MCP version in `.cursor/mcp.json`
|
|
@@ -75,7 +115,7 @@ Mutation commands (`db push`, `db generate`, `plugins add/remove`, env sync, and
|
|
|
75
115
|
|
|
76
116
|
## MCP Server
|
|
77
117
|
|
|
78
|
-
The CLI includes an MCP (Model Context Protocol) server with
|
|
118
|
+
The CLI includes an MCP (Model Context Protocol) server with 39 tools, 12 resources, and 4 prompt templates for AI-assisted development. The following is the complete MCP surface exposed by the current CLI.
|
|
79
119
|
|
|
80
120
|
### MCP Tools
|
|
81
121
|
|
|
@@ -138,6 +178,21 @@ The CLI includes an MCP (Model Context Protocol) server with 29 tools, 8 resourc
|
|
|
138
178
|
| ------------------------ | --------------------------------------------------------------- |
|
|
139
179
|
| `codapult_deploy_status` | Check Docker, Helm, Terraform, and Pulumi deployment readiness. |
|
|
140
180
|
|
|
181
|
+
#### Architecture Guard
|
|
182
|
+
|
|
183
|
+
| Tool | Description |
|
|
184
|
+
| -------------------------------- | ---------------------------------------------------------------------- |
|
|
185
|
+
| `codapult_guard_init` | Discover the project and create Guard state and an initial baseline. |
|
|
186
|
+
| `codapult_guard_context` | Return project architecture context for an AI agent. |
|
|
187
|
+
| `codapult_guard_propose` | Generate evidence-based rule and contract proposals. |
|
|
188
|
+
| `codapult_guard_proposal_decide` | Approve or reject proposed Guard policy. |
|
|
189
|
+
| `codapult_guard_check` | Check active Guard policy against the project or changed files. |
|
|
190
|
+
| `codapult_guard_audit` | Run a complete Guard scan, including baseline-suppressed findings. |
|
|
191
|
+
| `codapult_guard_review` | Prepare a bounded semantic-review packet from the current diff. |
|
|
192
|
+
| `codapult_guard_verify` | Run Guard, project checks, adapters, and contract verification. |
|
|
193
|
+
| `codapult_guard_impact` | Analyze affected modules and architecture impact paths. |
|
|
194
|
+
| `codapult_guard_explain` | Explain Guard findings and project-specific architectural constraints. |
|
|
195
|
+
|
|
141
196
|
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
197
|
|
|
143
198
|
### MCP Resources
|
|
@@ -212,6 +267,7 @@ pnpm run release -- --dry-run
|
|
|
212
267
|
### Prerequisites
|
|
213
268
|
|
|
214
269
|
- npm [trusted publishing](https://docs.npmjs.com/trusted-publishers) must be configured for the `@codapult/cli` package on npmjs.com.
|
|
270
|
+
- Before publishing a CLI release, the standalone `codapult-guard` package must be available on npm and the CLI dependency must use its published version rather than the pre-release workspace `file:` dependency.
|
|
215
271
|
- Commit messages should follow [Conventional Commits](https://www.conventionalcommits.org/) for meaningful changelogs (e.g. `feat:`, `fix:`, `chore:`).
|
|
216
272
|
|
|
217
273
|
## License
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { checkProjectRoot, readJsonFile } from '../utils/project.js';
|
|
3
3
|
import { ENV_FILE_NAME, loadProjectEnv } from '../utils/project-env.js';
|
|
4
4
|
import { getAdapters, getAuthMethods, getFeatures, getOauthProviders, FEATURE_ENV, } from '../utils/env-config.js';
|
|
5
|
-
import { heading, success,
|
|
5
|
+
import { heading, success, info, dim, label } from '../utils/ui.js';
|
|
6
6
|
import { collectAppConfigSummary } from '../utils/config-report.js';
|
|
7
|
+
import { config } from '../utils/config.js';
|
|
7
8
|
export function configShowCommand(options = {}) {
|
|
8
|
-
const root =
|
|
9
|
-
|
|
10
|
-
fail('Not inside a Codapult project.');
|
|
11
|
-
process.exit(1);
|
|
12
|
-
}
|
|
13
|
-
heading('Codapult Configuration');
|
|
9
|
+
const root = checkProjectRoot('exit');
|
|
10
|
+
heading(`${config.projectName} Configuration`);
|
|
14
11
|
label('Project root', root);
|
|
15
12
|
// --- Package info ---
|
|
16
13
|
const pkg = readJsonFile(resolve(root, 'package.json'));
|
|
@@ -44,7 +41,7 @@ export function configShowCommand(options = {}) {
|
|
|
44
41
|
console.log();
|
|
45
42
|
}
|
|
46
43
|
else {
|
|
47
|
-
dim(
|
|
44
|
+
dim(`src/config/app.ts not found — run \`${config.commandName} setup\``);
|
|
48
45
|
}
|
|
49
46
|
console.log();
|
|
50
47
|
if (env.source === 'file' && !env.fileExists) {
|
package/dist/commands/db.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process';
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { checkProjectRoot } 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
7
|
import { parseDatabaseSchema } from '../utils/schema-parser.js';
|
|
@@ -27,22 +27,14 @@ function getDbProvider(root, options) {
|
|
|
27
27
|
return 'turso';
|
|
28
28
|
}
|
|
29
29
|
export function dbPushCommand(options = {}) {
|
|
30
|
-
const root =
|
|
31
|
-
if (!root) {
|
|
32
|
-
fail('Not inside a Codapult project.');
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
30
|
+
const root = checkProjectRoot('exit');
|
|
35
31
|
heading('Database Push');
|
|
36
32
|
const provider = getDbProvider(root, options);
|
|
37
33
|
info(`Provider: ${provider}`);
|
|
38
34
|
run('pnpm db:push', root);
|
|
39
35
|
}
|
|
40
36
|
export function dbGenerateCommand(options = {}) {
|
|
41
|
-
const root =
|
|
42
|
-
if (!root) {
|
|
43
|
-
fail('Not inside a Codapult project.');
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
37
|
+
const root = checkProjectRoot('exit');
|
|
46
38
|
heading('Generate Migration');
|
|
47
39
|
const provider = getDbProvider(root, options);
|
|
48
40
|
info(`Provider: ${provider}`);
|
|
@@ -54,20 +46,12 @@ export function dbGenerateCommand(options = {}) {
|
|
|
54
46
|
}
|
|
55
47
|
}
|
|
56
48
|
export function dbSeedCommand(_options = {}) {
|
|
57
|
-
const root =
|
|
58
|
-
if (!root) {
|
|
59
|
-
fail('Not inside a Codapult project.');
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
49
|
+
const root = checkProjectRoot('exit');
|
|
62
50
|
heading('Seed Database');
|
|
63
51
|
run('pnpm db:seed', root);
|
|
64
52
|
}
|
|
65
53
|
export function dbStudioCommand(options = {}) {
|
|
66
|
-
const root =
|
|
67
|
-
if (!root) {
|
|
68
|
-
fail('Not inside a Codapult project.');
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
54
|
+
const root = checkProjectRoot('exit');
|
|
71
55
|
heading('Drizzle Studio');
|
|
72
56
|
const provider = getDbProvider(root, options);
|
|
73
57
|
info(`Provider: ${provider}`);
|
|
@@ -80,11 +64,7 @@ export function dbStudioCommand(options = {}) {
|
|
|
80
64
|
}
|
|
81
65
|
}
|
|
82
66
|
export async function dbStatusCommand(options = {}) {
|
|
83
|
-
const root =
|
|
84
|
-
if (!root) {
|
|
85
|
-
fail('Not inside a Codapult project.');
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
67
|
+
const root = checkProjectRoot('exit');
|
|
88
68
|
heading('Database Status');
|
|
89
69
|
const provider = getDbProvider(root, options);
|
|
90
70
|
info(`Provider: ${provider}`);
|
|
@@ -115,12 +95,9 @@ export async function dbStatusCommand(options = {}) {
|
|
|
115
95
|
console.log();
|
|
116
96
|
}
|
|
117
97
|
export function dbLiveDiffCommand(options = {}) {
|
|
118
|
-
const root =
|
|
119
|
-
if (!root)
|
|
120
|
-
fail('Not inside a Codapult project.');
|
|
121
|
-
process.exitCode = 1;
|
|
98
|
+
const root = checkProjectRoot('code');
|
|
99
|
+
if (!root)
|
|
122
100
|
return;
|
|
123
|
-
}
|
|
124
101
|
const env = loadProjectEnv(root, options);
|
|
125
102
|
const provider = getDbProvider(root, options);
|
|
126
103
|
const schemaPath = provider === 'postgres' ? 'src/lib/db/schema-pg.ts' : 'src/lib/db/schema.ts';
|
|
@@ -150,12 +127,9 @@ export function dbLiveDiffCommand(options = {}) {
|
|
|
150
127
|
}
|
|
151
128
|
}
|
|
152
129
|
export function dbSchemaDiffCommand() {
|
|
153
|
-
const root =
|
|
154
|
-
if (!root)
|
|
155
|
-
fail('Not inside a Codapult project.');
|
|
156
|
-
process.exitCode = 1;
|
|
130
|
+
const root = checkProjectRoot('code');
|
|
131
|
+
if (!root)
|
|
157
132
|
return;
|
|
158
|
-
}
|
|
159
133
|
const sqlitePath = 'src/lib/db/schema.ts';
|
|
160
134
|
const postgresPath = 'src/lib/db/schema-pg.ts';
|
|
161
135
|
const sqliteAbsolutePath = resolve(root, sqlitePath);
|
package/dist/commands/deploy.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { execSync, spawnSync } from 'node:child_process';
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { checkProjectRoot } 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
7
|
import { renderStructuredReport, summarizeChecks, } from '../utils/check-report.js';
|
|
8
|
+
import { config } from '../utils/config.js';
|
|
8
9
|
function hasCommand(cmd) {
|
|
9
10
|
return spawnSync(cmd, ['--version'], { stdio: 'ignore' }).status === 0;
|
|
10
11
|
}
|
|
@@ -12,11 +13,7 @@ function hasCommand(cmd) {
|
|
|
12
13
|
// codapult deploy vercel
|
|
13
14
|
// ---------------------------------------------------------------------------
|
|
14
15
|
export async function deployVercelCommand(options = {}) {
|
|
15
|
-
const root =
|
|
16
|
-
if (!root) {
|
|
17
|
-
fail('Not inside a Codapult project.');
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
16
|
+
const root = checkProjectRoot('exit');
|
|
20
17
|
heading('Deploy to Vercel');
|
|
21
18
|
// 1. Check Vercel CLI
|
|
22
19
|
if (!hasCommand('vercel')) {
|
|
@@ -81,11 +78,7 @@ export async function deployVercelCommand(options = {}) {
|
|
|
81
78
|
// codapult deploy docker
|
|
82
79
|
// ---------------------------------------------------------------------------
|
|
83
80
|
export async function deployDockerCommand(opts = {}) {
|
|
84
|
-
const root =
|
|
85
|
-
if (!root) {
|
|
86
|
-
fail('Not inside a Codapult project.');
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
81
|
+
const root = checkProjectRoot('exit');
|
|
89
82
|
heading('Deploy with Docker');
|
|
90
83
|
// 1. Check Docker
|
|
91
84
|
if (!hasCommand('docker')) {
|
|
@@ -108,7 +101,7 @@ export async function deployDockerCommand(opts = {}) {
|
|
|
108
101
|
}
|
|
109
102
|
// 4. Read package.json for name
|
|
110
103
|
const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf-8'));
|
|
111
|
-
const appName = pkg.name ||
|
|
104
|
+
const appName = pkg.name || config.appName;
|
|
112
105
|
const tag = opts.tag || 'latest';
|
|
113
106
|
const imageName = `${appName}:${tag}`;
|
|
114
107
|
info(`Image: ${imageName}`);
|
|
@@ -156,11 +149,7 @@ export async function deployDockerCommand(opts = {}) {
|
|
|
156
149
|
// codapult deploy status
|
|
157
150
|
// ---------------------------------------------------------------------------
|
|
158
151
|
export function deployStatusCommand(options = {}) {
|
|
159
|
-
const root =
|
|
160
|
-
if (!root) {
|
|
161
|
-
fail('Not inside a Codapult project.');
|
|
162
|
-
process.exit(1);
|
|
163
|
-
}
|
|
152
|
+
const root = checkProjectRoot('exit');
|
|
164
153
|
const checks = [
|
|
165
154
|
{ name: 'Dockerfile', path: 'Dockerfile' },
|
|
166
155
|
{ name: 'docker-compose.yml', path: 'docker-compose.yml' },
|
|
@@ -235,7 +224,7 @@ export function deployStatusCommand(options = {}) {
|
|
|
235
224
|
process.exitCode = report.summary.failures > 0 ? 1 : 0;
|
|
236
225
|
console.log();
|
|
237
226
|
dim('Deploy targets:');
|
|
238
|
-
dim(
|
|
239
|
-
dim(
|
|
227
|
+
dim(` ${config.commandName} deploy vercel — Vercel (recommended)`);
|
|
228
|
+
dim(` ${config.commandName} deploy docker — Docker build + run`);
|
|
240
229
|
console.log();
|
|
241
230
|
}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { checkProjectRoot } from '../utils/project.js';
|
|
2
2
|
import { collectProjectHealth } from '../utils/health.js';
|
|
3
|
-
import { fail } from '../utils/ui.js';
|
|
4
3
|
import { healthExitCode, renderHealthReport } from '../utils/health-render.js';
|
|
5
4
|
export function doctorCommand(options = {}) {
|
|
6
|
-
const root =
|
|
7
|
-
if (!root) {
|
|
8
|
-
fail('Not inside a Codapult project.');
|
|
9
|
-
process.exit(1);
|
|
10
|
-
}
|
|
5
|
+
const root = checkProjectRoot('exit');
|
|
11
6
|
const report = collectProjectHealth(root, {
|
|
12
7
|
envSource: options.envFile === false ? 'process' : 'file',
|
|
13
8
|
});
|
package/dist/commands/env.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { checkProjectRoot } from '../utils/project.js';
|
|
4
4
|
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, getProjectEnvSource, loadProjectEnv, } from '../utils/project-env.js';
|
|
5
5
|
import { heading, success, fail, info, dim, warn, confirm } from '../utils/ui.js';
|
|
6
6
|
import { renderStructuredReport, summarizeChecks } from '../utils/check-report.js';
|
|
@@ -33,11 +33,7 @@ function parseEnvFile(content) {
|
|
|
33
33
|
// codapult env check
|
|
34
34
|
// ---------------------------------------------------------------------------
|
|
35
35
|
export function envCheckCommand(options = {}) {
|
|
36
|
-
const root =
|
|
37
|
-
if (!root) {
|
|
38
|
-
fail('Not inside a Codapult project.');
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
36
|
+
const root = checkProjectRoot('exit');
|
|
41
37
|
const examplePath = resolve(root, ENV_EXAMPLE_FILE_NAME);
|
|
42
38
|
const localPath = resolve(root, ENV_FILE_NAME);
|
|
43
39
|
if (!existsSync(examplePath)) {
|
|
@@ -101,11 +97,7 @@ export function envCheckCommand(options = {}) {
|
|
|
101
97
|
// codapult env sync
|
|
102
98
|
// ---------------------------------------------------------------------------
|
|
103
99
|
export async function envSyncCommand(options = {}) {
|
|
104
|
-
const root =
|
|
105
|
-
if (!root) {
|
|
106
|
-
fail('Not inside a Codapult project.');
|
|
107
|
-
process.exit(1);
|
|
108
|
-
}
|
|
100
|
+
const root = checkProjectRoot('exit');
|
|
109
101
|
heading(`Sync ${ENV_FILE_NAME} with ${ENV_EXAMPLE_FILE_NAME}`);
|
|
110
102
|
if (getProjectEnvSource(options) === 'process') {
|
|
111
103
|
warn(`\`codapult env sync --no-env-file\` cannot update process.env`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { resolve, dirname } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { checkProjectRoot } from '../utils/project.js';
|
|
4
4
|
import { heading, success, fail, info, dim } from '../utils/ui.js';
|
|
5
5
|
import { validateGeneratedName } from '../utils/validation.js';
|
|
6
6
|
function toKebab(name) {
|
|
@@ -31,11 +31,7 @@ function writeIfNotExists(filePath, content) {
|
|
|
31
31
|
// ---------------------------------------------------------------------------
|
|
32
32
|
export function generatePageCommand(name) {
|
|
33
33
|
validateGeneratedName(name);
|
|
34
|
-
const root =
|
|
35
|
-
if (!root) {
|
|
36
|
-
fail('Not inside a Codapult project.');
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
34
|
+
const root = checkProjectRoot('exit');
|
|
39
35
|
const kebab = toKebab(name);
|
|
40
36
|
const pascal = toPascal(name);
|
|
41
37
|
const title = pascal.replace(/([A-Z])/g, ' $1').trim();
|
|
@@ -87,11 +83,7 @@ export default async function ${pascal}Page() {
|
|
|
87
83
|
// ---------------------------------------------------------------------------
|
|
88
84
|
export function generateApiCommand(name) {
|
|
89
85
|
validateGeneratedName(name);
|
|
90
|
-
const root =
|
|
91
|
-
if (!root) {
|
|
92
|
-
fail('Not inside a Codapult project.');
|
|
93
|
-
process.exit(1);
|
|
94
|
-
}
|
|
86
|
+
const root = checkProjectRoot('exit');
|
|
95
87
|
const kebab = toKebab(name);
|
|
96
88
|
const camel = toCamel(name);
|
|
97
89
|
const schemaName = `${camel}Schema`;
|
|
@@ -167,11 +159,7 @@ export async function POST(req: Request) {
|
|
|
167
159
|
// ---------------------------------------------------------------------------
|
|
168
160
|
export function generateActionCommand(name) {
|
|
169
161
|
validateGeneratedName(name);
|
|
170
|
-
const root =
|
|
171
|
-
if (!root) {
|
|
172
|
-
fail('Not inside a Codapult project.');
|
|
173
|
-
process.exit(1);
|
|
174
|
-
}
|
|
162
|
+
const root = checkProjectRoot('exit');
|
|
175
163
|
const kebab = toKebab(name);
|
|
176
164
|
const camel = toCamel(name);
|
|
177
165
|
const schemaName = `${camel}Schema`;
|
|
@@ -220,11 +208,7 @@ export async function ${camel}Action(input: unknown): Promise<{ success: boolean
|
|
|
220
208
|
// ---------------------------------------------------------------------------
|
|
221
209
|
export function generatePluginCommand(name) {
|
|
222
210
|
validateGeneratedName(name);
|
|
223
|
-
const root =
|
|
224
|
-
if (!root) {
|
|
225
|
-
fail('Not inside a Codapult project.');
|
|
226
|
-
process.exit(1);
|
|
227
|
-
}
|
|
211
|
+
const root = checkProjectRoot('exit');
|
|
228
212
|
const kebab = toKebab(name);
|
|
229
213
|
const camel = toCamel(name);
|
|
230
214
|
const pascal = toPascal(name);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
vi.mock('node:fs');
|
|
3
|
-
vi.mock('../utils/project.js', () => ({
|
|
3
|
+
vi.mock('../utils/project.js', async (importOriginal) => ({
|
|
4
4
|
findProjectRoot: vi.fn(),
|
|
5
|
+
checkProjectRoot: vi.fn((await importOriginal()).checkProjectRoot),
|
|
5
6
|
}));
|
|
6
7
|
vi.mock('../utils/ui.js', () => ({
|
|
7
8
|
heading: vi.fn(),
|
|
@@ -11,9 +12,10 @@ vi.mock('../utils/ui.js', () => ({
|
|
|
11
12
|
dim: vi.fn(),
|
|
12
13
|
}));
|
|
13
14
|
const { existsSync, writeFileSync, mkdirSync } = await import('node:fs');
|
|
14
|
-
const { findProjectRoot } = await import('../utils/project.js');
|
|
15
|
+
const { checkProjectRoot, findProjectRoot } = await import('../utils/project.js');
|
|
15
16
|
const { generatePageCommand, generateApiCommand, generateActionCommand, generatePluginCommand } = await import('./generate.js');
|
|
16
17
|
const mockedFindRoot = vi.mocked(findProjectRoot);
|
|
18
|
+
const mockedCheckRoot = vi.mocked(checkProjectRoot);
|
|
17
19
|
const mockedExists = vi.mocked(existsSync);
|
|
18
20
|
const mockedWrite = vi.mocked(writeFileSync);
|
|
19
21
|
const mockedMkdir = vi.mocked(mkdirSync);
|
|
@@ -25,7 +27,7 @@ beforeEach(() => {
|
|
|
25
27
|
});
|
|
26
28
|
describe('generatePageCommand', () => {
|
|
27
29
|
it('generates a dashboard page file with correct naming', () => {
|
|
28
|
-
|
|
30
|
+
mockedCheckRoot.mockReturnValue('/project');
|
|
29
31
|
mockedExists.mockReturnValue(false);
|
|
30
32
|
generatePageCommand('userSettings');
|
|
31
33
|
expect(mockedMkdir).toHaveBeenCalled();
|
|
@@ -37,14 +39,14 @@ describe('generatePageCommand', () => {
|
|
|
37
39
|
expect(content).toContain('getAppSession');
|
|
38
40
|
});
|
|
39
41
|
it('converts camelCase to kebab-case in path', () => {
|
|
40
|
-
|
|
42
|
+
mockedCheckRoot.mockReturnValue('/project');
|
|
41
43
|
mockedExists.mockReturnValue(false);
|
|
42
44
|
generatePageCommand('myDashboard');
|
|
43
45
|
const [path] = mockedWrite.mock.calls[0];
|
|
44
46
|
expect(path).toContain('my-dashboard/page.tsx');
|
|
45
47
|
});
|
|
46
48
|
it('does not overwrite existing page', () => {
|
|
47
|
-
|
|
49
|
+
mockedCheckRoot.mockReturnValue('/project');
|
|
48
50
|
mockedExists.mockReturnValue(true);
|
|
49
51
|
generatePageCommand('analytics');
|
|
50
52
|
expect(mockedWrite).not.toHaveBeenCalled();
|
|
@@ -57,7 +59,7 @@ describe('generatePageCommand', () => {
|
|
|
57
59
|
});
|
|
58
60
|
describe('generateApiCommand', () => {
|
|
59
61
|
it('generates an API route with auth and rate limiting', () => {
|
|
60
|
-
|
|
62
|
+
mockedCheckRoot.mockReturnValue('/project');
|
|
61
63
|
mockedExists.mockReturnValue(false);
|
|
62
64
|
generateApiCommand('webhooks');
|
|
63
65
|
const [path, content] = mockedWrite.mock.calls[0];
|
|
@@ -69,7 +71,7 @@ describe('generateApiCommand', () => {
|
|
|
69
71
|
expect(content).toContain('export async function POST(req: Request)');
|
|
70
72
|
});
|
|
71
73
|
it('converts multi-word names to kebab-case', () => {
|
|
72
|
-
|
|
74
|
+
mockedCheckRoot.mockReturnValue('/project');
|
|
73
75
|
mockedExists.mockReturnValue(false);
|
|
74
76
|
generateApiCommand('userBilling');
|
|
75
77
|
const [path, content] = mockedWrite.mock.calls[0];
|
|
@@ -79,7 +81,7 @@ describe('generateApiCommand', () => {
|
|
|
79
81
|
});
|
|
80
82
|
describe('generateActionCommand', () => {
|
|
81
83
|
it('generates a server action file', () => {
|
|
82
|
-
|
|
84
|
+
mockedCheckRoot.mockReturnValue('/project');
|
|
83
85
|
mockedExists.mockReturnValue(false);
|
|
84
86
|
generateActionCommand('updateProfile');
|
|
85
87
|
const [path, content] = mockedWrite.mock.calls[0];
|
|
@@ -94,7 +96,7 @@ describe('generateActionCommand', () => {
|
|
|
94
96
|
});
|
|
95
97
|
describe('generatePluginCommand', () => {
|
|
96
98
|
it('scaffolds a complete plugin directory', () => {
|
|
97
|
-
|
|
99
|
+
mockedCheckRoot.mockReturnValue('/project');
|
|
98
100
|
mockedExists.mockReturnValue(false);
|
|
99
101
|
generatePluginCommand('my-widget');
|
|
100
102
|
// package.json, tsconfig.json, src/index.ts, codapult-plugin.json, .gitignore, README.md
|
|
@@ -106,7 +108,7 @@ describe('generatePluginCommand', () => {
|
|
|
106
108
|
expect(writtenPaths.some((p) => p.includes('codapult-plugin.json'))).toBe(true);
|
|
107
109
|
});
|
|
108
110
|
it('generates correct plugin name references', () => {
|
|
109
|
-
|
|
111
|
+
mockedCheckRoot.mockReturnValue('/project');
|
|
110
112
|
mockedExists.mockReturnValue(false);
|
|
111
113
|
generatePluginCommand('dataSync');
|
|
112
114
|
const indexWrite = mockedWrite.mock.calls.find(([p]) => p.includes('src/index.ts'));
|
|
@@ -117,7 +119,7 @@ describe('generatePluginCommand', () => {
|
|
|
117
119
|
expect(content).toContain("label: 'DataSync'");
|
|
118
120
|
});
|
|
119
121
|
it('exits when target directory already exists', () => {
|
|
120
|
-
|
|
122
|
+
mockedCheckRoot.mockReturnValue('/project');
|
|
121
123
|
mockedExists.mockReturnValue(true);
|
|
122
124
|
expect(() => generatePluginCommand('existing')).toThrow('process.exit');
|
|
123
125
|
expect(process.exit).toHaveBeenCalledWith(1);
|
package/dist/commands/mcp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { execFileSync } from 'node:child_process';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { checkProjectRoot } from '../utils/project.js';
|
|
5
5
|
import { collectMcpHealth } from '../utils/health.js';
|
|
6
6
|
import { checkEnvSchemaCompatibility } from '../utils/env-compatibility.js';
|
|
7
7
|
import { heading, success, fail, info, dim } from '../utils/ui.js';
|
|
@@ -27,11 +27,7 @@ function resolveVersion(version) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
export function mcpUpdateCommand(version, options = {}) {
|
|
30
|
-
const root =
|
|
31
|
-
if (!root) {
|
|
32
|
-
fail('Not inside a Codapult project.');
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
30
|
+
const root = checkProjectRoot('exit');
|
|
35
31
|
const configPath = getConfigPath(root);
|
|
36
32
|
const targetVersion = resolveVersion(version);
|
|
37
33
|
const packageSpec = `${PACKAGE_NAME}@${targetVersion}`;
|
|
@@ -61,22 +57,15 @@ export function mcpUpdateCommand(version, options = {}) {
|
|
|
61
57
|
dim('Restart or reload the MCP connection in your editor to use the new version.');
|
|
62
58
|
}
|
|
63
59
|
export function mcpDoctorCommand() {
|
|
64
|
-
const root =
|
|
65
|
-
if (!root) {
|
|
66
|
-
fail('Not inside a Codapult project.');
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
60
|
+
const root = checkProjectRoot('exit');
|
|
69
61
|
const report = collectMcpHealth(root);
|
|
70
62
|
renderHealthReport('MCP Doctor', report);
|
|
71
63
|
process.exitCode = healthExitCode(report);
|
|
72
64
|
}
|
|
73
65
|
export function mcpContractCheckCommand() {
|
|
74
|
-
const root =
|
|
75
|
-
if (!root)
|
|
76
|
-
fail('Not inside a Codapult project.');
|
|
77
|
-
process.exitCode = 1;
|
|
66
|
+
const root = checkProjectRoot('code');
|
|
67
|
+
if (!root)
|
|
78
68
|
return;
|
|
79
|
-
}
|
|
80
69
|
const result = checkEnvSchemaCompatibility(root);
|
|
81
70
|
heading('MCP Contract Check');
|
|
82
71
|
if (result.status === 'ok') {
|
package/dist/commands/plugins.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execSync, spawnSync } from 'node:child_process';
|
|
2
2
|
import { existsSync, readFileSync, readdirSync, rmSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { checkProjectRoot } from '../utils/project.js';
|
|
5
5
|
import { ENV_FILE_NAME, getProjectEnvSource, } from '../utils/project-env.js';
|
|
6
6
|
import { resolveManifest } from '../utils/manifest.js';
|
|
7
7
|
import { clonePlugin } from '../utils/git.js';
|
|
@@ -17,11 +17,7 @@ function execQuiet(cmd, cwd) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
export async function pluginsAddCommand(name, options = {}) {
|
|
20
|
-
const root =
|
|
21
|
-
if (!root) {
|
|
22
|
-
fail('Not inside a Codapult project.');
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
20
|
+
const root = checkProjectRoot('exit');
|
|
25
21
|
heading(`Installing plugin: ${name}`);
|
|
26
22
|
// Clone from a git URL when --from is provided
|
|
27
23
|
if (options.from) {
|
|
@@ -212,11 +208,7 @@ export async function pluginsAddCommand(name, options = {}) {
|
|
|
212
208
|
console.log();
|
|
213
209
|
}
|
|
214
210
|
export async function pluginsRemoveCommand(name, options = {}) {
|
|
215
|
-
const root =
|
|
216
|
-
if (!root) {
|
|
217
|
-
fail('Not inside a Codapult project.');
|
|
218
|
-
process.exit(1);
|
|
219
|
-
}
|
|
211
|
+
const root = checkProjectRoot('exit');
|
|
220
212
|
heading(`Removing plugin: ${name}`);
|
|
221
213
|
const result = resolveManifest(root, name);
|
|
222
214
|
let manifest = result?.manifest;
|
|
@@ -324,11 +316,7 @@ function getInstalledPluginNames(root) {
|
|
|
324
316
|
.map((f) => f.replace('.ts', ''));
|
|
325
317
|
}
|
|
326
318
|
export async function pluginsMigrateCommand(name, options) {
|
|
327
|
-
const root =
|
|
328
|
-
if (!root) {
|
|
329
|
-
fail('Not inside a Codapult project.');
|
|
330
|
-
process.exit(1);
|
|
331
|
-
}
|
|
319
|
+
const root = checkProjectRoot('exit');
|
|
332
320
|
const pluginNames = name ? [name] : getInstalledPluginNames(root);
|
|
333
321
|
if (pluginNames.length === 0) {
|
|
334
322
|
info('No installed plugins found.');
|
|
@@ -422,11 +410,7 @@ export async function pluginsMigrateCommand(name, options) {
|
|
|
422
410
|
// codapult plugins list
|
|
423
411
|
// ---------------------------------------------------------------------------
|
|
424
412
|
export function pluginsListCommand() {
|
|
425
|
-
const root =
|
|
426
|
-
if (!root) {
|
|
427
|
-
fail('Not inside a Codapult project.');
|
|
428
|
-
process.exit(1);
|
|
429
|
-
}
|
|
413
|
+
const root = checkProjectRoot('exit');
|
|
430
414
|
heading('Installed Plugins');
|
|
431
415
|
const pluginsDir = resolve(root, 'src/plugins');
|
|
432
416
|
if (!existsSync(pluginsDir)) {
|
package/dist/commands/setup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
|
|
2
2
|
import { resolve, relative, join } from 'node:path';
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
|
-
import {
|
|
4
|
+
import { checkProjectRoot } from '../utils/project.js';
|
|
5
5
|
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, } from '../utils/project-env.js';
|
|
6
6
|
import { heading, success, fail, info, dim, ask, confirm } from '../utils/ui.js';
|
|
7
7
|
async function selectPrompt(iface, question, options) {
|
|
@@ -783,11 +783,7 @@ async function interactiveSetup() {
|
|
|
783
783
|
return config;
|
|
784
784
|
}
|
|
785
785
|
export async function setupCommand(options) {
|
|
786
|
-
const root =
|
|
787
|
-
if (!root) {
|
|
788
|
-
fail('Not inside a Codapult project. Run this from your project directory.');
|
|
789
|
-
process.exit(1);
|
|
790
|
-
}
|
|
786
|
+
const root = checkProjectRoot('exit');
|
|
791
787
|
const presetRaw = options.preset;
|
|
792
788
|
let config;
|
|
793
789
|
if (presetRaw) {
|