@codebakers/cli 2.7.0 → 2.9.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/push-patterns.d.ts +15 -0
- package/dist/commands/push-patterns.js +186 -0
- package/dist/commands/setup.js +13 -2
- package/dist/index.js +23 -1
- package/dist/lib/progress.d.ts +42 -0
- package/dist/lib/progress.js +160 -0
- package/dist/mcp/server.js +294 -10
- package/package.json +1 -1
- package/src/commands/push-patterns.ts +222 -0
- package/src/commands/setup.ts +11 -2
- package/src/index.ts +23 -1
- package/src/lib/progress.ts +192 -0
- package/src/mcp/server.ts +312 -12
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora, { Ora } from 'ora';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Multi-step progress tracker for CLI operations
|
|
6
|
+
*/
|
|
7
|
+
export interface Step {
|
|
8
|
+
name: string;
|
|
9
|
+
action: () => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class ProgressTracker {
|
|
13
|
+
private currentStep = 0;
|
|
14
|
+
private totalSteps: number;
|
|
15
|
+
private steps: Step[];
|
|
16
|
+
private spinner: Ora | null = null;
|
|
17
|
+
|
|
18
|
+
constructor(steps: Step[]) {
|
|
19
|
+
this.steps = steps;
|
|
20
|
+
this.totalSteps = steps.length;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async run(): Promise<void> {
|
|
24
|
+
for (let i = 0; i < this.steps.length; i++) {
|
|
25
|
+
this.currentStep = i + 1;
|
|
26
|
+
const step = this.steps[i];
|
|
27
|
+
|
|
28
|
+
this.spinner = ora({
|
|
29
|
+
text: this.formatStepText(step.name),
|
|
30
|
+
prefixText: this.formatPrefix(),
|
|
31
|
+
}).start();
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
await step.action();
|
|
35
|
+
this.spinner.succeed(this.formatStepText(step.name));
|
|
36
|
+
} catch (error) {
|
|
37
|
+
this.spinner.fail(this.formatStepText(step.name));
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private formatPrefix(): string {
|
|
44
|
+
return chalk.gray(` [${this.currentStep}/${this.totalSteps}]`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private formatStepText(text: string): string {
|
|
48
|
+
return text;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Show a success box after completing a command
|
|
54
|
+
*/
|
|
55
|
+
export function showSuccessBox(title: string, lines: string[]): void {
|
|
56
|
+
const maxLength = Math.max(title.length, ...lines.map(l => l.length)) + 4;
|
|
57
|
+
const border = '═'.repeat(maxLength);
|
|
58
|
+
|
|
59
|
+
console.log(chalk.green(`\n ╔${border}╗`));
|
|
60
|
+
console.log(chalk.green(` ║`) + chalk.bold.white(` ${title.padEnd(maxLength - 2)} `) + chalk.green(`║`));
|
|
61
|
+
console.log(chalk.green(` ╠${border}╣`));
|
|
62
|
+
|
|
63
|
+
for (const line of lines) {
|
|
64
|
+
console.log(chalk.green(` ║`) + chalk.white(` ${line.padEnd(maxLength - 2)} `) + chalk.green(`║`));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(chalk.green(` ╚${border}╝\n`));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Display a quick start guide with examples
|
|
72
|
+
*/
|
|
73
|
+
export function showQuickStartGuide(): void {
|
|
74
|
+
console.log(chalk.blue('\n ═══════════════════════════════════════════════════════════'));
|
|
75
|
+
console.log(chalk.bold.white('\n 📚 Quick Start Guide\n'));
|
|
76
|
+
console.log(chalk.blue(' ═══════════════════════════════════════════════════════════\n'));
|
|
77
|
+
|
|
78
|
+
console.log(chalk.white(' Just ask the AI in natural language:\n'));
|
|
79
|
+
|
|
80
|
+
const examples = [
|
|
81
|
+
{
|
|
82
|
+
prompt: '"Build me a user dashboard with stats cards"',
|
|
83
|
+
desc: 'AI will use CodeBakers patterns for layout, components, and data fetching',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
prompt: '"Add Stripe subscription to my app"',
|
|
87
|
+
desc: 'AI loads payment patterns: checkout, webhooks, customer portal',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
prompt: '"Create an API endpoint for user profiles"',
|
|
91
|
+
desc: 'AI generates: route handler, validation, error handling, types',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
prompt: '"Set up auth with Google and email login"',
|
|
95
|
+
desc: 'AI implements OAuth + email auth following security patterns',
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
for (const example of examples) {
|
|
100
|
+
console.log(chalk.cyan(` → ${example.prompt}`));
|
|
101
|
+
console.log(chalk.gray(` ${example.desc}\n`));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(chalk.blue(' ───────────────────────────────────────────────────────────\n'));
|
|
105
|
+
|
|
106
|
+
console.log(chalk.white(' Pro Tips:\n'));
|
|
107
|
+
console.log(chalk.gray(' • Ask the AI ') + chalk.cyan('"What patterns do you have for payments?"'));
|
|
108
|
+
console.log(chalk.gray(' • Say ') + chalk.cyan('"/build a SaaS app"') + chalk.gray(' to start a full project'));
|
|
109
|
+
console.log(chalk.gray(' • Try ') + chalk.cyan('"/audit"') + chalk.gray(' to check code quality'));
|
|
110
|
+
console.log(chalk.gray(' • Use ') + chalk.cyan('"codebakers doctor"') + chalk.gray(' if something seems wrong\n'));
|
|
111
|
+
|
|
112
|
+
console.log(chalk.blue(' ═══════════════════════════════════════════════════════════\n'));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Format user-friendly error with context and recovery steps
|
|
117
|
+
*/
|
|
118
|
+
export interface FriendlyError {
|
|
119
|
+
title: string;
|
|
120
|
+
message: string;
|
|
121
|
+
cause?: string;
|
|
122
|
+
recovery: string[];
|
|
123
|
+
helpUrl?: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function formatFriendlyError(error: FriendlyError): string {
|
|
127
|
+
let output = '';
|
|
128
|
+
|
|
129
|
+
output += chalk.red(`\n ❌ ${error.title}\n`);
|
|
130
|
+
output += chalk.white(`\n ${error.message}\n`);
|
|
131
|
+
|
|
132
|
+
if (error.cause) {
|
|
133
|
+
output += chalk.gray(`\n Why: ${error.cause}\n`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (error.recovery.length > 0) {
|
|
137
|
+
output += chalk.yellow(`\n How to fix:\n`);
|
|
138
|
+
for (let i = 0; i < error.recovery.length; i++) {
|
|
139
|
+
output += chalk.white(` ${i + 1}. ${error.recovery[i]}\n`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (error.helpUrl) {
|
|
144
|
+
output += chalk.gray(`\n More help: ${error.helpUrl}\n`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return output;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Common error handlers with friendly messages
|
|
152
|
+
*/
|
|
153
|
+
export function getNetworkError(): FriendlyError {
|
|
154
|
+
return {
|
|
155
|
+
title: 'Connection Failed',
|
|
156
|
+
message: 'Could not connect to CodeBakers servers.',
|
|
157
|
+
cause: 'This usually means a network issue or the server is temporarily unavailable.',
|
|
158
|
+
recovery: [
|
|
159
|
+
'Check your internet connection',
|
|
160
|
+
'Try again in a few seconds',
|
|
161
|
+
'If using a VPN, try disabling it temporarily',
|
|
162
|
+
'Check status.codebakers.ai for server status',
|
|
163
|
+
],
|
|
164
|
+
helpUrl: 'https://codebakers.ai/docs/troubleshooting',
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function getAuthError(): FriendlyError {
|
|
169
|
+
return {
|
|
170
|
+
title: 'Authentication Failed',
|
|
171
|
+
message: 'Your API key is invalid or expired.',
|
|
172
|
+
recovery: [
|
|
173
|
+
'Go to codebakers.ai/dashboard',
|
|
174
|
+
'Copy your API key (starts with cb_)',
|
|
175
|
+
'Run: codebakers setup',
|
|
176
|
+
],
|
|
177
|
+
helpUrl: 'https://codebakers.ai/docs/getting-started',
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function getSubscriptionError(): FriendlyError {
|
|
182
|
+
return {
|
|
183
|
+
title: 'Subscription Required',
|
|
184
|
+
message: 'This feature requires an active subscription.',
|
|
185
|
+
recovery: [
|
|
186
|
+
'Visit codebakers.ai/pricing to see plans',
|
|
187
|
+
'Start a free trial with: codebakers setup',
|
|
188
|
+
'Contact support if you believe this is an error',
|
|
189
|
+
],
|
|
190
|
+
helpUrl: 'https://codebakers.ai/pricing',
|
|
191
|
+
};
|
|
192
|
+
}
|
package/src/mcp/server.ts
CHANGED
|
@@ -566,7 +566,7 @@ class CodeBakersServer {
|
|
|
566
566
|
{
|
|
567
567
|
name: 'scaffold_project',
|
|
568
568
|
description:
|
|
569
|
-
'Create a new project from scratch with Next.js + Supabase + Drizzle. Use this when user wants to build something new and no project exists yet. Creates all files, installs dependencies, and sets up CodeBakers patterns automatically.',
|
|
569
|
+
'Create a new project from scratch with Next.js + Supabase + Drizzle. Use this when user wants to build something new and no project exists yet. Creates all files, installs dependencies, and sets up CodeBakers patterns automatically. Set fullDeploy=true for seamless idea-to-deployment (creates GitHub repo, Supabase project, and deploys to Vercel). When fullDeploy=true, first call returns explanation - then call again with deployConfirmed=true after user confirms.',
|
|
570
570
|
inputSchema: {
|
|
571
571
|
type: 'object' as const,
|
|
572
572
|
properties: {
|
|
@@ -578,6 +578,14 @@ class CodeBakersServer {
|
|
|
578
578
|
type: 'string',
|
|
579
579
|
description: 'Brief description of what the project is for (used in PRD.md)',
|
|
580
580
|
},
|
|
581
|
+
fullDeploy: {
|
|
582
|
+
type: 'boolean',
|
|
583
|
+
description: 'If true, enables full deployment flow (GitHub + Supabase + Vercel). First call returns explanation for user confirmation.',
|
|
584
|
+
},
|
|
585
|
+
deployConfirmed: {
|
|
586
|
+
type: 'boolean',
|
|
587
|
+
description: 'Set to true AFTER user confirms they want full deployment. Only set this after showing user the explanation and getting their approval.',
|
|
588
|
+
},
|
|
581
589
|
},
|
|
582
590
|
required: ['projectName'],
|
|
583
591
|
},
|
|
@@ -900,7 +908,7 @@ class CodeBakersServer {
|
|
|
900
908
|
return this.handleGetPatternSection(args as { pattern: string; section: string });
|
|
901
909
|
|
|
902
910
|
case 'scaffold_project':
|
|
903
|
-
return this.handleScaffoldProject(args as { projectName: string; description?: string });
|
|
911
|
+
return this.handleScaffoldProject(args as { projectName: string; description?: string; fullDeploy?: boolean; deployConfirmed?: boolean });
|
|
904
912
|
|
|
905
913
|
case 'init_project':
|
|
906
914
|
return this.handleInitProject(args as { projectName?: string });
|
|
@@ -1376,10 +1384,15 @@ Show the user what their simple request was expanded into, then proceed with the
|
|
|
1376
1384
|
};
|
|
1377
1385
|
}
|
|
1378
1386
|
|
|
1379
|
-
private async handleScaffoldProject(args: { projectName: string; description?: string }) {
|
|
1380
|
-
const { projectName, description } = args;
|
|
1387
|
+
private async handleScaffoldProject(args: { projectName: string; description?: string; fullDeploy?: boolean; deployConfirmed?: boolean }) {
|
|
1388
|
+
const { projectName, description, fullDeploy, deployConfirmed } = args;
|
|
1381
1389
|
const cwd = process.cwd();
|
|
1382
1390
|
|
|
1391
|
+
// If fullDeploy requested but not confirmed, show explanation and ask for confirmation
|
|
1392
|
+
if (fullDeploy && !deployConfirmed) {
|
|
1393
|
+
return this.showFullDeployExplanation(projectName, description);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1383
1396
|
// Check if directory has files
|
|
1384
1397
|
const files = fs.readdirSync(cwd);
|
|
1385
1398
|
const hasFiles = files.filter(f => !f.startsWith('.')).length > 0;
|
|
@@ -1533,14 +1546,22 @@ phase: setup
|
|
|
1533
1546
|
|
|
1534
1547
|
results.push('\n---\n');
|
|
1535
1548
|
results.push('## ✅ Project Created Successfully!\n');
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1549
|
+
|
|
1550
|
+
// If fullDeploy is enabled and confirmed, proceed with cloud deployment
|
|
1551
|
+
if (fullDeploy && deployConfirmed) {
|
|
1552
|
+
results.push('## 🚀 Starting Full Deployment...\n');
|
|
1553
|
+
const deployResults = await this.executeFullDeploy(projectName, cwd, description);
|
|
1554
|
+
results.push(...deployResults);
|
|
1555
|
+
} else {
|
|
1556
|
+
results.push('### Next Steps:\n');
|
|
1557
|
+
results.push('1. **Set up Supabase:** Go to https://supabase.com and create a free project');
|
|
1558
|
+
results.push('2. **Add credentials:** Copy your Supabase URL and anon key to `.env.local`');
|
|
1559
|
+
results.push('3. **Start building:** Just tell me what features you want!\n');
|
|
1560
|
+
results.push('### Example:\n');
|
|
1561
|
+
results.push('> "Add user authentication with email/password"');
|
|
1562
|
+
results.push('> "Create a dashboard with stats cards"');
|
|
1563
|
+
results.push('> "Build a todo list with CRUD operations"');
|
|
1564
|
+
}
|
|
1544
1565
|
|
|
1545
1566
|
} catch (error) {
|
|
1546
1567
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
@@ -1555,6 +1576,285 @@ phase: setup
|
|
|
1555
1576
|
};
|
|
1556
1577
|
}
|
|
1557
1578
|
|
|
1579
|
+
/**
|
|
1580
|
+
* Show explanation of what fullDeploy will do and ask for confirmation
|
|
1581
|
+
*/
|
|
1582
|
+
private showFullDeployExplanation(projectName: string, description?: string) {
|
|
1583
|
+
const explanation = `# 🚀 Full Deployment: ${projectName}
|
|
1584
|
+
|
|
1585
|
+
## What This Will Do
|
|
1586
|
+
|
|
1587
|
+
Full deployment creates a complete production-ready environment automatically:
|
|
1588
|
+
|
|
1589
|
+
### 1. 📁 Local Project
|
|
1590
|
+
- Create Next.js + Supabase + Drizzle project
|
|
1591
|
+
- Install all dependencies
|
|
1592
|
+
- Set up CodeBakers patterns
|
|
1593
|
+
|
|
1594
|
+
### 2. 🐙 GitHub Repository
|
|
1595
|
+
- Create a new private repository: \`${projectName}\`
|
|
1596
|
+
- Initialize git and push code
|
|
1597
|
+
- Set up .gitignore properly
|
|
1598
|
+
|
|
1599
|
+
### 3. 🗄️ Supabase Project
|
|
1600
|
+
- Create a new Supabase project
|
|
1601
|
+
- Get database connection string
|
|
1602
|
+
- Get API keys (anon + service role)
|
|
1603
|
+
- Auto-configure .env.local
|
|
1604
|
+
|
|
1605
|
+
### 4. 🔺 Vercel Deployment
|
|
1606
|
+
- Deploy to Vercel
|
|
1607
|
+
- Connect to GitHub for auto-deploys
|
|
1608
|
+
- Set all environment variables
|
|
1609
|
+
- Get your live URL
|
|
1610
|
+
|
|
1611
|
+
---
|
|
1612
|
+
|
|
1613
|
+
## Requirements
|
|
1614
|
+
|
|
1615
|
+
Make sure you have these CLIs installed and authenticated:
|
|
1616
|
+
- \`gh\` - GitHub CLI (run: \`gh auth login\`)
|
|
1617
|
+
- \`supabase\` - Supabase CLI (run: \`supabase login\`)
|
|
1618
|
+
- \`vercel\` - Vercel CLI (run: \`vercel login\`)
|
|
1619
|
+
|
|
1620
|
+
---
|
|
1621
|
+
|
|
1622
|
+
## 🎯 Result
|
|
1623
|
+
|
|
1624
|
+
After completion, you'll have:
|
|
1625
|
+
- ✅ GitHub repo with your code
|
|
1626
|
+
- ✅ Supabase project with database ready
|
|
1627
|
+
- ✅ Live URL on Vercel
|
|
1628
|
+
- ✅ Auto-deploys on every push
|
|
1629
|
+
|
|
1630
|
+
---
|
|
1631
|
+
|
|
1632
|
+
**⚠️ IMPORTANT: Ask the user to confirm before proceeding.**
|
|
1633
|
+
|
|
1634
|
+
To proceed, call \`scaffold_project\` again with:
|
|
1635
|
+
\`\`\`json
|
|
1636
|
+
{
|
|
1637
|
+
"projectName": "${projectName}",
|
|
1638
|
+
"description": "${description || ''}",
|
|
1639
|
+
"fullDeploy": true,
|
|
1640
|
+
"deployConfirmed": true
|
|
1641
|
+
}
|
|
1642
|
+
\`\`\`
|
|
1643
|
+
|
|
1644
|
+
Or if user declines, call without fullDeploy:
|
|
1645
|
+
\`\`\`json
|
|
1646
|
+
{
|
|
1647
|
+
"projectName": "${projectName}",
|
|
1648
|
+
"description": "${description || ''}"
|
|
1649
|
+
}
|
|
1650
|
+
\`\`\`
|
|
1651
|
+
`;
|
|
1652
|
+
|
|
1653
|
+
return {
|
|
1654
|
+
content: [{
|
|
1655
|
+
type: 'text' as const,
|
|
1656
|
+
text: explanation,
|
|
1657
|
+
}],
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
/**
|
|
1662
|
+
* Execute full cloud deployment (GitHub + Supabase + Vercel)
|
|
1663
|
+
*/
|
|
1664
|
+
private async executeFullDeploy(projectName: string, cwd: string, description?: string): Promise<string[]> {
|
|
1665
|
+
const results: string[] = [];
|
|
1666
|
+
|
|
1667
|
+
// Check for required CLIs
|
|
1668
|
+
const cliChecks = this.checkRequiredCLIs();
|
|
1669
|
+
if (cliChecks.missing.length > 0) {
|
|
1670
|
+
results.push('### ❌ Missing Required CLIs\n');
|
|
1671
|
+
results.push('The following CLIs are required for full deployment:\n');
|
|
1672
|
+
for (const cli of cliChecks.missing) {
|
|
1673
|
+
results.push(`- **${cli.name}**: ${cli.installCmd}`);
|
|
1674
|
+
}
|
|
1675
|
+
results.push('\nInstall the missing CLIs and try again.');
|
|
1676
|
+
return results;
|
|
1677
|
+
}
|
|
1678
|
+
results.push('✓ All required CLIs found\n');
|
|
1679
|
+
|
|
1680
|
+
// Step 1: Initialize Git and create GitHub repo
|
|
1681
|
+
results.push('### Step 1: GitHub Repository\n');
|
|
1682
|
+
try {
|
|
1683
|
+
// Initialize git
|
|
1684
|
+
execSync('git init', { cwd, stdio: 'pipe' });
|
|
1685
|
+
execSync('git add .', { cwd, stdio: 'pipe' });
|
|
1686
|
+
execSync('git commit -m "Initial commit from CodeBakers"', { cwd, stdio: 'pipe' });
|
|
1687
|
+
results.push('✓ Initialized git repository');
|
|
1688
|
+
|
|
1689
|
+
// Create GitHub repo
|
|
1690
|
+
const ghDescription = description || `${projectName} - Created with CodeBakers`;
|
|
1691
|
+
execSync(`gh repo create ${projectName} --private --source=. --push --description "${ghDescription}"`, { cwd, stdio: 'pipe' });
|
|
1692
|
+
results.push(`✓ Created GitHub repo: ${projectName}`);
|
|
1693
|
+
results.push(` → https://github.com/${this.getGitHubUsername()}/${projectName}\n`);
|
|
1694
|
+
} catch (error) {
|
|
1695
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
1696
|
+
results.push(`⚠️ GitHub setup failed: ${msg}`);
|
|
1697
|
+
results.push(' You can create the repo manually: gh repo create\n');
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
// Step 2: Create Supabase project
|
|
1701
|
+
results.push('### Step 2: Supabase Project\n');
|
|
1702
|
+
try {
|
|
1703
|
+
// Create Supabase project (this may take a while)
|
|
1704
|
+
const orgId = this.getSupabaseOrgId();
|
|
1705
|
+
if (orgId) {
|
|
1706
|
+
execSync(`supabase projects create ${projectName} --org-id ${orgId} --region us-east-1 --db-password "${this.generatePassword()}"`, { cwd, stdio: 'pipe', timeout: 120000 });
|
|
1707
|
+
results.push(`✓ Created Supabase project: ${projectName}`);
|
|
1708
|
+
|
|
1709
|
+
// Get project credentials
|
|
1710
|
+
const projectsOutput = execSync('supabase projects list --output json', { cwd, encoding: 'utf-8' });
|
|
1711
|
+
const projects = JSON.parse(projectsOutput);
|
|
1712
|
+
const newProject = projects.find((p: { name: string }) => p.name === projectName);
|
|
1713
|
+
|
|
1714
|
+
if (newProject) {
|
|
1715
|
+
// Update .env.local with Supabase credentials
|
|
1716
|
+
const envPath = path.join(cwd, '.env.local');
|
|
1717
|
+
let envContent = fs.readFileSync(envPath, 'utf-8');
|
|
1718
|
+
envContent = envContent.replace('your-supabase-url', `https://${newProject.id}.supabase.co`);
|
|
1719
|
+
envContent = envContent.replace('your-anon-key', newProject.anon_key || 'YOUR_ANON_KEY');
|
|
1720
|
+
fs.writeFileSync(envPath, envContent);
|
|
1721
|
+
results.push('✓ Updated .env.local with Supabase credentials\n');
|
|
1722
|
+
}
|
|
1723
|
+
} else {
|
|
1724
|
+
results.push('⚠️ Could not detect Supabase organization');
|
|
1725
|
+
results.push(' Run: supabase orgs list\n');
|
|
1726
|
+
}
|
|
1727
|
+
} catch (error) {
|
|
1728
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
1729
|
+
results.push(`⚠️ Supabase setup failed: ${msg}`);
|
|
1730
|
+
results.push(' Create project manually at: https://supabase.com/dashboard\n');
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
// Step 3: Deploy to Vercel
|
|
1734
|
+
results.push('### Step 3: Vercel Deployment\n');
|
|
1735
|
+
try {
|
|
1736
|
+
// Link to Vercel (creates new project)
|
|
1737
|
+
execSync('vercel link --yes', { cwd, stdio: 'pipe' });
|
|
1738
|
+
results.push('✓ Linked to Vercel');
|
|
1739
|
+
|
|
1740
|
+
// Set environment variables from .env.local
|
|
1741
|
+
const envPath = path.join(cwd, '.env.local');
|
|
1742
|
+
if (fs.existsSync(envPath)) {
|
|
1743
|
+
const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
1744
|
+
const envVars = envContent.split('\n')
|
|
1745
|
+
.filter(line => line.includes('=') && !line.startsWith('#'))
|
|
1746
|
+
.map(line => {
|
|
1747
|
+
const [key, ...valueParts] = line.split('=');
|
|
1748
|
+
return { key: key.trim(), value: valueParts.join('=').trim() };
|
|
1749
|
+
});
|
|
1750
|
+
|
|
1751
|
+
for (const { key, value } of envVars) {
|
|
1752
|
+
if (value && !value.includes('your-')) {
|
|
1753
|
+
try {
|
|
1754
|
+
execSync(`vercel env add ${key} production <<< "${value}"`, { cwd, stdio: 'pipe', shell: 'bash' });
|
|
1755
|
+
} catch {
|
|
1756
|
+
// Env var might already exist, try to update
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
results.push('✓ Set environment variables');
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
// Deploy to production
|
|
1764
|
+
const deployOutput = execSync('vercel --prod --yes', { cwd, encoding: 'utf-8' });
|
|
1765
|
+
const urlMatch = deployOutput.match(/https:\/\/[^\s]+\.vercel\.app/);
|
|
1766
|
+
const deployUrl = urlMatch ? urlMatch[0] : 'Check Vercel dashboard';
|
|
1767
|
+
results.push(`✓ Deployed to Vercel`);
|
|
1768
|
+
results.push(` → ${deployUrl}\n`);
|
|
1769
|
+
|
|
1770
|
+
// Connect to GitHub for auto-deploys
|
|
1771
|
+
try {
|
|
1772
|
+
execSync('vercel git connect --yes', { cwd, stdio: 'pipe' });
|
|
1773
|
+
results.push('✓ Connected to GitHub for auto-deploys\n');
|
|
1774
|
+
} catch {
|
|
1775
|
+
results.push('⚠️ Could not auto-connect to GitHub\n');
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
} catch (error) {
|
|
1779
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
1780
|
+
results.push(`⚠️ Vercel deployment failed: ${msg}`);
|
|
1781
|
+
results.push(' Deploy manually: vercel --prod\n');
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
// Summary
|
|
1785
|
+
results.push('---\n');
|
|
1786
|
+
results.push('## 🎉 Full Deployment Complete!\n');
|
|
1787
|
+
results.push('Your project is now live with:');
|
|
1788
|
+
results.push('- GitHub repo with CI/CD ready');
|
|
1789
|
+
results.push('- Supabase database configured');
|
|
1790
|
+
results.push('- Vercel hosting with auto-deploys\n');
|
|
1791
|
+
results.push('**Start building features - every push auto-deploys!**');
|
|
1792
|
+
|
|
1793
|
+
return results;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
/**
|
|
1797
|
+
* Check if required CLIs are installed
|
|
1798
|
+
*/
|
|
1799
|
+
private checkRequiredCLIs(): { installed: string[]; missing: { name: string; installCmd: string }[] } {
|
|
1800
|
+
const clis = [
|
|
1801
|
+
{ name: 'gh', cmd: 'gh --version', installCmd: 'npm install -g gh' },
|
|
1802
|
+
{ name: 'supabase', cmd: 'supabase --version', installCmd: 'npm install -g supabase' },
|
|
1803
|
+
{ name: 'vercel', cmd: 'vercel --version', installCmd: 'npm install -g vercel' },
|
|
1804
|
+
];
|
|
1805
|
+
|
|
1806
|
+
const installed: string[] = [];
|
|
1807
|
+
const missing: { name: string; installCmd: string }[] = [];
|
|
1808
|
+
|
|
1809
|
+
for (const cli of clis) {
|
|
1810
|
+
try {
|
|
1811
|
+
execSync(cli.cmd, { stdio: 'pipe' });
|
|
1812
|
+
installed.push(cli.name);
|
|
1813
|
+
} catch {
|
|
1814
|
+
missing.push({ name: cli.name, installCmd: cli.installCmd });
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
return { installed, missing };
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
/**
|
|
1822
|
+
* Get GitHub username from gh CLI
|
|
1823
|
+
*/
|
|
1824
|
+
private getGitHubUsername(): string {
|
|
1825
|
+
try {
|
|
1826
|
+
const output = execSync('gh api user --jq .login', { encoding: 'utf-8' });
|
|
1827
|
+
return output.trim();
|
|
1828
|
+
} catch {
|
|
1829
|
+
return 'YOUR_USERNAME';
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
/**
|
|
1834
|
+
* Get Supabase organization ID
|
|
1835
|
+
*/
|
|
1836
|
+
private getSupabaseOrgId(): string | null {
|
|
1837
|
+
try {
|
|
1838
|
+
const output = execSync('supabase orgs list --output json', { encoding: 'utf-8' });
|
|
1839
|
+
const orgs = JSON.parse(output);
|
|
1840
|
+
return orgs[0]?.id || null;
|
|
1841
|
+
} catch {
|
|
1842
|
+
return null;
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
/**
|
|
1847
|
+
* Generate a secure random password for Supabase
|
|
1848
|
+
*/
|
|
1849
|
+
private generatePassword(): string {
|
|
1850
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
1851
|
+
let password = '';
|
|
1852
|
+
for (let i = 0; i < 24; i++) {
|
|
1853
|
+
password += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
1854
|
+
}
|
|
1855
|
+
return password;
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1558
1858
|
private async handleInitProject(args: { projectName?: string }) {
|
|
1559
1859
|
const cwd = process.cwd();
|
|
1560
1860
|
const results: string[] = [];
|