@codapult/cli 0.21.1 → 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 +2 -2
- 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 +127 -4
- package/dist/commands/setup.js +360 -154
- 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 +9 -9
- package/dist/utils/env-schema-parser.d.ts +0 -2
- package/dist/utils/env-schema-parser.js +0 -32
package/dist/commands/setup.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
|
|
2
2
|
import { resolve, relative, join } from 'node:path';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
3
4
|
import { createInterface } from 'node:readline';
|
|
4
5
|
import { checkProjectRoot } from '../utils/project.js';
|
|
6
|
+
import { getFeatureEnv } from '../utils/env-config.js';
|
|
5
7
|
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, } from '../utils/project-env.js';
|
|
6
|
-
import { heading, success, fail, info, dim, ask, confirm } from '../utils/ui.js';
|
|
8
|
+
import { heading, success, fail, info, dim, ask, confirm, warn } from '../utils/ui.js';
|
|
7
9
|
async function selectPrompt(iface, question, options) {
|
|
8
10
|
console.log(`\n ${question}`);
|
|
9
11
|
options.forEach((opt, i) => console.log(` ${i + 1}. ${opt}`));
|
|
@@ -125,9 +127,11 @@ const BUILT_IN_PRESETS = {
|
|
|
125
127
|
enableBranding: false,
|
|
126
128
|
enableTwoFactor: false,
|
|
127
129
|
enableGraphQL: false,
|
|
128
|
-
|
|
130
|
+
enablePlugins: false,
|
|
131
|
+
enableDocs: true,
|
|
129
132
|
enableBlog: true,
|
|
130
|
-
|
|
133
|
+
enablePromotions: true,
|
|
134
|
+
enableSeo: true,
|
|
131
135
|
enableCompare: true,
|
|
132
136
|
removeUnusedCode: true,
|
|
133
137
|
},
|
|
@@ -136,10 +140,13 @@ const BUILT_IN_PRESETS = {
|
|
|
136
140
|
authProvider: 'better-auth',
|
|
137
141
|
},
|
|
138
142
|
};
|
|
143
|
+
function isBuiltInPresetName(value) {
|
|
144
|
+
return Object.hasOwn(BUILT_IN_PRESETS, value);
|
|
145
|
+
}
|
|
139
146
|
const DEFAULT_CONFIG = {
|
|
140
147
|
appName: 'Codapult',
|
|
141
148
|
appUrl: 'http://localhost:3000',
|
|
142
|
-
appMode: '
|
|
149
|
+
appMode: 'full',
|
|
143
150
|
authProvider: 'better-auth',
|
|
144
151
|
ssoProvider: 'none',
|
|
145
152
|
paymentProvider: 'stripe',
|
|
@@ -158,7 +165,7 @@ const DEFAULT_CONFIG = {
|
|
|
158
165
|
enableGraphQL: true,
|
|
159
166
|
enableSSO: false,
|
|
160
167
|
enableApiDocs: true,
|
|
161
|
-
|
|
168
|
+
enableDocs: true,
|
|
162
169
|
enableExperiments: true,
|
|
163
170
|
enableFeatureRequests: true,
|
|
164
171
|
enableCompare: false,
|
|
@@ -177,7 +184,10 @@ const DEFAULT_CONFIG = {
|
|
|
177
184
|
enableBranding: true,
|
|
178
185
|
enableTwoFactor: true,
|
|
179
186
|
enablePlugins: true,
|
|
187
|
+
enablePromotions: true,
|
|
188
|
+
enableSeo: true,
|
|
180
189
|
removeUnusedCode: false,
|
|
190
|
+
cleanPruneMarkers: true,
|
|
181
191
|
};
|
|
182
192
|
function parsePresetValue(raw) {
|
|
183
193
|
const parts = raw
|
|
@@ -185,18 +195,18 @@ function parsePresetValue(raw) {
|
|
|
185
195
|
.map((s) => s.trim())
|
|
186
196
|
.filter(Boolean);
|
|
187
197
|
const result = {};
|
|
188
|
-
if (parts.length === 1 && !parts[0].includes('=')) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
198
|
+
// if (parts.length === 1 && !parts[0].includes('=')) {
|
|
199
|
+
// const name = parts[0];
|
|
200
|
+
// if (!(name in BUILT_IN_PRESETS)) {
|
|
201
|
+
// fail(`Unknown preset: "${name}". Available: ${Object.keys(BUILT_IN_PRESETS).join(', ')}`);
|
|
202
|
+
// process.exit(1);
|
|
203
|
+
// }
|
|
204
|
+
// return BUILT_IN_PRESETS[name];
|
|
205
|
+
// }
|
|
196
206
|
let base = {};
|
|
197
207
|
for (const part of parts) {
|
|
198
208
|
if (!part.includes('=')) {
|
|
199
|
-
if (part
|
|
209
|
+
if (isBuiltInPresetName(part)) {
|
|
200
210
|
base = { ...base, ...BUILT_IN_PRESETS[part] };
|
|
201
211
|
continue;
|
|
202
212
|
}
|
|
@@ -223,10 +233,13 @@ export function resolvePreset(raw) {
|
|
|
223
233
|
config.enableBatch = false;
|
|
224
234
|
config.enablePlayground = false;
|
|
225
235
|
}
|
|
236
|
+
if (!config.enableTeams) {
|
|
237
|
+
config.enableBranding = false;
|
|
238
|
+
}
|
|
226
239
|
return config;
|
|
227
240
|
}
|
|
228
241
|
export function getPresetNames() {
|
|
229
|
-
return Object.keys(BUILT_IN_PRESETS);
|
|
242
|
+
return Object.keys(BUILT_IN_PRESETS).filter(isBuiltInPresetName);
|
|
230
243
|
}
|
|
231
244
|
// All app-router paths are under `src/app/[locale]/...` (next-intl).
|
|
232
245
|
// API routes (`src/app/api/...`) and `src/lib`/`src/components` paths
|
|
@@ -273,6 +286,7 @@ const MODULE_REMOVALS = [
|
|
|
273
286
|
`${APP}/(protected)/(dashboard)/dashboard/ai/chat`,
|
|
274
287
|
'src/components/ai/ChatUI.tsx',
|
|
275
288
|
'src/app/api/ai/chat',
|
|
289
|
+
'src/lib/ai/conversations.ts',
|
|
276
290
|
],
|
|
277
291
|
label: 'AI Chat',
|
|
278
292
|
},
|
|
@@ -284,6 +298,7 @@ const MODULE_REMOVALS = [
|
|
|
284
298
|
'src/lib/ai/embeddings',
|
|
285
299
|
'src/lib/ai/vector-store',
|
|
286
300
|
'src/lib/ai/rag.ts',
|
|
301
|
+
'src/lib/ai/rag.test.ts',
|
|
287
302
|
'src/app/api/ai/index',
|
|
288
303
|
'src/app/api/ai/search',
|
|
289
304
|
],
|
|
@@ -295,6 +310,9 @@ const MODULE_REMOVALS = [
|
|
|
295
310
|
`${APP}/(protected)/(dashboard)/dashboard/ai/agents`,
|
|
296
311
|
'src/components/ai/AgentBuilder.tsx',
|
|
297
312
|
'src/components/ai/AgentSelector.tsx',
|
|
313
|
+
'src/lib/ai/tools/agent-runner.ts',
|
|
314
|
+
'src/lib/ai/tools/agent-runner.test.ts',
|
|
315
|
+
'src/hooks/ai/useAgents.ts',
|
|
298
316
|
],
|
|
299
317
|
label: 'AI Agents',
|
|
300
318
|
},
|
|
@@ -303,6 +321,7 @@ const MODULE_REMOVALS = [
|
|
|
303
321
|
paths: [
|
|
304
322
|
`${APP}/(protected)/(dashboard)/dashboard/ai/batch`,
|
|
305
323
|
'src/components/ai/BatchJobManager.tsx',
|
|
324
|
+
'src/lib/ai/batch',
|
|
306
325
|
],
|
|
307
326
|
label: 'AI Batch',
|
|
308
327
|
},
|
|
@@ -312,6 +331,7 @@ const MODULE_REMOVALS = [
|
|
|
312
331
|
`${APP}/(protected)/(dashboard)/dashboard/ai/playground`,
|
|
313
332
|
'src/components/ai/AIPlayground.tsx',
|
|
314
333
|
'src/components/ai/PlaygroundComparison.tsx',
|
|
334
|
+
'src/lib/ai/playground',
|
|
315
335
|
],
|
|
316
336
|
label: 'AI Playground',
|
|
317
337
|
},
|
|
@@ -342,8 +362,12 @@ const MODULE_REMOVALS = [
|
|
|
342
362
|
'src/lib/db/organizations.ts',
|
|
343
363
|
'src/lib/actions/organizations.ts',
|
|
344
364
|
'src/lib/actions/organizations.test.ts',
|
|
365
|
+
'src/lib/organizations/quotas.ts',
|
|
366
|
+
'src/lib/organizations/quotas.test.ts',
|
|
367
|
+
'src/lib/organizations/active-org-cookie.ts',
|
|
345
368
|
'src/lib/payments/seats.ts',
|
|
346
369
|
'src/lib/payments/seats.test.ts',
|
|
370
|
+
'src/lib/scim',
|
|
347
371
|
'src/app/api/scim',
|
|
348
372
|
],
|
|
349
373
|
label: 'Teams',
|
|
@@ -353,8 +377,10 @@ const MODULE_REMOVALS = [
|
|
|
353
377
|
paths: [
|
|
354
378
|
`${APP}/(public)/(marketing)/waitlist`,
|
|
355
379
|
`${APP}/(protected)/(admin)/admin/waitlist`,
|
|
356
|
-
'src/components/
|
|
380
|
+
'src/components/waitlist',
|
|
381
|
+
'src/components/admin/WaitlistTable.tsx',
|
|
357
382
|
'src/lib/actions/waitlist.ts',
|
|
383
|
+
'src/app/api/admin/export/waitlist',
|
|
358
384
|
],
|
|
359
385
|
label: 'Waitlist',
|
|
360
386
|
},
|
|
@@ -386,7 +412,7 @@ const MODULE_REMOVALS = [
|
|
|
386
412
|
label: 'API Docs',
|
|
387
413
|
},
|
|
388
414
|
{
|
|
389
|
-
key: '
|
|
415
|
+
key: 'enableDocs',
|
|
390
416
|
paths: [
|
|
391
417
|
`${APP}/(public)/(marketing)/docs`,
|
|
392
418
|
'src/lib/docs',
|
|
@@ -429,8 +455,8 @@ const MODULE_REMOVALS = [
|
|
|
429
455
|
key: 'enableCompare',
|
|
430
456
|
paths: [
|
|
431
457
|
`${APP}/(public)/(marketing)/compare`,
|
|
458
|
+
'src/components/marketing/compare',
|
|
432
459
|
'src/config/competitor-comparison.ts',
|
|
433
|
-
'src/components/marketing/ComparisonTable.tsx',
|
|
434
460
|
],
|
|
435
461
|
label: 'Compare',
|
|
436
462
|
},
|
|
@@ -482,16 +508,40 @@ const MODULE_REMOVALS = [
|
|
|
482
508
|
],
|
|
483
509
|
label: 'Workflow Automation',
|
|
484
510
|
},
|
|
511
|
+
{
|
|
512
|
+
key: 'enablePromotions',
|
|
513
|
+
paths: [
|
|
514
|
+
`${APP}/(protected)/(admin)/admin/promotions`,
|
|
515
|
+
'src/components/admin/PromotionDurationFields.tsx',
|
|
516
|
+
'src/lib/actions/promotions.ts',
|
|
517
|
+
'src/lib/actions/promotions.test.ts',
|
|
518
|
+
],
|
|
519
|
+
label: 'Promotions',
|
|
520
|
+
},
|
|
485
521
|
{
|
|
486
522
|
key: 'enableReferrals',
|
|
487
523
|
paths: [
|
|
488
524
|
`${APP}/(protected)/(dashboard)/dashboard/referrals`,
|
|
525
|
+
'src/components/dashboard/ReferralDashboard.tsx',
|
|
489
526
|
'src/lib/referrals',
|
|
527
|
+
'src/lib/payments/referral-webhook.ts',
|
|
528
|
+
'src/lib/payments/referral-webhook.test.ts',
|
|
529
|
+
'src/lib/usage.test.ts',
|
|
490
530
|
'src/app/api/referrals',
|
|
491
|
-
'src/components/dashboard/ReferralDashboard.tsx',
|
|
492
531
|
],
|
|
493
532
|
label: 'Referral Program',
|
|
494
533
|
},
|
|
534
|
+
{
|
|
535
|
+
key: ['enablePromotions', 'enableReferrals'],
|
|
536
|
+
paths: [
|
|
537
|
+
'src/components/marketing/PromotionErrorToast.tsx',
|
|
538
|
+
'src/lib/promotions',
|
|
539
|
+
'src/lib/payments/promotion-checkout.ts',
|
|
540
|
+
'src/lib/payments/promotion-webhook.ts',
|
|
541
|
+
'src/lib/payments/promotion-webhook-data.ts',
|
|
542
|
+
],
|
|
543
|
+
label: 'Promotions & Referral Program',
|
|
544
|
+
},
|
|
495
545
|
{
|
|
496
546
|
key: 'enableAnalytics',
|
|
497
547
|
paths: [
|
|
@@ -506,12 +556,10 @@ const MODULE_REMOVALS = [
|
|
|
506
556
|
key: 'enableWebhooks',
|
|
507
557
|
paths: [
|
|
508
558
|
`${APP}/(protected)/(dashboard)/dashboard/webhooks`,
|
|
509
|
-
`${APP}/(protected)/(admin)/admin/webhooks`,
|
|
510
|
-
'src/app/api/webhooks',
|
|
511
|
-
'src/lib/outgoing-webhooks',
|
|
512
|
-
'src/lib/webhook-log.ts',
|
|
513
|
-
'src/lib/webhook-log.test.ts',
|
|
514
559
|
'src/components/dashboard/OutgoingWebhooks.tsx',
|
|
560
|
+
'src/app/api/webhooks/outgoing',
|
|
561
|
+
'src/lib/webhooks/outgoing.ts',
|
|
562
|
+
'src/lib/webhooks/outgoing.test.ts',
|
|
515
563
|
],
|
|
516
564
|
label: 'Outgoing Webhooks',
|
|
517
565
|
},
|
|
@@ -540,113 +588,206 @@ const MODULE_REMOVALS = [
|
|
|
540
588
|
key: 'enableBranding',
|
|
541
589
|
paths: [
|
|
542
590
|
`${APP}/(protected)/(dashboard)/dashboard/branding`,
|
|
591
|
+
`${APP}/(protected)/(dashboard)/dashboard/custom-domain`,
|
|
543
592
|
'src/components/dashboard/BrandingSettings.tsx',
|
|
544
593
|
'src/components/dashboard/BrandingProvider.tsx',
|
|
545
594
|
'src/components/dashboard/sidebar/SidebarBrandLink.tsx',
|
|
546
|
-
'src/app/api/branding',
|
|
547
|
-
'src/lib/branding',
|
|
548
|
-
`${APP}/(protected)/(dashboard)/dashboard/custom-domain`,
|
|
549
595
|
'src/components/dashboard/CustomDomainSettings.tsx',
|
|
596
|
+
'src/app/api/branding',
|
|
550
597
|
'src/app/api/custom-domain',
|
|
598
|
+
'src/lib/branding',
|
|
551
599
|
'src/lib/custom-domains',
|
|
552
600
|
],
|
|
553
601
|
label: 'White-label Branding',
|
|
554
602
|
},
|
|
555
603
|
{
|
|
556
604
|
key: 'enableTwoFactor',
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
label: 'Two-factor Authentication
|
|
605
|
+
paths: [
|
|
606
|
+
'src/components/dashboard/TwoFactorSettings.tsx',
|
|
607
|
+
'src/lib/email/templates/TwoFactorOtpEmail.tsx',
|
|
608
|
+
],
|
|
609
|
+
label: 'Two-factor Authentication',
|
|
562
610
|
},
|
|
563
611
|
{
|
|
564
612
|
key: 'enablePlugins',
|
|
565
613
|
paths: [
|
|
566
614
|
// `${APP}/(public)/(marketing)/plugins`,
|
|
567
615
|
`${APP}/(protected)/(dashboard)/dashboard/plugins`,
|
|
568
|
-
'src/
|
|
569
|
-
// 'src/components/marketing/
|
|
570
|
-
// 'src/components/marketing/PluginDetail.tsx',
|
|
616
|
+
// 'src/components/marketing/plugins/PluginsShowcase.tsx',
|
|
617
|
+
// 'src/components/marketing/plugins/PluginDetail.tsx',
|
|
571
618
|
'src/components/dashboard/PluginMarketplace.tsx',
|
|
619
|
+
'src/lib/plugins/marketplace.ts',
|
|
572
620
|
'plugins/example-analytics',
|
|
573
621
|
],
|
|
574
622
|
label: 'Plugin Marketplace',
|
|
575
623
|
},
|
|
624
|
+
{
|
|
625
|
+
key: 'enableSeo',
|
|
626
|
+
paths: [
|
|
627
|
+
'src/app/robots.ts',
|
|
628
|
+
'src/app/robots.test.ts',
|
|
629
|
+
'src/app/sitemap.ts',
|
|
630
|
+
'src/app/sitemap.test.ts',
|
|
631
|
+
],
|
|
632
|
+
label: 'SEO robots route',
|
|
633
|
+
},
|
|
576
634
|
];
|
|
577
|
-
//
|
|
578
|
-
//
|
|
579
|
-
//
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
635
|
+
// Whitelist CLI options that write runtime feature toggles to the env file.
|
|
636
|
+
// Other enable* options only control code pruning and must not write env flags.
|
|
637
|
+
// Feature keys are resolved to actual env variable names from the project schema below.
|
|
638
|
+
const CONFIG_FEATURE_KEYS = {
|
|
639
|
+
enableApiDocs: 'apiDocs',
|
|
640
|
+
enableDocs: 'docs',
|
|
641
|
+
enableChangelog: 'changelog',
|
|
642
|
+
enableBlog: 'blog',
|
|
643
|
+
enableWaitlist: 'waitlist',
|
|
644
|
+
enableFeatureRequests: 'featureRequests',
|
|
645
|
+
enableCompare: 'compare',
|
|
646
|
+
enableAI: 'ai',
|
|
647
|
+
enableAiChat: 'aiChat',
|
|
648
|
+
enableRAG: 'aiRag',
|
|
649
|
+
enableAgents: 'aiAgents',
|
|
650
|
+
enableBatch: 'aiBatch',
|
|
651
|
+
enablePlayground: 'aiPlayground',
|
|
652
|
+
enableTeams: 'teams',
|
|
653
|
+
enableReferrals: 'referrals',
|
|
654
|
+
enablePromotions: 'promotions',
|
|
655
|
+
enableSeo: 'seo',
|
|
656
|
+
enableGraphQL: 'graphql',
|
|
657
|
+
enableConnect: 'connect',
|
|
658
|
+
enableEventStore: 'eventStore',
|
|
659
|
+
enableOtel: 'otel',
|
|
660
|
+
enableAnalytics: 'analytics',
|
|
661
|
+
enableWorkflows: 'workflows',
|
|
662
|
+
enableExperiments: 'experiments',
|
|
663
|
+
enableDripCampaigns: 'dripCampaigns',
|
|
664
|
+
enableOnboarding: 'onboarding',
|
|
665
|
+
enableWebhooks: 'webhooks',
|
|
666
|
+
enableAuditLog: 'auditLog',
|
|
667
|
+
enableReports: 'reports',
|
|
668
|
+
enableBranding: 'branding',
|
|
669
|
+
enableTwoFactor: 'twoFactor',
|
|
670
|
+
enablePlugins: 'plugins',
|
|
612
671
|
};
|
|
613
|
-
// codapult:prune:start {key}
|
|
672
|
+
// codapult:prune:start {key[,key...]}
|
|
614
673
|
// codapult:prune:replace
|
|
615
|
-
// codapult:prune:end {key}
|
|
674
|
+
// codapult:prune:end {key[,key...]}
|
|
616
675
|
const PRUNE_MARKER_FILES = [
|
|
617
676
|
'src/app/sitemap.ts',
|
|
618
677
|
'src/app/sitemap.test.ts',
|
|
619
678
|
'src/app/(marketing)/llms.txt/route.ts',
|
|
679
|
+
'src/app/(marketing)/llms.txt/route.test.ts',
|
|
620
680
|
'src/app/api/checkout/route.ts',
|
|
681
|
+
'src/app/api/checkout/route.test.ts',
|
|
682
|
+
'src/app/api/auth/sso/callback/route.ts',
|
|
683
|
+
'src/app/api/auth/sso/callback/route.test.ts',
|
|
684
|
+
'src/app/api/webhooks/stripe/route.ts',
|
|
685
|
+
'src/app/api/webhooks/stripe/route.test.ts',
|
|
686
|
+
'src/app/api/webhooks/polar/route.ts',
|
|
687
|
+
'src/app/api/webhooks/lemonsqueezy/route.ts',
|
|
688
|
+
'src/app/api/analytics/route.ts',
|
|
689
|
+
'src/app/api/analytics/route.test.ts',
|
|
690
|
+
'src/app/api/reports/route.ts',
|
|
691
|
+
'src/app/api/ai/chat/route.ts',
|
|
692
|
+
'src/app/api/ai/index/route.ts',
|
|
693
|
+
'src/app/api/ai/search/route.ts',
|
|
694
|
+
'src/components/auth/AuthForm.tsx',
|
|
621
695
|
'src/components/marketing/Footer.tsx',
|
|
696
|
+
'src/components/marketing/landing/PricingSection.tsx',
|
|
697
|
+
'src/components/MdxContent.tsx',
|
|
698
|
+
'src/components/dashboard/sidebar/Sidebar.tsx',
|
|
699
|
+
'src/components/dashboard/sidebar/SidebarContent.tsx',
|
|
700
|
+
'src/components/ai/ChatUI.tsx',
|
|
701
|
+
'src/components/ai/index.ts',
|
|
702
|
+
'src/proxy.ts',
|
|
703
|
+
'src/proxy.test.ts',
|
|
704
|
+
`${APP}/(public)/layout.tsx`,
|
|
705
|
+
`${APP}/(public)/(auth)/layout.tsx`,
|
|
706
|
+
`${APP}/(public)/(auth)/sign-in/page.tsx`,
|
|
707
|
+
`${APP}/(public)/(auth)/sign-up/page.tsx`,
|
|
708
|
+
`${APP}/(public)/(marketing)/page.tsx`,
|
|
709
|
+
`${APP}/(protected)/(dashboard)/layout.tsx`,
|
|
710
|
+
`${APP}/(protected)/(dashboard)/dashboard/analytics/page.tsx`,
|
|
711
|
+
`${APP}/(protected)/(dashboard)/dashboard/billing/page.tsx`,
|
|
712
|
+
`${APP}/(protected)/(dashboard)/dashboard/reports/page.tsx`,
|
|
713
|
+
`${APP}/(protected)/(dashboard)/dashboard/settings/page.tsx`,
|
|
714
|
+
`${APP}/(protected)/(admin)/layout.tsx`,
|
|
715
|
+
'src/lib/validation.ts',
|
|
716
|
+
'src/lib/ai/api.ts',
|
|
717
|
+
'src/lib/ai/api-schemas.ts',
|
|
718
|
+
'src/lib/ai/tools/index.ts',
|
|
719
|
+
'src/lib/ai/tools/manager.ts',
|
|
720
|
+
'src/lib/ai/tools/types.ts',
|
|
721
|
+
'src/hooks/ai/useGateway.ts',
|
|
722
|
+
'src/lib/ai/metering/logger.ts',
|
|
723
|
+
'src/lib/ai/metering/types.ts',
|
|
724
|
+
'src/lib/ai/rag.ts',
|
|
725
|
+
'src/lib/ai/gateway/pipeline.ts',
|
|
726
|
+
'src/lib/ai/tools/executor.ts',
|
|
622
727
|
'src/lib/auth/index.ts',
|
|
623
728
|
'src/lib/auth/client-adapter.ts',
|
|
729
|
+
'src/lib/auth/client-adapter.test.ts',
|
|
730
|
+
'src/lib/auth/adapters/better-auth.ts',
|
|
731
|
+
'src/lib/auth/adapters/better-auth.test.ts',
|
|
732
|
+
'src/lib/auth/adapters/better-auth-client.ts',
|
|
733
|
+
'src/lib/auth/adapters/better-auth-client.test.ts',
|
|
734
|
+
'src/lib/auth/adapters/kinde.ts',
|
|
735
|
+
'src/lib/auth/adapters/kinde.test.ts',
|
|
736
|
+
'src/lib/auth/adapters/kinde-client.ts',
|
|
624
737
|
'src/lib/jobs/definitions.ts',
|
|
738
|
+
'src/lib/jobs/definitions.test.ts',
|
|
625
739
|
'src/lib/actions/admin.ts',
|
|
740
|
+
'src/lib/actions/admin.test.ts',
|
|
741
|
+
'src/lib/actions/billing.ts',
|
|
742
|
+
'src/lib/payments/adapter.ts',
|
|
743
|
+
'src/lib/payments/adapters/stripe.ts',
|
|
744
|
+
'src/lib/payments/adapters/stripe.test.ts',
|
|
745
|
+
'src/lib/payments/adapters/polar.ts',
|
|
746
|
+
'src/lib/payments/adapters/polar.test.ts',
|
|
747
|
+
'src/lib/payments/adapters/lemonsqueezy.ts',
|
|
626
748
|
'src/lib/actions/impersonation.ts',
|
|
749
|
+
'src/lib/actions/impersonation.test.ts',
|
|
627
750
|
'src/lib/scheduled-reports/index.ts',
|
|
628
|
-
'src/lib/
|
|
629
|
-
'src/lib/
|
|
630
|
-
'src/lib/
|
|
751
|
+
'src/lib/gdpr/index.ts',
|
|
752
|
+
'src/lib/gdpr/gdpr.test.ts',
|
|
753
|
+
'src/lib/email/index.ts',
|
|
754
|
+
'src/lib/usage.ts',
|
|
755
|
+
'src/lib/access-control.ts',
|
|
756
|
+
'src/lib/access-control.test.ts',
|
|
757
|
+
'src/lib/db/schema.ts',
|
|
758
|
+
'src/lib/db/schema-pg.ts',
|
|
759
|
+
'src/lib/db/admin.ts',
|
|
760
|
+
'src/lib/onboarding/checks.ts',
|
|
761
|
+
'src/lib/organizations/context.ts',
|
|
762
|
+
'src/config/env.ts',
|
|
763
|
+
'src/config/navigation.ts',
|
|
631
764
|
'src/config/marketing.test.ts',
|
|
632
765
|
'src/config/env-schema.ts',
|
|
633
766
|
'src/instrumentation.ts',
|
|
634
767
|
'src/proxy.ts',
|
|
768
|
+
'src/proxy.test.ts',
|
|
769
|
+
'scripts/seed.ts',
|
|
635
770
|
];
|
|
636
|
-
export function buildEnvContent(content, config) {
|
|
771
|
+
export function buildEnvContent(content, config, root) {
|
|
637
772
|
let result = content;
|
|
638
773
|
const replacements = {
|
|
639
774
|
NEXT_PUBLIC_APP_NAME: config.appName,
|
|
640
775
|
NEXT_PUBLIC_APP_URL: config.appUrl,
|
|
641
776
|
APP_MODE: config.appMode,
|
|
642
777
|
AUTH_PROVIDER: config.authProvider,
|
|
778
|
+
SSO_PROVIDER: config.ssoProvider,
|
|
643
779
|
PAYMENT_PROVIDER: config.paymentProvider,
|
|
644
780
|
STORAGE_PROVIDER: config.storageProvider,
|
|
645
781
|
JOB_PROVIDER: config.jobProvider,
|
|
646
782
|
};
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
783
|
+
const featureEnv = getFeatureEnv(root, { includeAuthMethods: true });
|
|
784
|
+
for (const [cliKey, feature] of Object.entries(CONFIG_FEATURE_KEYS)) {
|
|
785
|
+
const enabled = config[cliKey];
|
|
786
|
+
if (typeof enabled === 'boolean') {
|
|
787
|
+
const envVar = featureEnv[feature];
|
|
788
|
+
if (!envVar)
|
|
789
|
+
continue;
|
|
790
|
+
replacements[envVar] = String(enabled);
|
|
650
791
|
}
|
|
651
792
|
}
|
|
652
793
|
for (const [key, value] of Object.entries(replacements)) {
|
|
@@ -667,7 +808,7 @@ function generateEnvFile(root, config) {
|
|
|
667
808
|
info(`${ENV_FILE_NAME} already exists — creating ${ENV_FILE_NAME}.new instead`);
|
|
668
809
|
}
|
|
669
810
|
const exampleContent = existsSync(envExamplePath) ? readFileSync(envExamplePath, 'utf-8') : '';
|
|
670
|
-
const content = buildEnvContent(exampleContent, config);
|
|
811
|
+
const content = buildEnvContent(exampleContent, config, root);
|
|
671
812
|
const outputPath = existsSync(envLocalPath) ? `${envLocalPath}.new` : envLocalPath;
|
|
672
813
|
writeFileSync(outputPath, content, 'utf-8');
|
|
673
814
|
success(`Written to ${relative(root, outputPath)}`);
|
|
@@ -701,66 +842,106 @@ function generateMcpConfig(root) {
|
|
|
701
842
|
writeFileSync(mcpPath, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
702
843
|
success('Created .cursor/mcp.json — Codapult MCP server configured for Cursor');
|
|
703
844
|
}
|
|
704
|
-
function pruneMarkedBlocks(content, disabledKeys) {
|
|
845
|
+
function pruneMarkedBlocks(content, disabledKeys, cleanMarkers) {
|
|
705
846
|
const keySet = new Set(disabledKeys.map(String));
|
|
706
|
-
const
|
|
707
|
-
const
|
|
708
|
-
const
|
|
709
|
-
const replaceRe = /^[ \t]
|
|
710
|
-
const endRe =
|
|
711
|
-
const
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
847
|
+
const keyList = '([A-Za-z][A-Za-z0-9]*(?:,[A-Za-z][A-Za-z0-9]*)*)';
|
|
848
|
+
const startRe = new RegExp(`^[ \\t]*\\/\\/\\s*codapult:prune:start\\s+${keyList}[ \\t]*$`);
|
|
849
|
+
const jsxStartRe = new RegExp(`^[ \\t]*\\{\\/\\*\\s*codapult:prune:start\\s+${keyList}\\s*\\*\\/\\}[ \\t]*$`);
|
|
850
|
+
const replaceRe = /^[ \t]*(?:\/\/\s*codapult:prune:replace|\{\/\*\s*codapult:prune:replace\s*\*\/\})[ \t]*$/;
|
|
851
|
+
const endRe = new RegExp(`^[ \\t]*.*?\\/\\/\\s*codapult:prune:end\\s+${keyList}[ \\t]*$`);
|
|
852
|
+
const jsxEndRe = new RegExp(`^[ \\t]*\\{\\/\\*\\s*codapult:prune:end\\s+${keyList}\\s*\\*\\/\\}[ \\t]*$`);
|
|
853
|
+
const commentRe = /^([ \t]*)(?:\/\/ ?(.*)|\{\/\*\s?(.*?)\s?\*\/\})$/;
|
|
854
|
+
const parseKeys = (value) => [...new Set(value.split(','))].sort();
|
|
855
|
+
const matchStart = (line) => startRe.exec(line) ?? jsxStartRe.exec(line);
|
|
856
|
+
const matchEnd = (line) => endRe.exec(line) ?? jsxEndRe.exec(line);
|
|
857
|
+
const hasSameKeys = (left, right) => left.length === right.length && left.every((key, index) => key === right[index]);
|
|
858
|
+
const findBlockEnd = (lines, startIndex, rootKeys) => {
|
|
859
|
+
const stack = [rootKeys];
|
|
860
|
+
let replaceIndex;
|
|
861
|
+
for (let i = startIndex + 1; i < lines.length; i += 1) {
|
|
862
|
+
const nestedStart = matchStart(lines[i]);
|
|
863
|
+
if (nestedStart) {
|
|
864
|
+
stack.push(parseKeys(nestedStart[1]));
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
const end = matchEnd(lines[i]);
|
|
868
|
+
if (end && hasSameKeys(parseKeys(end[1]), stack[stack.length - 1])) {
|
|
869
|
+
stack.pop();
|
|
870
|
+
if (stack.length === 0)
|
|
871
|
+
return { endIndex: i, replaceIndex };
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
if (stack.length === 1 && replaceRe.test(lines[i]) && replaceIndex === undefined) {
|
|
875
|
+
replaceIndex = i;
|
|
723
876
|
}
|
|
724
877
|
}
|
|
725
|
-
throw new Error(`Unclosed "codapult:prune:start ${
|
|
878
|
+
throw new Error(`Unclosed "codapult:prune:start ${rootKeys.join(',')}" — no matching end found.`);
|
|
726
879
|
};
|
|
727
|
-
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
const key = start[1];
|
|
735
|
-
const body = seekTo(i + 1, key);
|
|
736
|
-
if (body.kind === 'end') {
|
|
737
|
-
i = body.i; // тело отбрасываем целиком
|
|
738
|
-
continue;
|
|
739
|
-
}
|
|
740
|
-
// body.kind === 'replace': строки от body.i до end — это закомментированный replacement
|
|
741
|
-
const replEnd = seekTo(body.i, key);
|
|
742
|
-
if (replEnd.kind !== 'end') {
|
|
743
|
-
throw new Error(`Expected "end" after "replace" for key "${key}".`);
|
|
744
|
-
}
|
|
745
|
-
for (let r = body.i; r < replEnd.i - 1; r++) {
|
|
746
|
-
const line = lines[r];
|
|
747
|
-
if (line.trim() === '') {
|
|
748
|
-
out.push('');
|
|
880
|
+
const processLines = (lines) => {
|
|
881
|
+
const out = [];
|
|
882
|
+
for (let i = 0; i < lines.length;) {
|
|
883
|
+
const start = matchStart(lines[i]);
|
|
884
|
+
if (!start) {
|
|
885
|
+
out.push(lines[i]);
|
|
886
|
+
i += 1;
|
|
749
887
|
continue;
|
|
750
888
|
}
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
889
|
+
const keys = parseKeys(start[1]);
|
|
890
|
+
const { endIndex, replaceIndex } = findBlockEnd(lines, i, keys);
|
|
891
|
+
const shouldPrune = keys.every((key) => keySet.has(key));
|
|
892
|
+
if (shouldPrune) {
|
|
893
|
+
if (replaceIndex !== undefined) {
|
|
894
|
+
const replacement = [];
|
|
895
|
+
for (let r = replaceIndex + 1; r < endIndex; r += 1) {
|
|
896
|
+
const line = lines[r];
|
|
897
|
+
if (line.trim() === '') {
|
|
898
|
+
replacement.push('');
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
const match = commentRe.exec(line);
|
|
902
|
+
if (!match) {
|
|
903
|
+
throw new Error(`Line ${r + 1} in "replace" section for "${keys.join(',')}" is not commented out: ${JSON.stringify(line)}`);
|
|
904
|
+
}
|
|
905
|
+
replacement.push(match[1] + (match[2] ?? match[3]));
|
|
906
|
+
}
|
|
907
|
+
out.push(...processLines(replacement));
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
else {
|
|
911
|
+
out.push(lines[i]);
|
|
912
|
+
const bodyEnd = replaceIndex ?? endIndex;
|
|
913
|
+
out.push(...processLines(lines.slice(i + 1, bodyEnd)));
|
|
914
|
+
if (replaceIndex !== undefined) {
|
|
915
|
+
out.push(lines[replaceIndex]);
|
|
916
|
+
out.push(...processLines(lines.slice(replaceIndex + 1, endIndex)));
|
|
917
|
+
}
|
|
918
|
+
out.push(lines[endIndex]);
|
|
754
919
|
}
|
|
755
|
-
|
|
920
|
+
i = endIndex + 1;
|
|
756
921
|
}
|
|
757
|
-
|
|
758
|
-
}
|
|
759
|
-
|
|
922
|
+
return out;
|
|
923
|
+
};
|
|
924
|
+
const result = processLines(content.split('\n'));
|
|
925
|
+
return (cleanMarkers
|
|
926
|
+
? result.flatMap((line) => {
|
|
927
|
+
if (endRe.test(line)) {
|
|
928
|
+
const markerIndex = line.indexOf('// codapult:prune:end');
|
|
929
|
+
const prefix = line.slice(0, markerIndex);
|
|
930
|
+
return prefix.trim() ? [prefix.trimEnd()] : [];
|
|
931
|
+
}
|
|
932
|
+
if (startRe.test(line) ||
|
|
933
|
+
jsxStartRe.test(line) ||
|
|
934
|
+
replaceRe.test(line) ||
|
|
935
|
+
jsxEndRe.test(line)) {
|
|
936
|
+
return [];
|
|
937
|
+
}
|
|
938
|
+
return [line];
|
|
939
|
+
})
|
|
940
|
+
: result).join('\n');
|
|
760
941
|
}
|
|
761
|
-
function pruneMarkedBlocksInFiles(root, config) {
|
|
942
|
+
function pruneMarkedBlocksInFiles(root, config, cleanMarkers) {
|
|
762
943
|
const disabledKeys = Object.keys(config).filter((key) => key.startsWith('enable') && config[key] === false);
|
|
763
|
-
if (disabledKeys.length === 0)
|
|
944
|
+
if (disabledKeys.length === 0 && !cleanMarkers)
|
|
764
945
|
return;
|
|
765
946
|
dim(`Pruning files...`);
|
|
766
947
|
for (const relativePath of PRUNE_MARKER_FILES) {
|
|
@@ -768,7 +949,7 @@ function pruneMarkedBlocksInFiles(root, config) {
|
|
|
768
949
|
if (!existsSync(fullPath))
|
|
769
950
|
continue;
|
|
770
951
|
const original = readFileSync(fullPath, 'utf-8');
|
|
771
|
-
const pruned = pruneMarkedBlocks(original, disabledKeys);
|
|
952
|
+
const pruned = pruneMarkedBlocks(original, disabledKeys, cleanMarkers);
|
|
772
953
|
if (pruned !== original) {
|
|
773
954
|
writeFileSync(fullPath, pruned, 'utf-8');
|
|
774
955
|
dim(` patched ${relativePath}`);
|
|
@@ -778,34 +959,47 @@ function pruneMarkedBlocksInFiles(root, config) {
|
|
|
778
959
|
function removeModules(root, config) {
|
|
779
960
|
let totalRemoved = 0;
|
|
780
961
|
for (const removal of MODULE_REMOVALS) {
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
962
|
+
const keys = Array.isArray(removal.key) ? removal.key : [removal.key];
|
|
963
|
+
if (keys.every((key) => !config[key])) {
|
|
964
|
+
dim(`Removing ${removal.label}...`);
|
|
965
|
+
let removed = 0;
|
|
966
|
+
const missing = [];
|
|
967
|
+
for (const p of removal.paths) {
|
|
968
|
+
const fullPath = resolve(root, p);
|
|
969
|
+
if (existsSync(fullPath)) {
|
|
970
|
+
rmSync(fullPath, { recursive: true });
|
|
971
|
+
dim(` deleted ${p}`);
|
|
972
|
+
removed += 1;
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
missing.push(p);
|
|
976
|
+
}
|
|
792
977
|
}
|
|
793
|
-
|
|
794
|
-
|
|
978
|
+
totalRemoved += removed;
|
|
979
|
+
// Surface stale paths so removals don't silently no-op when the host
|
|
980
|
+
// project's file layout changes (e.g. moving routes under [locale]).
|
|
981
|
+
if (removed === 0 && missing.length > 0) {
|
|
982
|
+
dim(` no matching files found (expected ${missing.length} path(s))`);
|
|
795
983
|
}
|
|
796
984
|
}
|
|
797
|
-
totalRemoved += removed;
|
|
798
|
-
// Surface stale paths so removals don't silently no-op when the host
|
|
799
|
-
// project's file layout changes (e.g. moving routes under [locale]).
|
|
800
|
-
if (removed === 0 && missing.length > 0) {
|
|
801
|
-
dim(` no matching files found (expected ${missing.length} path(s))`);
|
|
802
|
-
}
|
|
803
985
|
}
|
|
804
|
-
pruneMarkedBlocksInFiles(root, config);
|
|
805
986
|
if (totalRemoved > 0) {
|
|
806
987
|
dim(`Total removed: ${totalRemoved}`);
|
|
807
988
|
}
|
|
808
989
|
}
|
|
990
|
+
function format(root) {
|
|
991
|
+
const prettierPath = resolve(root, 'node_modules/.bin/prettier');
|
|
992
|
+
if (existsSync(prettierPath)) {
|
|
993
|
+
const formatCode = spawnSync('pnpm', ['exec', 'prettier', '--write', '.', '--log-level', 'warn'], { cwd: root, stdio: 'inherit' }).status;
|
|
994
|
+
if (formatCode === 0)
|
|
995
|
+
dim('Formatted successfully.');
|
|
996
|
+
else
|
|
997
|
+
warn(`Formatting failed (exit ${formatCode}).`);
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
dim('Prettier is unavailable; skipping formatting');
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
809
1003
|
async function interactiveSetup() {
|
|
810
1004
|
const iface = createInterface({ input: process.stdin, output: process.stdout });
|
|
811
1005
|
heading('Codapult Setup');
|
|
@@ -823,7 +1017,7 @@ async function interactiveSetup() {
|
|
|
823
1017
|
const config = {
|
|
824
1018
|
appName,
|
|
825
1019
|
appUrl,
|
|
826
|
-
appMode: '
|
|
1020
|
+
appMode: 'full',
|
|
827
1021
|
authProvider,
|
|
828
1022
|
ssoProvider,
|
|
829
1023
|
paymentProvider: await selectPrompt(iface, 'Payment provider:', ['stripe', 'lemonsqueezy', 'polar']),
|
|
@@ -846,7 +1040,7 @@ async function interactiveSetup() {
|
|
|
846
1040
|
enableWaitlist: await confirm(iface, 'Enable Waitlist page?'),
|
|
847
1041
|
enableGraphQL: await confirm(iface, 'Enable GraphQL API layer?'),
|
|
848
1042
|
enableApiDocs: await confirm(iface, 'Enable interactive API docs?'),
|
|
849
|
-
|
|
1043
|
+
enableDocs: await confirm(iface, 'Enable Documentation module?'),
|
|
850
1044
|
enableExperiments: await confirm(iface, 'Enable A/B Testing?'),
|
|
851
1045
|
enableFeatureRequests: await confirm(iface, 'Enable Feature Request board?'),
|
|
852
1046
|
enableCompare: await confirm(iface, 'Enable competitor comparison pages (/compare)?', false),
|
|
@@ -865,8 +1059,15 @@ async function interactiveSetup() {
|
|
|
865
1059
|
enableBranding: authEnabled && (await confirm(iface, 'Enable per-org branding (white-label)?')),
|
|
866
1060
|
enableTwoFactor: authEnabled && (await confirm(iface, 'Enable two-factor authentication (TOTP)?')),
|
|
867
1061
|
enablePlugins: await confirm(iface, 'Enable plugin marketplace (/dashboard/plugins)?'),
|
|
1062
|
+
enablePromotions: await confirm(iface, 'Enable promotion codes and pricing overrides?', true),
|
|
1063
|
+
enableSeo: await confirm(iface, 'Enable SEO robots directives?', true),
|
|
868
1064
|
removeUnusedCode: emptyLine() && (await confirm(iface, 'Remove unused module code?', false)),
|
|
1065
|
+
cleanPruneMarkers: await confirm(iface, 'Remove prune markers from code?', true),
|
|
869
1066
|
};
|
|
1067
|
+
if (!config.enableTeams && config.enableBranding) {
|
|
1068
|
+
info('Per-org branding and custom domains require Teams; disabling them.');
|
|
1069
|
+
config.enableBranding = false;
|
|
1070
|
+
}
|
|
870
1071
|
iface.close();
|
|
871
1072
|
return config;
|
|
872
1073
|
}
|
|
@@ -876,7 +1077,7 @@ export async function setupCommand(options) {
|
|
|
876
1077
|
let config;
|
|
877
1078
|
if (presetRaw) {
|
|
878
1079
|
heading('Codapult Setup (preset mode)');
|
|
879
|
-
info(`Applying preset: ${presetRaw}
|
|
1080
|
+
info(`Applying preset: ${presetRaw}`);
|
|
880
1081
|
config = resolvePreset(presetRaw);
|
|
881
1082
|
}
|
|
882
1083
|
else {
|
|
@@ -893,6 +1094,11 @@ export async function setupCommand(options) {
|
|
|
893
1094
|
heading('Removing unused modules');
|
|
894
1095
|
removeModules(root, config);
|
|
895
1096
|
}
|
|
1097
|
+
if (config.removeUnusedCode || config.cleanPruneMarkers) {
|
|
1098
|
+
pruneMarkedBlocksInFiles(root, config, config.cleanPruneMarkers);
|
|
1099
|
+
heading('Formatting after removing unused code');
|
|
1100
|
+
format(root);
|
|
1101
|
+
}
|
|
896
1102
|
heading('Setting up MCP integration');
|
|
897
1103
|
generateMcpConfig(root);
|
|
898
1104
|
heading('Done!');
|