@codapult/cli 0.22.0 → 0.23.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 +1 -1
- package/dist/commands/config-show.js +8 -8
- package/dist/commands/mcp.js +6 -6
- package/dist/commands/recipes.js +4 -1
- package/dist/commands/setup.d.ts +126 -3
- package/dist/commands/setup.js +358 -152
- package/dist/index.js +1 -0
- package/dist/mcp/prompts.js +1 -1
- package/dist/mcp/resources.js +1 -1
- package/dist/mcp/tools/db.js +5 -4
- package/dist/mcp/tools/env.js +15 -13
- package/dist/mcp/tools/project.js +15 -9
- package/dist/utils/env-compatibility.d.ts +3 -3
- package/dist/utils/env-compatibility.js +23 -32
- package/dist/utils/env-config.d.ts +30 -89
- package/dist/utils/env-config.js +129 -312
- package/dist/utils/health.js +4 -4
- package/dist/utils/live-db-diff.js +3 -3
- package/dist/utils/project-env-schema.d.ts +31 -0
- package/dist/utils/project-env-schema.js +126 -0
- package/dist/utils/test-project-env.d.ts +2 -0
- package/dist/utils/test-project-env.js +55 -0
- package/package.json +2 -2
- package/dist/utils/env-schema-parser.d.ts +0 -2
- package/dist/utils/env-schema-parser.js +0 -32
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createRequire, registerHooks } from 'node:module';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { extname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import ts from 'typescript';
|
|
6
|
+
const ENV_SCHEMA_PATH = 'src/config/env-schema.ts';
|
|
7
|
+
const APP_CONFIG_PATH = 'src/config/app.ts';
|
|
8
|
+
const OAUTH_PROVIDERS_PATH = 'src/lib/auth/oauth-providers.ts';
|
|
9
|
+
const projectModules = new Map();
|
|
10
|
+
/**
|
|
11
|
+
* Load the env schema from the Codapult project, transpiling its TypeScript
|
|
12
|
+
* source in memory so the CLI can validate the exact source used by the app.
|
|
13
|
+
*/
|
|
14
|
+
export function loadProjectEnvSchema(root) {
|
|
15
|
+
// Function declarations are hoisted; keep the source-loading implementation below its API.
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
17
|
+
return loadProjectSourceModule(root, ENV_SCHEMA_PATH, (loaded) => typeof loaded.createEnvSchema === 'function');
|
|
18
|
+
}
|
|
19
|
+
export function loadProjectAppConfig(root) {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
21
|
+
return loadProjectSourceModule(root, APP_CONFIG_PATH, (loaded) => typeof loaded.createAppConfig === 'function');
|
|
22
|
+
}
|
|
23
|
+
export function loadProjectOAuthProviders(root) {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
25
|
+
return loadProjectSourceModule(root, OAUTH_PROVIDERS_PATH, (loaded) => {
|
|
26
|
+
const credentials = loaded.oauthCredentialKeys;
|
|
27
|
+
return typeof credentials === 'object' && credentials !== null;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function loadProjectSourceModule(root, relativePath, isExpectedModule) {
|
|
31
|
+
const sourcePath = resolve(root, relativePath);
|
|
32
|
+
if (!existsSync(sourcePath)) {
|
|
33
|
+
throw new Error(`Required project source is missing: ${relativePath}`);
|
|
34
|
+
}
|
|
35
|
+
const cached = projectModules.get(sourcePath);
|
|
36
|
+
if (cached) {
|
|
37
|
+
if (!isExpectedModule(cached))
|
|
38
|
+
throw new Error(`${relativePath} does not export expected values`);
|
|
39
|
+
return cached;
|
|
40
|
+
}
|
|
41
|
+
const absoluteRoot = resolve(root);
|
|
42
|
+
const projectRequire = createRequire(resolve(absoluteRoot, 'package.json'));
|
|
43
|
+
const hooks = registerHooks({
|
|
44
|
+
resolve(specifier, context, nextResolve) {
|
|
45
|
+
try {
|
|
46
|
+
return nextResolve(specifier, context);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (!specifier.startsWith('.') || extname(specifier))
|
|
50
|
+
throw error;
|
|
51
|
+
const resolved = nextResolve(`${specifier}.ts`, context);
|
|
52
|
+
if (resolved.url.startsWith('file:') &&
|
|
53
|
+
!fileURLToPath(resolved.url).startsWith(`${absoluteRoot}/`)) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
return resolved;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
load(url, context, nextLoad) {
|
|
60
|
+
if (!url.startsWith('file:') || !url.endsWith('.ts'))
|
|
61
|
+
return nextLoad(url, context);
|
|
62
|
+
const filename = fileURLToPath(url);
|
|
63
|
+
const source = readFileSync(filename, 'utf8');
|
|
64
|
+
const output = ts.transpileModule(source, {
|
|
65
|
+
fileName: filename,
|
|
66
|
+
compilerOptions: {
|
|
67
|
+
module: ts.ModuleKind.CommonJS,
|
|
68
|
+
target: ts.ScriptTarget.ES2022,
|
|
69
|
+
esModuleInterop: true,
|
|
70
|
+
},
|
|
71
|
+
}).outputText;
|
|
72
|
+
return { format: 'commonjs', source: output, shortCircuit: true };
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
try {
|
|
76
|
+
const loaded = projectRequire(sourcePath);
|
|
77
|
+
if (typeof loaded !== 'object' || loaded === null || !isExpectedModule(loaded)) {
|
|
78
|
+
throw new Error(`${relativePath} does not export the expected values`);
|
|
79
|
+
}
|
|
80
|
+
projectModules.set(sourcePath, loaded);
|
|
81
|
+
return loaded;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new Error(`Could not load project source ${relativePath}: ${String(error)}`, {
|
|
85
|
+
cause: error,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
hooks.deregister();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export function getProjectEnvSchema(root, environment = {}) {
|
|
93
|
+
const defaults = loadProjectAppConfig(root).createAppConfig(environment);
|
|
94
|
+
const schema = loadProjectEnvSchema(root).createEnvSchema(environment, {
|
|
95
|
+
skipRuntimeChecks: true,
|
|
96
|
+
defaults,
|
|
97
|
+
});
|
|
98
|
+
return schema;
|
|
99
|
+
}
|
|
100
|
+
export function getProjectEnvSchemaKeys(root) {
|
|
101
|
+
return Object.keys(getProjectEnvSchema(root).shape);
|
|
102
|
+
}
|
|
103
|
+
/** Parse the simple KEY=value format used by the project's env files. */
|
|
104
|
+
export function parseProjectEnv(content) {
|
|
105
|
+
const values = {};
|
|
106
|
+
for (const line of content.split(/\r?\n/)) {
|
|
107
|
+
const match = /^\s*(?:export\s+)?([A-Z][A-Z0-9_]*)\s*=\s*(.*?)\s*$/.exec(line);
|
|
108
|
+
if (!match)
|
|
109
|
+
continue;
|
|
110
|
+
const [, key, rawValue] = match;
|
|
111
|
+
let value = rawValue;
|
|
112
|
+
if (value.length >= 2 &&
|
|
113
|
+
((value.startsWith('"') && value.endsWith('"')) ||
|
|
114
|
+
(value.startsWith("'") && value.endsWith("'")) ||
|
|
115
|
+
(value.startsWith('`') && value.endsWith('`')))) {
|
|
116
|
+
value = value.slice(1, -1);
|
|
117
|
+
if (rawValue.startsWith('"'))
|
|
118
|
+
value = value.replace(/\\n/g, '\n').replace(/\\r/g, '\r');
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
value = value.replace(/\s+#.*$/, '').trim();
|
|
122
|
+
}
|
|
123
|
+
values[key] = value.trim().length > 0 ? value : undefined;
|
|
124
|
+
}
|
|
125
|
+
return values;
|
|
126
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
/** Write the minimal app-owned env source modules required by CLI integration fixtures. */
|
|
4
|
+
export function writeProjectEnvSources(root) {
|
|
5
|
+
mkdirSync(join(root, 'src/config'), { recursive: true });
|
|
6
|
+
mkdirSync(join(root, 'src/lib/auth'), { recursive: true });
|
|
7
|
+
writeFileSync(join(root, 'src/config/app.ts'), [
|
|
8
|
+
'export function createAppConfig(environment = {}) {',
|
|
9
|
+
" const appUrl = environment.NEXT_PUBLIC_APP_URL ?? 'http://localhost:3000';",
|
|
10
|
+
' return {',
|
|
11
|
+
" appName: environment.NEXT_PUBLIC_APP_NAME ?? 'codapult',",
|
|
12
|
+
' appUrl,',
|
|
13
|
+
" currency: environment.NEXT_PUBLIC_APP_CURRENCY ?? 'USD',",
|
|
14
|
+
' reverseProxyUrl: environment.NEXT_PUBLIC_APP_PROXY_URL,',
|
|
15
|
+
' };',
|
|
16
|
+
'}',
|
|
17
|
+
'export const appConfig = createAppConfig();',
|
|
18
|
+
'',
|
|
19
|
+
].join('\n'));
|
|
20
|
+
writeFileSync(join(root, 'src/config/env-schema.ts'), [
|
|
21
|
+
'const keys = [',
|
|
22
|
+
" 'APP_MODE', 'DB_PROVIDER', 'AUTH_PROVIDER', 'PAYMENT_PROVIDER',",
|
|
23
|
+
" 'STORAGE_PROVIDER', 'JOB_PROVIDER', 'SSO_PROVIDER', 'NOTIFICATION_TRANSPORT',",
|
|
24
|
+
" 'EMBEDDING_PROVIDER', 'VECTOR_STORE_PROVIDER', 'SUPPORT_PROVIDER',",
|
|
25
|
+
" 'ENABLE_TWO_FACTOR', 'AUTH_MAGIC_LINK', 'AUTH_PASSKEYS',",
|
|
26
|
+
" 'ENABLE_AI', 'ENABLE_AI_CHAT', 'ENABLE_AI_RAG', 'ENABLE_AI_AGENTS',",
|
|
27
|
+
" 'ENABLE_AI_BATCH', 'ENABLE_AI_PLAYGROUND', 'ENABLE_BLOG', 'ENABLE_TEAMS',",
|
|
28
|
+
" 'ENABLE_PROMOTIONS', 'ENABLE_SEO', 'ENABLE_COMPARE', 'ENABLE_DOCS', 'ENABLE_PLUGINS',",
|
|
29
|
+
" 'ENABLE_ANALYTICS', 'ENABLE_WORKFLOWS',",
|
|
30
|
+
'];',
|
|
31
|
+
'export function createEnvSchema(environment = {}, { defaults = {} } = {}) {',
|
|
32
|
+
" const landing = environment.APP_MODE === 'landing';",
|
|
33
|
+
" const alwaysOn = new Set(['ENABLE_DOCS', 'ENABLE_BLOG', 'ENABLE_PROMOTIONS', 'ENABLE_PLUGINS']);",
|
|
34
|
+
" const landingOnly = new Set(['ENABLE_SEO', 'ENABLE_COMPARE']);",
|
|
35
|
+
' const defaultsByKey = {',
|
|
36
|
+
" APP_MODE: 'full', DB_PROVIDER: 'turso', AUTH_PROVIDER: landing ? 'none' : 'better-auth',",
|
|
37
|
+
" PAYMENT_PROVIDER: 'stripe', STORAGE_PROVIDER: 'local', JOB_PROVIDER: landing ? 'none' : 'memory',",
|
|
38
|
+
" SSO_PROVIDER: 'none', NOTIFICATION_TRANSPORT: 'poll', EMBEDDING_PROVIDER: 'openai',",
|
|
39
|
+
" VECTOR_STORE_PROVIDER: 'sqlite', SUPPORT_PROVIDER: 'none',",
|
|
40
|
+
" ENABLE_TWO_FACTOR: 'true', AUTH_MAGIC_LINK: 'true', AUTH_PASSKEYS: 'true',",
|
|
41
|
+
" ENABLE_AI: String(!landing), ENABLE_AI_CHAT: String(!landing), ENABLE_AI_RAG: 'false',",
|
|
42
|
+
' ENABLE_AI_AGENTS: String(!landing), ENABLE_AI_BATCH: String(!landing), ENABLE_AI_PLAYGROUND: String(!landing),',
|
|
43
|
+
" ENABLE_BLOG: 'true', ENABLE_TEAMS: String(!landing), ENABLE_PROMOTIONS: 'true',",
|
|
44
|
+
" ENABLE_SEO: String(landing), ENABLE_COMPARE: String(landing), ENABLE_DOCS: 'true',",
|
|
45
|
+
" ENABLE_PLUGINS: 'true', ENABLE_ANALYTICS: String(!landing), ENABLE_WORKFLOWS: String(!landing),",
|
|
46
|
+
' NEXT_PUBLIC_APP_NAME: defaults.appName, NEXT_PUBLIC_APP_URL: defaults.appUrl,',
|
|
47
|
+
' };',
|
|
48
|
+
' return { shape: Object.fromEntries(keys.map((key) => [key, { parse: (value) => value ?? (',
|
|
49
|
+
" alwaysOn.has(key) ? 'true' : landingOnly.has(key) ? String(landing) : defaultsByKey[key]",
|
|
50
|
+
' ) }])) };',
|
|
51
|
+
'}',
|
|
52
|
+
'',
|
|
53
|
+
].join('\n'));
|
|
54
|
+
writeFileSync(join(root, 'src/lib/auth/oauth-providers.ts'), "export const oauthCredentialKeys = { google: ['GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_SECRET'] };\n");
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codapult/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"description": "Next.js SaaS CLI and MCP server for Codapult boilerplate projects, with setup, plugins, database, deployment, and AI-agent architecture guardrails",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"packageManager": "pnpm@12.16.1+sha512.091d1dee7927575661b25dab3c2ae31cafc1c54d6b71ed6a6600cf0c1cb10434a447eae14015f1b23e2e6bedeed79df94a932e2164d2832280dce3fb32f656d1",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=22.18.0"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"bin": {
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
function propertyName(node) {
|
|
3
|
-
if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node))
|
|
4
|
-
return node.text;
|
|
5
|
-
return undefined;
|
|
6
|
-
}
|
|
7
|
-
/** Extract keys from the z.object({...}) assigned to envSchema, independent of formatting/chaining. */
|
|
8
|
-
export function extractEnvSchemaKeys(content) {
|
|
9
|
-
const sourceFile = ts.createSourceFile('env-schema.ts', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
10
|
-
const keys = [];
|
|
11
|
-
const visit = (node) => {
|
|
12
|
-
if (ts.isCallExpression(node) &&
|
|
13
|
-
ts.isPropertyAccessExpression(node.expression) &&
|
|
14
|
-
node.expression.name.text === 'object') {
|
|
15
|
-
const object = node.arguments[0];
|
|
16
|
-
if (node.arguments.length > 0 && ts.isObjectLiteralExpression(object)) {
|
|
17
|
-
for (const property of object.properties) {
|
|
18
|
-
if (ts.isPropertyAssignment(property) ||
|
|
19
|
-
ts.isMethodDeclaration(property) ||
|
|
20
|
-
ts.isGetAccessorDeclaration(property)) {
|
|
21
|
-
const name = propertyName(property.name);
|
|
22
|
-
if (name)
|
|
23
|
-
keys.push(name);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
ts.forEachChild(node, visit);
|
|
29
|
-
};
|
|
30
|
-
visit(sourceFile);
|
|
31
|
-
return [...new Set(keys)];
|
|
32
|
-
}
|