@codapult/cli 0.4.2 → 0.6.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/dist/commands/config-show.d.ts +2 -1
- package/dist/commands/config-show.js +12 -8
- package/dist/commands/db.d.ts +6 -5
- package/dist/commands/db.js +15 -17
- package/dist/commands/deploy.d.ts +5 -4
- package/dist/commands/deploy.js +28 -10
- package/dist/commands/doctor.d.ts +2 -1
- package/dist/commands/doctor.js +13 -7
- package/dist/commands/env.d.ts +3 -2
- package/dist/commands/env.js +27 -18
- package/dist/commands/plugins.d.ts +4 -3
- package/dist/commands/plugins.js +18 -6
- package/dist/commands/setup.d.ts +2 -1
- package/dist/commands/setup.js +28 -9
- package/dist/index.js +21 -27
- package/dist/mcp/resources.js +4 -3
- package/dist/mcp/tools/db.js +7 -3
- package/dist/mcp/tools/db.test.js +18 -2
- package/dist/mcp/tools/deploy.js +2 -1
- package/dist/mcp/tools/env.js +30 -14
- package/dist/mcp/tools/env.test.js +31 -8
- package/dist/mcp/tools/plugins.js +20 -6
- package/dist/mcp/tools/project.js +25 -7
- package/dist/mcp/tools/project.test.js +56 -11
- package/dist/mcp/tools/schemas.d.ts +5 -0
- package/dist/mcp/tools/schemas.js +5 -0
- package/dist/utils/env-config.d.ts +4 -4
- package/dist/utils/env-config.js +4 -4
- package/dist/utils/patchers.js +3 -2
- package/dist/utils/patchers.test.js +2 -1
- package/dist/utils/project-env.d.ts +16 -0
- package/dist/utils/project-env.js +38 -0
- package/dist/utils/project-env.test.d.ts +1 -0
- package/dist/utils/project-env.test.js +47 -0
- package/package.json +1 -1
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ProjectEnvOptions } from '../utils/project-env.js';
|
|
2
|
+
export declare function configShowCommand(options?: ProjectEnvOptions): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { findProjectRoot, readJsonFile } from '../utils/project.js';
|
|
4
|
+
import { ENV_FILE_NAME, loadProjectEnv } from '../utils/project-env.js';
|
|
4
5
|
import { getAdapters, getAuthMethods, getFeatures, getOauthProviders, FEATURE_ENV, } from '../utils/env-config.js';
|
|
5
6
|
import { heading, success, fail, info, dim, label } from '../utils/ui.js';
|
|
6
7
|
/** Extracts a quoted string from a TS object literal: `field: 'value'` or `field: "value"`. */
|
|
@@ -21,7 +22,7 @@ function extractTsBoolField(content, field) {
|
|
|
21
22
|
const match = regex.exec(content);
|
|
22
23
|
return match ? match[1] === 'true' : null;
|
|
23
24
|
}
|
|
24
|
-
export function configShowCommand() {
|
|
25
|
+
export function configShowCommand(options = {}) {
|
|
25
26
|
const root = findProjectRoot();
|
|
26
27
|
if (!root) {
|
|
27
28
|
fail('Not inside a Codapult project.');
|
|
@@ -36,8 +37,8 @@ export function configShowCommand() {
|
|
|
36
37
|
label('Version', typeof pkg.version === 'string' ? pkg.version : 'unknown');
|
|
37
38
|
}
|
|
38
39
|
console.log();
|
|
39
|
-
const
|
|
40
|
-
const envContent =
|
|
40
|
+
const env = loadProjectEnv(root, options);
|
|
41
|
+
const envContent = env.content;
|
|
41
42
|
// --- App config (src/config/app.ts) ---
|
|
42
43
|
const appConfigPath = resolve(root, 'src/config/app.ts');
|
|
43
44
|
if (existsSync(appConfigPath)) {
|
|
@@ -82,12 +83,15 @@ export function configShowCommand() {
|
|
|
82
83
|
dim('src/config/app.ts not found — run `codapult setup`');
|
|
83
84
|
}
|
|
84
85
|
console.log();
|
|
85
|
-
if (!
|
|
86
|
-
dim(
|
|
86
|
+
if (env.source === 'file' && !env.fileExists) {
|
|
87
|
+
dim(`${ENV_FILE_NAME} not found — adapters / features / auth methods unavailable`);
|
|
87
88
|
console.log();
|
|
88
89
|
return;
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
+
if (env.source === 'process') {
|
|
92
|
+
dim('Reading adapters / features / auth methods from process.env');
|
|
93
|
+
}
|
|
94
|
+
// --- Adapters (from project env source) ---
|
|
91
95
|
info('Adapters');
|
|
92
96
|
const adapters = getAdapters(envContent);
|
|
93
97
|
label(' Database', adapters.database);
|
|
@@ -99,7 +103,7 @@ export function configShowCommand() {
|
|
|
99
103
|
label(' Embedding', adapters.embedding);
|
|
100
104
|
label(' Vector store', adapters.vectorStore);
|
|
101
105
|
console.log();
|
|
102
|
-
// --- Auth methods (from
|
|
106
|
+
// --- Auth methods (from project env source) ---
|
|
103
107
|
info('Auth methods');
|
|
104
108
|
const authMethods = getAuthMethods(envContent);
|
|
105
109
|
label(' Magic Link', authMethods.magicLink ? 'enabled' : 'disabled');
|
|
@@ -108,7 +112,7 @@ export function configShowCommand() {
|
|
|
108
112
|
const oauth = getOauthProviders(envContent);
|
|
109
113
|
label(' OAuth providers', oauth.length > 0 ? oauth.join(', ') : 'none');
|
|
110
114
|
console.log();
|
|
111
|
-
// --- Feature toggles (from
|
|
115
|
+
// --- Feature toggles (from project env source + ENABLE_* defaults) ---
|
|
112
116
|
info('Features');
|
|
113
117
|
const features = getFeatures(envContent);
|
|
114
118
|
const featureKeys = Object.keys(FEATURE_ENV);
|
package/dist/commands/db.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
1
|
+
import { type ProjectEnvOptions } from '../utils/project-env.js';
|
|
2
|
+
export declare function dbPushCommand(options?: ProjectEnvOptions): void;
|
|
3
|
+
export declare function dbGenerateCommand(options?: ProjectEnvOptions): void;
|
|
4
|
+
export declare function dbSeedCommand(_options?: ProjectEnvOptions): void;
|
|
5
|
+
export declare function dbStudioCommand(options?: ProjectEnvOptions): void;
|
|
6
|
+
export declare function dbStatusCommand(options?: ProjectEnvOptions): Promise<void>;
|
package/dist/commands/db.js
CHANGED
|
@@ -2,6 +2,7 @@ import { execSync } from 'node:child_process';
|
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { findProjectRoot } from '../utils/project.js';
|
|
5
|
+
import { loadProjectEnv } from '../utils/project-env.js';
|
|
5
6
|
import { heading, success, fail, info, dim, warn } from '../utils/ui.js';
|
|
6
7
|
function run(cmd, cwd) {
|
|
7
8
|
info(`Running: ${cmd}`);
|
|
@@ -14,35 +15,32 @@ function run(cmd, cwd) {
|
|
|
14
15
|
process.exit(1);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
function getDbProvider(root) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (match)
|
|
23
|
-
return match[1];
|
|
24
|
-
}
|
|
18
|
+
function getDbProvider(root, options) {
|
|
19
|
+
const { content } = loadProjectEnv(root, options);
|
|
20
|
+
const match = /^DB_PROVIDER\s*=\s*"?(\w+)"?/m.exec(content);
|
|
21
|
+
if (match)
|
|
22
|
+
return match[1];
|
|
25
23
|
return 'turso';
|
|
26
24
|
}
|
|
27
|
-
export function dbPushCommand() {
|
|
25
|
+
export function dbPushCommand(options = {}) {
|
|
28
26
|
const root = findProjectRoot();
|
|
29
27
|
if (!root) {
|
|
30
28
|
fail('Not inside a Codapult project.');
|
|
31
29
|
process.exit(1);
|
|
32
30
|
}
|
|
33
31
|
heading('Database Push');
|
|
34
|
-
const provider = getDbProvider(root);
|
|
32
|
+
const provider = getDbProvider(root, options);
|
|
35
33
|
info(`Provider: ${provider}`);
|
|
36
34
|
run('pnpm db:push', root);
|
|
37
35
|
}
|
|
38
|
-
export function dbGenerateCommand() {
|
|
36
|
+
export function dbGenerateCommand(options = {}) {
|
|
39
37
|
const root = findProjectRoot();
|
|
40
38
|
if (!root) {
|
|
41
39
|
fail('Not inside a Codapult project.');
|
|
42
40
|
process.exit(1);
|
|
43
41
|
}
|
|
44
42
|
heading('Generate Migration');
|
|
45
|
-
const provider = getDbProvider(root);
|
|
43
|
+
const provider = getDbProvider(root, options);
|
|
46
44
|
info(`Provider: ${provider}`);
|
|
47
45
|
if (provider === 'postgres') {
|
|
48
46
|
run('DB_PROVIDER=postgres pnpm db:generate', root);
|
|
@@ -51,7 +49,7 @@ export function dbGenerateCommand() {
|
|
|
51
49
|
run('pnpm db:generate', root);
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
|
-
export function dbSeedCommand() {
|
|
52
|
+
export function dbSeedCommand(_options = {}) {
|
|
55
53
|
const root = findProjectRoot();
|
|
56
54
|
if (!root) {
|
|
57
55
|
fail('Not inside a Codapult project.');
|
|
@@ -60,14 +58,14 @@ export function dbSeedCommand() {
|
|
|
60
58
|
heading('Seed Database');
|
|
61
59
|
run('pnpm db:seed', root);
|
|
62
60
|
}
|
|
63
|
-
export function dbStudioCommand() {
|
|
61
|
+
export function dbStudioCommand(options = {}) {
|
|
64
62
|
const root = findProjectRoot();
|
|
65
63
|
if (!root) {
|
|
66
64
|
fail('Not inside a Codapult project.');
|
|
67
65
|
process.exit(1);
|
|
68
66
|
}
|
|
69
67
|
heading('Drizzle Studio');
|
|
70
|
-
const provider = getDbProvider(root);
|
|
68
|
+
const provider = getDbProvider(root, options);
|
|
71
69
|
info(`Provider: ${provider}`);
|
|
72
70
|
info('Opening Drizzle Studio in browser...');
|
|
73
71
|
if (provider === 'postgres') {
|
|
@@ -77,14 +75,14 @@ export function dbStudioCommand() {
|
|
|
77
75
|
run('npx drizzle-kit studio', root);
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
export async function dbStatusCommand() {
|
|
78
|
+
export async function dbStatusCommand(options = {}) {
|
|
81
79
|
const root = findProjectRoot();
|
|
82
80
|
if (!root) {
|
|
83
81
|
fail('Not inside a Codapult project.');
|
|
84
82
|
process.exit(1);
|
|
85
83
|
}
|
|
86
84
|
heading('Database Status');
|
|
87
|
-
const provider = getDbProvider(root);
|
|
85
|
+
const provider = getDbProvider(root, options);
|
|
88
86
|
info(`Provider: ${provider}`);
|
|
89
87
|
const schemaPath = resolve(root, 'src/lib/db/schema.ts');
|
|
90
88
|
if (existsSync(schemaPath)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
1
|
+
import { type ProjectEnvOptions } from '../utils/project-env.js';
|
|
2
|
+
export declare function deployVercelCommand(options?: ProjectEnvOptions): Promise<void>;
|
|
3
|
+
export declare function deployDockerCommand(opts?: {
|
|
3
4
|
tag?: string;
|
|
4
|
-
}): Promise<void>;
|
|
5
|
-
export declare function deployStatusCommand(): void;
|
|
5
|
+
} & ProjectEnvOptions): Promise<void>;
|
|
6
|
+
export declare function deployStatusCommand(options?: ProjectEnvOptions): void;
|
package/dist/commands/deploy.js
CHANGED
|
@@ -2,6 +2,7 @@ import { execSync } from 'node:child_process';
|
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { findProjectRoot } from '../utils/project.js';
|
|
5
|
+
import { ENV_FILE_NAME, getProjectEnvSource, loadProjectEnv, } from '../utils/project-env.js';
|
|
5
6
|
import { heading, success, fail, info, dim, warn, confirm } from '../utils/ui.js';
|
|
6
7
|
function hasCommand(cmd) {
|
|
7
8
|
try {
|
|
@@ -15,7 +16,7 @@ function hasCommand(cmd) {
|
|
|
15
16
|
// ---------------------------------------------------------------------------
|
|
16
17
|
// codapult deploy vercel
|
|
17
18
|
// ---------------------------------------------------------------------------
|
|
18
|
-
export async function deployVercelCommand() {
|
|
19
|
+
export async function deployVercelCommand(options = {}) {
|
|
19
20
|
const root = findProjectRoot();
|
|
20
21
|
if (!root) {
|
|
21
22
|
fail('Not inside a Codapult project.');
|
|
@@ -38,12 +39,14 @@ export async function deployVercelCommand() {
|
|
|
38
39
|
warn('vercel.json not found — Vercel will use defaults');
|
|
39
40
|
}
|
|
40
41
|
// 3. Check required env vars
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
|
|
42
|
+
const env = loadProjectEnv(root, options);
|
|
43
|
+
if (env.source === 'process') {
|
|
44
|
+
info('Checking Vercel env requirements from process.env');
|
|
45
|
+
}
|
|
46
|
+
if (env.source === 'process' || env.fileExists) {
|
|
44
47
|
const critical = ['TURSO_DATABASE_URL', 'BETTER_AUTH_SECRET', 'BETTER_AUTH_URL'];
|
|
45
48
|
for (const key of critical) {
|
|
46
|
-
const match = new RegExp(`^${key}\\s*=\\s*"?(.+?)"?\\s*$`, 'm').exec(content);
|
|
49
|
+
const match = new RegExp(`^${key}\\s*=\\s*"?(.+?)"?\\s*$`, 'm').exec(env.content);
|
|
47
50
|
if (match && !/^(your-|generate-)/.test(match[1])) {
|
|
48
51
|
success(`${key} configured`);
|
|
49
52
|
}
|
|
@@ -82,7 +85,7 @@ export async function deployVercelCommand() {
|
|
|
82
85
|
// ---------------------------------------------------------------------------
|
|
83
86
|
// codapult deploy docker
|
|
84
87
|
// ---------------------------------------------------------------------------
|
|
85
|
-
export async function deployDockerCommand(opts) {
|
|
88
|
+
export async function deployDockerCommand(opts = {}) {
|
|
86
89
|
const root = findProjectRoot();
|
|
87
90
|
if (!root) {
|
|
88
91
|
fail('Not inside a Codapult project.');
|
|
@@ -133,10 +136,17 @@ export async function deployDockerCommand(opts) {
|
|
|
133
136
|
console.log();
|
|
134
137
|
const runNow = await confirm('Run container locally? (port 3000)');
|
|
135
138
|
if (runNow) {
|
|
139
|
+
const envSource = getProjectEnvSource(opts);
|
|
140
|
+
if (envSource === 'process') {
|
|
141
|
+
warn(`Process env mode is enabled — automatic docker run with ${ENV_FILE_NAME} is unavailable`);
|
|
142
|
+
dim('Run Docker manually with the env vars you want to pass through.');
|
|
143
|
+
console.log();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
136
146
|
info('Starting container...');
|
|
137
|
-
dim(`docker run -p 3000:3000 --env-file
|
|
147
|
+
dim(`docker run -p 3000:3000 --env-file ${ENV_FILE_NAME} ${imageName}`);
|
|
138
148
|
try {
|
|
139
|
-
execSync(`docker run -p 3000:3000 --env-file
|
|
149
|
+
execSync(`docker run -p 3000:3000 --env-file ${ENV_FILE_NAME} ${imageName}`, {
|
|
140
150
|
cwd: root,
|
|
141
151
|
stdio: 'inherit',
|
|
142
152
|
});
|
|
@@ -150,7 +160,7 @@ export async function deployDockerCommand(opts) {
|
|
|
150
160
|
// ---------------------------------------------------------------------------
|
|
151
161
|
// codapult deploy status
|
|
152
162
|
// ---------------------------------------------------------------------------
|
|
153
|
-
export function deployStatusCommand() {
|
|
163
|
+
export function deployStatusCommand(options = {}) {
|
|
154
164
|
const root = findProjectRoot();
|
|
155
165
|
if (!root) {
|
|
156
166
|
fail('Not inside a Codapult project.');
|
|
@@ -164,7 +174,6 @@ export function deployStatusCommand() {
|
|
|
164
174
|
{ name: 'Terraform (AWS)', path: 'infra/terraform/main.tf' },
|
|
165
175
|
{ name: 'Pulumi (AWS)', path: 'infra/pulumi/index.ts' },
|
|
166
176
|
{ name: 'Helm chart', path: 'infra/helm/codapult/Chart.yaml' },
|
|
167
|
-
{ name: '.env.local', path: '.env.local' },
|
|
168
177
|
];
|
|
169
178
|
for (const { name, path } of checks) {
|
|
170
179
|
if (existsSync(resolve(root, path))) {
|
|
@@ -174,6 +183,15 @@ export function deployStatusCommand() {
|
|
|
174
183
|
dim(` · ${name} — not found`);
|
|
175
184
|
}
|
|
176
185
|
}
|
|
186
|
+
if (getProjectEnvSource(options) === 'process') {
|
|
187
|
+
success('Environment source: process.env');
|
|
188
|
+
}
|
|
189
|
+
else if (existsSync(resolve(root, ENV_FILE_NAME))) {
|
|
190
|
+
success(ENV_FILE_NAME);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
dim(` · ${ENV_FILE_NAME} — not found`);
|
|
194
|
+
}
|
|
177
195
|
// Check if standalone output is enabled
|
|
178
196
|
const nextConfig = resolve(root, 'next.config.ts');
|
|
179
197
|
if (existsSync(nextConfig)) {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ProjectEnvOptions } from '../utils/project-env.js';
|
|
2
|
+
export declare function doctorCommand(options?: ProjectEnvOptions): void;
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { existsSync,
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { execSync } from 'node:child_process';
|
|
4
4
|
import { findProjectRoot, readJsonFile } from '../utils/project.js';
|
|
5
|
+
import { ENV_FILE_NAME, loadProjectEnv } from '../utils/project-env.js';
|
|
5
6
|
import { resolveManifest } from '../utils/manifest.js';
|
|
6
7
|
import { findPageConflicts, findPageBackups } from '../utils/patchers.js';
|
|
7
8
|
import { findProviderIssues, getAdapters, readEnvVar } from '../utils/env-config.js';
|
|
@@ -24,7 +25,7 @@ function tryExec(cmd, cwd) {
|
|
|
24
25
|
return null;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
export function doctorCommand() {
|
|
28
|
+
export function doctorCommand(options = {}) {
|
|
28
29
|
const root = findProjectRoot();
|
|
29
30
|
if (!root) {
|
|
30
31
|
fail('Not inside a Codapult project.');
|
|
@@ -54,14 +55,19 @@ export function doctorCommand() {
|
|
|
54
55
|
console.log();
|
|
55
56
|
// --- Environment ---
|
|
56
57
|
info('Environment');
|
|
57
|
-
const
|
|
58
|
-
if (!
|
|
59
|
-
fail(
|
|
58
|
+
const env = loadProjectEnv(root, options);
|
|
59
|
+
if (env.source === 'file' && !env.fileExists) {
|
|
60
|
+
fail(`${ENV_FILE_NAME} not found — run \`codapult setup\``);
|
|
60
61
|
issues += 1;
|
|
61
62
|
}
|
|
62
63
|
else {
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
if (env.source === 'process') {
|
|
65
|
+
success('Using process.env (project configured with --no-env-file)');
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
success(`${ENV_FILE_NAME} exists`);
|
|
69
|
+
}
|
|
70
|
+
const envContent = env.content;
|
|
65
71
|
const adapters = getAdapters(envContent);
|
|
66
72
|
label(' DB_PROVIDER', adapters.database);
|
|
67
73
|
label(' AUTH_PROVIDER', adapters.auth);
|
package/dist/commands/env.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
1
|
+
import { type ProjectEnvOptions } from '../utils/project-env.js';
|
|
2
|
+
export declare function envCheckCommand(options?: ProjectEnvOptions): void;
|
|
3
|
+
export declare function envSyncCommand(options?: ProjectEnvOptions): Promise<void>;
|
package/dist/commands/env.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { findProjectRoot } from '../utils/project.js';
|
|
4
|
+
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, getProjectEnvSource, loadProjectEnv, } from '../utils/project-env.js';
|
|
4
5
|
import { heading, success, fail, info, dim, warn, confirm } from '../utils/ui.js';
|
|
5
6
|
function parseEnvFile(content) {
|
|
6
7
|
const entries = [];
|
|
@@ -30,25 +31,26 @@ function parseEnvFile(content) {
|
|
|
30
31
|
// ---------------------------------------------------------------------------
|
|
31
32
|
// codapult env check
|
|
32
33
|
// ---------------------------------------------------------------------------
|
|
33
|
-
export function envCheckCommand() {
|
|
34
|
+
export function envCheckCommand(options = {}) {
|
|
34
35
|
const root = findProjectRoot();
|
|
35
36
|
if (!root) {
|
|
36
37
|
fail('Not inside a Codapult project.');
|
|
37
38
|
process.exit(1);
|
|
38
39
|
}
|
|
39
40
|
heading('Environment Check');
|
|
40
|
-
const examplePath = resolve(root,
|
|
41
|
-
const localPath = resolve(root,
|
|
41
|
+
const examplePath = resolve(root, ENV_EXAMPLE_FILE_NAME);
|
|
42
|
+
const localPath = resolve(root, ENV_FILE_NAME);
|
|
42
43
|
if (!existsSync(examplePath)) {
|
|
43
|
-
fail(
|
|
44
|
+
fail(`${ENV_EXAMPLE_FILE_NAME} not found`);
|
|
44
45
|
process.exit(1);
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
const env = loadProjectEnv(root, options);
|
|
48
|
+
if (env.source === 'file' && !existsSync(localPath)) {
|
|
49
|
+
fail(`${ENV_FILE_NAME} not found — run: cp ${ENV_EXAMPLE_FILE_NAME} ${ENV_FILE_NAME}`);
|
|
48
50
|
process.exit(1);
|
|
49
51
|
}
|
|
50
52
|
const exampleEntries = parseEnvFile(readFileSync(examplePath, 'utf-8'));
|
|
51
|
-
const localContent =
|
|
53
|
+
const localContent = env.content;
|
|
52
54
|
const localEntries = parseEnvFile(localContent);
|
|
53
55
|
const localKeys = new Set(localEntries.map((e) => e.key));
|
|
54
56
|
const requiredKeys = exampleEntries.filter((e) => e.required);
|
|
@@ -73,7 +75,8 @@ export function envCheckCommand() {
|
|
|
73
75
|
const extra = localEntries.filter((e) => !exampleEntries.some((ex) => ex.key === e.key));
|
|
74
76
|
if (extra.length > 0) {
|
|
75
77
|
console.log();
|
|
76
|
-
|
|
78
|
+
const envLabel = env.source === 'process' ? 'process.env' : ENV_FILE_NAME;
|
|
79
|
+
info(`${extra.length} extra variable(s) in ${envLabel} (not in ${ENV_EXAMPLE_FILE_NAME}):`);
|
|
77
80
|
for (const e of extra) {
|
|
78
81
|
dim(` ${e.key}`);
|
|
79
82
|
}
|
|
@@ -93,24 +96,30 @@ export function envCheckCommand() {
|
|
|
93
96
|
// ---------------------------------------------------------------------------
|
|
94
97
|
// codapult env sync
|
|
95
98
|
// ---------------------------------------------------------------------------
|
|
96
|
-
export async function envSyncCommand() {
|
|
99
|
+
export async function envSyncCommand(options = {}) {
|
|
97
100
|
const root = findProjectRoot();
|
|
98
101
|
if (!root) {
|
|
99
102
|
fail('Not inside a Codapult project.');
|
|
100
103
|
process.exit(1);
|
|
101
104
|
}
|
|
102
|
-
heading(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
heading(`Sync ${ENV_FILE_NAME} with ${ENV_EXAMPLE_FILE_NAME}`);
|
|
106
|
+
if (getProjectEnvSource(options) === 'process') {
|
|
107
|
+
warn(`\`codapult env sync --no-env-file\` cannot update process.env`);
|
|
108
|
+
dim(`Use this command without \`--no-env-file\` to manage ${ENV_FILE_NAME}.`);
|
|
109
|
+
console.log();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const examplePath = resolve(root, ENV_EXAMPLE_FILE_NAME);
|
|
113
|
+
const localPath = resolve(root, ENV_FILE_NAME);
|
|
105
114
|
if (!existsSync(examplePath)) {
|
|
106
|
-
fail(
|
|
115
|
+
fail(`${ENV_EXAMPLE_FILE_NAME} not found`);
|
|
107
116
|
process.exit(1);
|
|
108
117
|
}
|
|
109
118
|
if (!existsSync(localPath)) {
|
|
110
|
-
info(
|
|
119
|
+
info(`${ENV_FILE_NAME} does not exist — creating from ${ENV_EXAMPLE_FILE_NAME}`);
|
|
111
120
|
const content = readFileSync(examplePath, 'utf-8');
|
|
112
121
|
writeFileSync(localPath, content, 'utf-8');
|
|
113
|
-
success(
|
|
122
|
+
success(`Created ${ENV_FILE_NAME}`);
|
|
114
123
|
return;
|
|
115
124
|
}
|
|
116
125
|
const exampleEntries = parseEnvFile(readFileSync(examplePath, 'utf-8'));
|
|
@@ -123,11 +132,11 @@ export async function envSyncCommand() {
|
|
|
123
132
|
console.log();
|
|
124
133
|
return;
|
|
125
134
|
}
|
|
126
|
-
info(`${newEntries.length} new variable(s) found in
|
|
135
|
+
info(`${newEntries.length} new variable(s) found in ${ENV_EXAMPLE_FILE_NAME}:`);
|
|
127
136
|
for (const e of newEntries) {
|
|
128
137
|
dim(` ${e.key}=${e.value}${e.comment ? ` # ${e.comment}` : ''}`);
|
|
129
138
|
}
|
|
130
|
-
const proceed = await confirm(`Add ${newEntries.length} variable(s) to
|
|
139
|
+
const proceed = await confirm(`Add ${newEntries.length} variable(s) to ${ENV_FILE_NAME}?`);
|
|
131
140
|
if (!proceed) {
|
|
132
141
|
info('Cancelled.');
|
|
133
142
|
return;
|
|
@@ -139,6 +148,6 @@ export async function envSyncCommand() {
|
|
|
139
148
|
appendContent += `${e.key}=${e.value}\n`;
|
|
140
149
|
}
|
|
141
150
|
writeFileSync(localPath, localContent.trimEnd() + appendContent, 'utf-8');
|
|
142
|
-
success(`Added ${newEntries.length} variable(s) to
|
|
151
|
+
success(`Added ${newEntries.length} variable(s) to ${ENV_FILE_NAME}`);
|
|
143
152
|
console.log();
|
|
144
153
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ProjectEnvOptions } from '../utils/project-env.js';
|
|
2
|
+
export declare function pluginsAddCommand(name: string, options?: {
|
|
2
3
|
from?: string;
|
|
3
4
|
ci?: boolean;
|
|
4
|
-
}): Promise<void>;
|
|
5
|
-
export declare function pluginsRemoveCommand(name: string): Promise<void>;
|
|
5
|
+
} & ProjectEnvOptions): Promise<void>;
|
|
6
|
+
export declare function pluginsRemoveCommand(name: string, options?: ProjectEnvOptions): Promise<void>;
|
|
6
7
|
export declare function pluginsMigrateCommand(name: string | undefined, options: {
|
|
7
8
|
push?: boolean;
|
|
8
9
|
}): Promise<void>;
|
package/dist/commands/plugins.js
CHANGED
|
@@ -2,6 +2,7 @@ import { execSync, spawnSync } from 'node:child_process';
|
|
|
2
2
|
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { findProjectRoot } from '../utils/project.js';
|
|
5
|
+
import { ENV_FILE_NAME, getProjectEnvSource, } from '../utils/project-env.js';
|
|
5
6
|
import { resolveManifest } from '../utils/manifest.js';
|
|
6
7
|
import { clonePlugin } from '../utils/git.js';
|
|
7
8
|
import { patchSchemaImports, patchSchemaTables, patchDbReExports, patchNextConfig, createPluginRegistration, patchPages, findPageConflicts, patchEnvFile, patchPackageJson, } from '../utils/patchers.js';
|
|
@@ -18,7 +19,7 @@ function execQuiet(cmd, cwd) {
|
|
|
18
19
|
// ---------------------------------------------------------------------------
|
|
19
20
|
// codapult plugins add <name>
|
|
20
21
|
// ---------------------------------------------------------------------------
|
|
21
|
-
export async function pluginsAddCommand(name, options) {
|
|
22
|
+
export async function pluginsAddCommand(name, options = {}) {
|
|
22
23
|
const root = findProjectRoot();
|
|
23
24
|
if (!root) {
|
|
24
25
|
fail('Not inside a Codapult project.');
|
|
@@ -149,8 +150,14 @@ export async function pluginsAddCommand(name, options) {
|
|
|
149
150
|
// 9. Append env vars (skipped in CI — env vars are configured in the hosting dashboard)
|
|
150
151
|
if (!options.ci && manifest.install.env && Object.keys(manifest.install.env).length > 0) {
|
|
151
152
|
info('Adding environment variables...');
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
if (getProjectEnvSource(options) === 'process') {
|
|
154
|
+
warn(`Project uses process.env — skipping ${ENV_FILE_NAME} patch`);
|
|
155
|
+
dim('Add the plugin env vars in your shell, CI, or hosting dashboard.');
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
patchEnvFile(root, manifest.name, manifest.install.env, 'add');
|
|
159
|
+
success(`Environment variables added to ${ENV_FILE_NAME}`);
|
|
160
|
+
}
|
|
154
161
|
}
|
|
155
162
|
if (options.ci) {
|
|
156
163
|
heading('Done!');
|
|
@@ -200,7 +207,7 @@ export async function pluginsAddCommand(name, options) {
|
|
|
200
207
|
// ---------------------------------------------------------------------------
|
|
201
208
|
// codapult plugins remove <name>
|
|
202
209
|
// ---------------------------------------------------------------------------
|
|
203
|
-
export async function pluginsRemoveCommand(name) {
|
|
210
|
+
export async function pluginsRemoveCommand(name, options = {}) {
|
|
204
211
|
const root = findProjectRoot();
|
|
205
212
|
if (!root) {
|
|
206
213
|
fail('Not inside a Codapult project.');
|
|
@@ -264,8 +271,13 @@ export async function pluginsRemoveCommand(name) {
|
|
|
264
271
|
// 7. Remove env vars
|
|
265
272
|
if (manifest.install.env && Object.keys(manifest.install.env).length > 0) {
|
|
266
273
|
info('Removing environment variables...');
|
|
267
|
-
|
|
268
|
-
|
|
274
|
+
if (getProjectEnvSource(options) === 'process') {
|
|
275
|
+
warn(`Project uses process.env — no ${ENV_FILE_NAME} changes to remove`);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
patchEnvFile(root, manifest.name, manifest.install.env, 'remove');
|
|
279
|
+
success('Environment variables removed');
|
|
280
|
+
}
|
|
269
281
|
}
|
|
270
282
|
// 8. Remove dependency
|
|
271
283
|
info('Removing dependency...');
|
package/dist/commands/setup.d.ts
CHANGED
package/dist/commands/setup.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'node
|
|
|
2
2
|
import { resolve, relative, join } from 'node:path';
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
4
|
import { findProjectRoot } from '../utils/project.js';
|
|
5
|
+
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, } from '../utils/project-env.js';
|
|
5
6
|
import { heading, success, fail, info, dim } from '../utils/ui.js';
|
|
6
7
|
const rl = () => createInterface({ input: process.stdin, output: process.stdout });
|
|
7
8
|
function ask(iface, question, defaultValue) {
|
|
@@ -221,6 +222,7 @@ const MODULE_REMOVALS = [
|
|
|
221
222
|
paths: [
|
|
222
223
|
`${APP}/(marketing)/docs/api`,
|
|
223
224
|
'src/lib/api-docs.ts',
|
|
225
|
+
'src/lib/openapi.ts',
|
|
224
226
|
'src/components/docs/ApiReference.tsx',
|
|
225
227
|
],
|
|
226
228
|
label: 'API Docs',
|
|
@@ -441,10 +443,10 @@ const FEATURE_ENV_VARS = {
|
|
|
441
443
|
enablePlugins: 'ENABLE_PLUGINS',
|
|
442
444
|
};
|
|
443
445
|
function generateEnvFile(root, config) {
|
|
444
|
-
const envExamplePath = join(root,
|
|
445
|
-
const envLocalPath = join(root,
|
|
446
|
+
const envExamplePath = join(root, ENV_EXAMPLE_FILE_NAME);
|
|
447
|
+
const envLocalPath = join(root, ENV_FILE_NAME);
|
|
446
448
|
if (existsSync(envLocalPath)) {
|
|
447
|
-
info(
|
|
449
|
+
info(`${ENV_FILE_NAME} already exists — creating ${ENV_FILE_NAME}.new instead`);
|
|
448
450
|
}
|
|
449
451
|
let content = existsSync(envExamplePath) ? readFileSync(envExamplePath, 'utf-8') : '';
|
|
450
452
|
const replacements = {
|
|
@@ -474,6 +476,13 @@ function generateEnvFile(root, config) {
|
|
|
474
476
|
writeFileSync(outputPath, content, 'utf-8');
|
|
475
477
|
success(`Written to ${relative(root, outputPath)}`);
|
|
476
478
|
}
|
|
479
|
+
function printProcessEnvNextSteps() {
|
|
480
|
+
info('Next steps:');
|
|
481
|
+
dim('1. Configure required env vars in your shell, CI, or Vercel dashboard');
|
|
482
|
+
dim('2. pnpm install');
|
|
483
|
+
dim('3. Run Codapult commands from a process where those env vars are available');
|
|
484
|
+
dim('4. pnpm dev');
|
|
485
|
+
}
|
|
477
486
|
function generateMcpConfig(root) {
|
|
478
487
|
const cursorDir = join(root, '.cursor');
|
|
479
488
|
const mcpPath = join(cursorDir, 'mcp.json');
|
|
@@ -600,7 +609,12 @@ export async function setupCommand(options) {
|
|
|
600
609
|
config = await interactiveSetup();
|
|
601
610
|
}
|
|
602
611
|
heading('Generating configuration');
|
|
603
|
-
|
|
612
|
+
if (options.envFile === false) {
|
|
613
|
+
dim(`Skipped ${ENV_FILE_NAME} generation`);
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
generateEnvFile(root, config);
|
|
617
|
+
}
|
|
604
618
|
heading('Removing unused modules');
|
|
605
619
|
removeModules(root, config);
|
|
606
620
|
heading('Setting up MCP integration');
|
|
@@ -610,11 +624,16 @@ export async function setupCommand(options) {
|
|
|
610
624
|
info('Preset applied. Proceeding to build.');
|
|
611
625
|
}
|
|
612
626
|
else {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
627
|
+
if (options.envFile === false) {
|
|
628
|
+
printProcessEnvNextSteps();
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
info('Next steps:');
|
|
632
|
+
dim(`1. Fill in secrets in ${ENV_FILE_NAME}`);
|
|
633
|
+
dim('2. pnpm install');
|
|
634
|
+
dim('3. pnpm db:push');
|
|
635
|
+
dim('4. pnpm dev');
|
|
636
|
+
}
|
|
618
637
|
}
|
|
619
638
|
console.log();
|
|
620
639
|
}
|