@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
package/dist/mcp/server.js
CHANGED
|
@@ -509,7 +509,7 @@ class CodeBakersServer {
|
|
|
509
509
|
},
|
|
510
510
|
{
|
|
511
511
|
name: 'scaffold_project',
|
|
512
|
-
description: '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.',
|
|
512
|
+
description: '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.',
|
|
513
513
|
inputSchema: {
|
|
514
514
|
type: 'object',
|
|
515
515
|
properties: {
|
|
@@ -521,6 +521,14 @@ class CodeBakersServer {
|
|
|
521
521
|
type: 'string',
|
|
522
522
|
description: 'Brief description of what the project is for (used in PRD.md)',
|
|
523
523
|
},
|
|
524
|
+
fullDeploy: {
|
|
525
|
+
type: 'boolean',
|
|
526
|
+
description: 'If true, enables full deployment flow (GitHub + Supabase + Vercel). First call returns explanation for user confirmation.',
|
|
527
|
+
},
|
|
528
|
+
deployConfirmed: {
|
|
529
|
+
type: 'boolean',
|
|
530
|
+
description: 'Set to true AFTER user confirms they want full deployment. Only set this after showing user the explanation and getting their approval.',
|
|
531
|
+
},
|
|
524
532
|
},
|
|
525
533
|
required: ['projectName'],
|
|
526
534
|
},
|
|
@@ -1204,8 +1212,12 @@ Show the user what their simple request was expanded into, then proceed with the
|
|
|
1204
1212
|
};
|
|
1205
1213
|
}
|
|
1206
1214
|
async handleScaffoldProject(args) {
|
|
1207
|
-
const { projectName, description } = args;
|
|
1215
|
+
const { projectName, description, fullDeploy, deployConfirmed } = args;
|
|
1208
1216
|
const cwd = process.cwd();
|
|
1217
|
+
// If fullDeploy requested but not confirmed, show explanation and ask for confirmation
|
|
1218
|
+
if (fullDeploy && !deployConfirmed) {
|
|
1219
|
+
return this.showFullDeployExplanation(projectName, description);
|
|
1220
|
+
}
|
|
1209
1221
|
// Check if directory has files
|
|
1210
1222
|
const files = fs.readdirSync(cwd);
|
|
1211
1223
|
const hasFiles = files.filter(f => !f.startsWith('.')).length > 0;
|
|
@@ -1344,14 +1356,22 @@ phase: setup
|
|
|
1344
1356
|
}
|
|
1345
1357
|
results.push('\n---\n');
|
|
1346
1358
|
results.push('## ✅ Project Created Successfully!\n');
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1359
|
+
// If fullDeploy is enabled and confirmed, proceed with cloud deployment
|
|
1360
|
+
if (fullDeploy && deployConfirmed) {
|
|
1361
|
+
results.push('## 🚀 Starting Full Deployment...\n');
|
|
1362
|
+
const deployResults = await this.executeFullDeploy(projectName, cwd, description);
|
|
1363
|
+
results.push(...deployResults);
|
|
1364
|
+
}
|
|
1365
|
+
else {
|
|
1366
|
+
results.push('### Next Steps:\n');
|
|
1367
|
+
results.push('1. **Set up Supabase:** Go to https://supabase.com and create a free project');
|
|
1368
|
+
results.push('2. **Add credentials:** Copy your Supabase URL and anon key to `.env.local`');
|
|
1369
|
+
results.push('3. **Start building:** Just tell me what features you want!\n');
|
|
1370
|
+
results.push('### Example:\n');
|
|
1371
|
+
results.push('> "Add user authentication with email/password"');
|
|
1372
|
+
results.push('> "Create a dashboard with stats cards"');
|
|
1373
|
+
results.push('> "Build a todo list with CRUD operations"');
|
|
1374
|
+
}
|
|
1355
1375
|
}
|
|
1356
1376
|
catch (error) {
|
|
1357
1377
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
@@ -1364,6 +1384,270 @@ phase: setup
|
|
|
1364
1384
|
}],
|
|
1365
1385
|
};
|
|
1366
1386
|
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Show explanation of what fullDeploy will do and ask for confirmation
|
|
1389
|
+
*/
|
|
1390
|
+
showFullDeployExplanation(projectName, description) {
|
|
1391
|
+
const explanation = `# 🚀 Full Deployment: ${projectName}
|
|
1392
|
+
|
|
1393
|
+
## What This Will Do
|
|
1394
|
+
|
|
1395
|
+
Full deployment creates a complete production-ready environment automatically:
|
|
1396
|
+
|
|
1397
|
+
### 1. 📁 Local Project
|
|
1398
|
+
- Create Next.js + Supabase + Drizzle project
|
|
1399
|
+
- Install all dependencies
|
|
1400
|
+
- Set up CodeBakers patterns
|
|
1401
|
+
|
|
1402
|
+
### 2. 🐙 GitHub Repository
|
|
1403
|
+
- Create a new private repository: \`${projectName}\`
|
|
1404
|
+
- Initialize git and push code
|
|
1405
|
+
- Set up .gitignore properly
|
|
1406
|
+
|
|
1407
|
+
### 3. 🗄️ Supabase Project
|
|
1408
|
+
- Create a new Supabase project
|
|
1409
|
+
- Get database connection string
|
|
1410
|
+
- Get API keys (anon + service role)
|
|
1411
|
+
- Auto-configure .env.local
|
|
1412
|
+
|
|
1413
|
+
### 4. 🔺 Vercel Deployment
|
|
1414
|
+
- Deploy to Vercel
|
|
1415
|
+
- Connect to GitHub for auto-deploys
|
|
1416
|
+
- Set all environment variables
|
|
1417
|
+
- Get your live URL
|
|
1418
|
+
|
|
1419
|
+
---
|
|
1420
|
+
|
|
1421
|
+
## Requirements
|
|
1422
|
+
|
|
1423
|
+
Make sure you have these CLIs installed and authenticated:
|
|
1424
|
+
- \`gh\` - GitHub CLI (run: \`gh auth login\`)
|
|
1425
|
+
- \`supabase\` - Supabase CLI (run: \`supabase login\`)
|
|
1426
|
+
- \`vercel\` - Vercel CLI (run: \`vercel login\`)
|
|
1427
|
+
|
|
1428
|
+
---
|
|
1429
|
+
|
|
1430
|
+
## 🎯 Result
|
|
1431
|
+
|
|
1432
|
+
After completion, you'll have:
|
|
1433
|
+
- ✅ GitHub repo with your code
|
|
1434
|
+
- ✅ Supabase project with database ready
|
|
1435
|
+
- ✅ Live URL on Vercel
|
|
1436
|
+
- ✅ Auto-deploys on every push
|
|
1437
|
+
|
|
1438
|
+
---
|
|
1439
|
+
|
|
1440
|
+
**⚠️ IMPORTANT: Ask the user to confirm before proceeding.**
|
|
1441
|
+
|
|
1442
|
+
To proceed, call \`scaffold_project\` again with:
|
|
1443
|
+
\`\`\`json
|
|
1444
|
+
{
|
|
1445
|
+
"projectName": "${projectName}",
|
|
1446
|
+
"description": "${description || ''}",
|
|
1447
|
+
"fullDeploy": true,
|
|
1448
|
+
"deployConfirmed": true
|
|
1449
|
+
}
|
|
1450
|
+
\`\`\`
|
|
1451
|
+
|
|
1452
|
+
Or if user declines, call without fullDeploy:
|
|
1453
|
+
\`\`\`json
|
|
1454
|
+
{
|
|
1455
|
+
"projectName": "${projectName}",
|
|
1456
|
+
"description": "${description || ''}"
|
|
1457
|
+
}
|
|
1458
|
+
\`\`\`
|
|
1459
|
+
`;
|
|
1460
|
+
return {
|
|
1461
|
+
content: [{
|
|
1462
|
+
type: 'text',
|
|
1463
|
+
text: explanation,
|
|
1464
|
+
}],
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Execute full cloud deployment (GitHub + Supabase + Vercel)
|
|
1469
|
+
*/
|
|
1470
|
+
async executeFullDeploy(projectName, cwd, description) {
|
|
1471
|
+
const results = [];
|
|
1472
|
+
// Check for required CLIs
|
|
1473
|
+
const cliChecks = this.checkRequiredCLIs();
|
|
1474
|
+
if (cliChecks.missing.length > 0) {
|
|
1475
|
+
results.push('### ❌ Missing Required CLIs\n');
|
|
1476
|
+
results.push('The following CLIs are required for full deployment:\n');
|
|
1477
|
+
for (const cli of cliChecks.missing) {
|
|
1478
|
+
results.push(`- **${cli.name}**: ${cli.installCmd}`);
|
|
1479
|
+
}
|
|
1480
|
+
results.push('\nInstall the missing CLIs and try again.');
|
|
1481
|
+
return results;
|
|
1482
|
+
}
|
|
1483
|
+
results.push('✓ All required CLIs found\n');
|
|
1484
|
+
// Step 1: Initialize Git and create GitHub repo
|
|
1485
|
+
results.push('### Step 1: GitHub Repository\n');
|
|
1486
|
+
try {
|
|
1487
|
+
// Initialize git
|
|
1488
|
+
(0, child_process_1.execSync)('git init', { cwd, stdio: 'pipe' });
|
|
1489
|
+
(0, child_process_1.execSync)('git add .', { cwd, stdio: 'pipe' });
|
|
1490
|
+
(0, child_process_1.execSync)('git commit -m "Initial commit from CodeBakers"', { cwd, stdio: 'pipe' });
|
|
1491
|
+
results.push('✓ Initialized git repository');
|
|
1492
|
+
// Create GitHub repo
|
|
1493
|
+
const ghDescription = description || `${projectName} - Created with CodeBakers`;
|
|
1494
|
+
(0, child_process_1.execSync)(`gh repo create ${projectName} --private --source=. --push --description "${ghDescription}"`, { cwd, stdio: 'pipe' });
|
|
1495
|
+
results.push(`✓ Created GitHub repo: ${projectName}`);
|
|
1496
|
+
results.push(` → https://github.com/${this.getGitHubUsername()}/${projectName}\n`);
|
|
1497
|
+
}
|
|
1498
|
+
catch (error) {
|
|
1499
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
1500
|
+
results.push(`⚠️ GitHub setup failed: ${msg}`);
|
|
1501
|
+
results.push(' You can create the repo manually: gh repo create\n');
|
|
1502
|
+
}
|
|
1503
|
+
// Step 2: Create Supabase project
|
|
1504
|
+
results.push('### Step 2: Supabase Project\n');
|
|
1505
|
+
try {
|
|
1506
|
+
// Create Supabase project (this may take a while)
|
|
1507
|
+
const orgId = this.getSupabaseOrgId();
|
|
1508
|
+
if (orgId) {
|
|
1509
|
+
(0, child_process_1.execSync)(`supabase projects create ${projectName} --org-id ${orgId} --region us-east-1 --db-password "${this.generatePassword()}"`, { cwd, stdio: 'pipe', timeout: 120000 });
|
|
1510
|
+
results.push(`✓ Created Supabase project: ${projectName}`);
|
|
1511
|
+
// Get project credentials
|
|
1512
|
+
const projectsOutput = (0, child_process_1.execSync)('supabase projects list --output json', { cwd, encoding: 'utf-8' });
|
|
1513
|
+
const projects = JSON.parse(projectsOutput);
|
|
1514
|
+
const newProject = projects.find((p) => p.name === projectName);
|
|
1515
|
+
if (newProject) {
|
|
1516
|
+
// Update .env.local with Supabase credentials
|
|
1517
|
+
const envPath = path.join(cwd, '.env.local');
|
|
1518
|
+
let envContent = fs.readFileSync(envPath, 'utf-8');
|
|
1519
|
+
envContent = envContent.replace('your-supabase-url', `https://${newProject.id}.supabase.co`);
|
|
1520
|
+
envContent = envContent.replace('your-anon-key', newProject.anon_key || 'YOUR_ANON_KEY');
|
|
1521
|
+
fs.writeFileSync(envPath, envContent);
|
|
1522
|
+
results.push('✓ Updated .env.local with Supabase credentials\n');
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
else {
|
|
1526
|
+
results.push('⚠️ Could not detect Supabase organization');
|
|
1527
|
+
results.push(' Run: supabase orgs list\n');
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
catch (error) {
|
|
1531
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
1532
|
+
results.push(`⚠️ Supabase setup failed: ${msg}`);
|
|
1533
|
+
results.push(' Create project manually at: https://supabase.com/dashboard\n');
|
|
1534
|
+
}
|
|
1535
|
+
// Step 3: Deploy to Vercel
|
|
1536
|
+
results.push('### Step 3: Vercel Deployment\n');
|
|
1537
|
+
try {
|
|
1538
|
+
// Link to Vercel (creates new project)
|
|
1539
|
+
(0, child_process_1.execSync)('vercel link --yes', { cwd, stdio: 'pipe' });
|
|
1540
|
+
results.push('✓ Linked to Vercel');
|
|
1541
|
+
// Set environment variables from .env.local
|
|
1542
|
+
const envPath = path.join(cwd, '.env.local');
|
|
1543
|
+
if (fs.existsSync(envPath)) {
|
|
1544
|
+
const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
1545
|
+
const envVars = envContent.split('\n')
|
|
1546
|
+
.filter(line => line.includes('=') && !line.startsWith('#'))
|
|
1547
|
+
.map(line => {
|
|
1548
|
+
const [key, ...valueParts] = line.split('=');
|
|
1549
|
+
return { key: key.trim(), value: valueParts.join('=').trim() };
|
|
1550
|
+
});
|
|
1551
|
+
for (const { key, value } of envVars) {
|
|
1552
|
+
if (value && !value.includes('your-')) {
|
|
1553
|
+
try {
|
|
1554
|
+
(0, child_process_1.execSync)(`vercel env add ${key} production <<< "${value}"`, { cwd, stdio: 'pipe', shell: 'bash' });
|
|
1555
|
+
}
|
|
1556
|
+
catch {
|
|
1557
|
+
// Env var might already exist, try to update
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
results.push('✓ Set environment variables');
|
|
1562
|
+
}
|
|
1563
|
+
// Deploy to production
|
|
1564
|
+
const deployOutput = (0, child_process_1.execSync)('vercel --prod --yes', { cwd, encoding: 'utf-8' });
|
|
1565
|
+
const urlMatch = deployOutput.match(/https:\/\/[^\s]+\.vercel\.app/);
|
|
1566
|
+
const deployUrl = urlMatch ? urlMatch[0] : 'Check Vercel dashboard';
|
|
1567
|
+
results.push(`✓ Deployed to Vercel`);
|
|
1568
|
+
results.push(` → ${deployUrl}\n`);
|
|
1569
|
+
// Connect to GitHub for auto-deploys
|
|
1570
|
+
try {
|
|
1571
|
+
(0, child_process_1.execSync)('vercel git connect --yes', { cwd, stdio: 'pipe' });
|
|
1572
|
+
results.push('✓ Connected to GitHub for auto-deploys\n');
|
|
1573
|
+
}
|
|
1574
|
+
catch {
|
|
1575
|
+
results.push('⚠️ Could not auto-connect to GitHub\n');
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
catch (error) {
|
|
1579
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
1580
|
+
results.push(`⚠️ Vercel deployment failed: ${msg}`);
|
|
1581
|
+
results.push(' Deploy manually: vercel --prod\n');
|
|
1582
|
+
}
|
|
1583
|
+
// Summary
|
|
1584
|
+
results.push('---\n');
|
|
1585
|
+
results.push('## 🎉 Full Deployment Complete!\n');
|
|
1586
|
+
results.push('Your project is now live with:');
|
|
1587
|
+
results.push('- GitHub repo with CI/CD ready');
|
|
1588
|
+
results.push('- Supabase database configured');
|
|
1589
|
+
results.push('- Vercel hosting with auto-deploys\n');
|
|
1590
|
+
results.push('**Start building features - every push auto-deploys!**');
|
|
1591
|
+
return results;
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* Check if required CLIs are installed
|
|
1595
|
+
*/
|
|
1596
|
+
checkRequiredCLIs() {
|
|
1597
|
+
const clis = [
|
|
1598
|
+
{ name: 'gh', cmd: 'gh --version', installCmd: 'npm install -g gh' },
|
|
1599
|
+
{ name: 'supabase', cmd: 'supabase --version', installCmd: 'npm install -g supabase' },
|
|
1600
|
+
{ name: 'vercel', cmd: 'vercel --version', installCmd: 'npm install -g vercel' },
|
|
1601
|
+
];
|
|
1602
|
+
const installed = [];
|
|
1603
|
+
const missing = [];
|
|
1604
|
+
for (const cli of clis) {
|
|
1605
|
+
try {
|
|
1606
|
+
(0, child_process_1.execSync)(cli.cmd, { stdio: 'pipe' });
|
|
1607
|
+
installed.push(cli.name);
|
|
1608
|
+
}
|
|
1609
|
+
catch {
|
|
1610
|
+
missing.push({ name: cli.name, installCmd: cli.installCmd });
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
return { installed, missing };
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Get GitHub username from gh CLI
|
|
1617
|
+
*/
|
|
1618
|
+
getGitHubUsername() {
|
|
1619
|
+
try {
|
|
1620
|
+
const output = (0, child_process_1.execSync)('gh api user --jq .login', { encoding: 'utf-8' });
|
|
1621
|
+
return output.trim();
|
|
1622
|
+
}
|
|
1623
|
+
catch {
|
|
1624
|
+
return 'YOUR_USERNAME';
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Get Supabase organization ID
|
|
1629
|
+
*/
|
|
1630
|
+
getSupabaseOrgId() {
|
|
1631
|
+
try {
|
|
1632
|
+
const output = (0, child_process_1.execSync)('supabase orgs list --output json', { encoding: 'utf-8' });
|
|
1633
|
+
const orgs = JSON.parse(output);
|
|
1634
|
+
return orgs[0]?.id || null;
|
|
1635
|
+
}
|
|
1636
|
+
catch {
|
|
1637
|
+
return null;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Generate a secure random password for Supabase
|
|
1642
|
+
*/
|
|
1643
|
+
generatePassword() {
|
|
1644
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
1645
|
+
let password = '';
|
|
1646
|
+
for (let i = 0; i < 24; i++) {
|
|
1647
|
+
password += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
1648
|
+
}
|
|
1649
|
+
return password;
|
|
1650
|
+
}
|
|
1367
1651
|
async handleInitProject(args) {
|
|
1368
1652
|
const cwd = process.cwd();
|
|
1369
1653
|
const results = [];
|
package/package.json
CHANGED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import { createInterface } from 'readline';
|
|
4
|
+
import { existsSync, readFileSync, readdirSync } from 'fs';
|
|
5
|
+
import { join, basename } from 'path';
|
|
6
|
+
import { getApiUrl, getApiKey } from '../config.js';
|
|
7
|
+
|
|
8
|
+
function prompt(question: string): Promise<string> {
|
|
9
|
+
const rl = createInterface({
|
|
10
|
+
input: process.stdin,
|
|
11
|
+
output: process.stdout,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
rl.question(question, (answer) => {
|
|
16
|
+
rl.close();
|
|
17
|
+
resolve(answer.trim());
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface PushOptions {
|
|
23
|
+
version: string;
|
|
24
|
+
changelog?: string;
|
|
25
|
+
autoPublish?: boolean;
|
|
26
|
+
sourcePath?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ModulesContent {
|
|
30
|
+
[key: string]: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Read all module files from a directory
|
|
35
|
+
*/
|
|
36
|
+
function readModulesFromDir(dirPath: string): ModulesContent {
|
|
37
|
+
const modules: ModulesContent = {};
|
|
38
|
+
|
|
39
|
+
if (!existsSync(dirPath)) {
|
|
40
|
+
return modules;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const files = readdirSync(dirPath).filter(f => f.endsWith('.md'));
|
|
44
|
+
|
|
45
|
+
for (const file of files) {
|
|
46
|
+
const filePath = join(dirPath, file);
|
|
47
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
48
|
+
const moduleName = basename(file, '.md');
|
|
49
|
+
modules[moduleName] = content;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return modules;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Push patterns to the server via admin API
|
|
57
|
+
*/
|
|
58
|
+
export async function pushPatterns(options: PushOptions): Promise<void> {
|
|
59
|
+
console.log(chalk.blue('\n CodeBakers Push Patterns\n'));
|
|
60
|
+
|
|
61
|
+
const sourcePath = options.sourcePath || process.cwd();
|
|
62
|
+
|
|
63
|
+
// Check for API key - first from config, then from environment
|
|
64
|
+
const apiKey = getApiKey() || process.env.CODEBAKERS_ADMIN_KEY;
|
|
65
|
+
if (!apiKey) {
|
|
66
|
+
console.log(chalk.red(' ✗ No API key found\n'));
|
|
67
|
+
console.log(chalk.gray(' Either:'));
|
|
68
|
+
console.log(chalk.cyan(' 1. Run `codebakers setup` to configure your API key'));
|
|
69
|
+
console.log(chalk.cyan(' 2. Set CODEBAKERS_ADMIN_KEY environment variable\n'));
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Read main files
|
|
74
|
+
const claudeMdPath = join(sourcePath, 'CLAUDE.md');
|
|
75
|
+
const cursorRulesPath = join(sourcePath, '.cursorrules');
|
|
76
|
+
|
|
77
|
+
let claudeMdContent: string | null = null;
|
|
78
|
+
let cursorRulesContent: string | null = null;
|
|
79
|
+
|
|
80
|
+
if (existsSync(claudeMdPath)) {
|
|
81
|
+
claudeMdContent = readFileSync(claudeMdPath, 'utf-8');
|
|
82
|
+
console.log(chalk.green(` ✓ Found CLAUDE.md (${(claudeMdContent.length / 1024).toFixed(1)} KB)`));
|
|
83
|
+
} else {
|
|
84
|
+
console.log(chalk.yellow(` ⚠ CLAUDE.md not found at ${claudeMdPath}`));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (existsSync(cursorRulesPath)) {
|
|
88
|
+
cursorRulesContent = readFileSync(cursorRulesPath, 'utf-8');
|
|
89
|
+
console.log(chalk.green(` ✓ Found .cursorrules (${(cursorRulesContent.length / 1024).toFixed(1)} KB)`));
|
|
90
|
+
} else {
|
|
91
|
+
console.log(chalk.yellow(` ⚠ .cursorrules not found at ${cursorRulesPath}`));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!claudeMdContent && !cursorRulesContent) {
|
|
95
|
+
console.log(chalk.red('\n ✗ No pattern files found. Nothing to push.\n'));
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Read module directories
|
|
100
|
+
const claudeModulesPath = join(sourcePath, '.claude');
|
|
101
|
+
const cursorModulesPath = join(sourcePath, '.cursorrules-modules');
|
|
102
|
+
|
|
103
|
+
const modulesContent = readModulesFromDir(claudeModulesPath);
|
|
104
|
+
const cursorModulesContent = readModulesFromDir(cursorModulesPath);
|
|
105
|
+
|
|
106
|
+
const claudeModuleCount = Object.keys(modulesContent).length;
|
|
107
|
+
const cursorModuleCount = Object.keys(cursorModulesContent).length;
|
|
108
|
+
|
|
109
|
+
if (claudeModuleCount > 0) {
|
|
110
|
+
console.log(chalk.green(` ✓ Found ${claudeModuleCount} Claude modules in .claude/`));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (cursorModuleCount > 0) {
|
|
114
|
+
console.log(chalk.green(` ✓ Found ${cursorModuleCount} Cursor modules in .cursorrules-modules/`));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log('');
|
|
118
|
+
|
|
119
|
+
// Show summary
|
|
120
|
+
console.log(chalk.white(' Push Summary:\n'));
|
|
121
|
+
console.log(chalk.gray(` Version: ${chalk.cyan(options.version)}`));
|
|
122
|
+
console.log(chalk.gray(` Auto-publish: ${options.autoPublish ? chalk.green('Yes') : chalk.yellow('No')}`));
|
|
123
|
+
if (options.changelog) {
|
|
124
|
+
console.log(chalk.gray(` Changelog: ${chalk.dim(options.changelog.slice(0, 60))}...`));
|
|
125
|
+
}
|
|
126
|
+
console.log('');
|
|
127
|
+
|
|
128
|
+
// Files to upload
|
|
129
|
+
console.log(chalk.white(' Files to upload:\n'));
|
|
130
|
+
if (claudeMdContent) console.log(chalk.cyan(' • CLAUDE.md'));
|
|
131
|
+
if (cursorRulesContent) console.log(chalk.cyan(' • .cursorrules'));
|
|
132
|
+
for (const mod of Object.keys(modulesContent)) {
|
|
133
|
+
console.log(chalk.dim(` • .claude/${mod}.md`));
|
|
134
|
+
}
|
|
135
|
+
for (const mod of Object.keys(cursorModulesContent)) {
|
|
136
|
+
console.log(chalk.dim(` • .cursorrules-modules/${mod}.md`));
|
|
137
|
+
}
|
|
138
|
+
console.log('');
|
|
139
|
+
|
|
140
|
+
// Confirm
|
|
141
|
+
const confirm = await prompt(chalk.gray(' Push these patterns? (y/N): '));
|
|
142
|
+
if (confirm.toLowerCase() !== 'y') {
|
|
143
|
+
console.log(chalk.gray('\n Cancelled.\n'));
|
|
144
|
+
process.exit(0);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Push to server
|
|
148
|
+
const spinner = ora('Pushing patterns to server...').start();
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
const apiUrl = getApiUrl();
|
|
152
|
+
const response = await fetch(`${apiUrl}/api/admin/content/push`, {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
headers: {
|
|
155
|
+
'Content-Type': 'application/json',
|
|
156
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
157
|
+
},
|
|
158
|
+
body: JSON.stringify({
|
|
159
|
+
version: options.version,
|
|
160
|
+
claudeMdContent,
|
|
161
|
+
cursorRulesContent,
|
|
162
|
+
modulesContent: claudeModuleCount > 0 ? modulesContent : undefined,
|
|
163
|
+
cursorModulesContent: cursorModuleCount > 0 ? cursorModulesContent : undefined,
|
|
164
|
+
changelog: options.changelog,
|
|
165
|
+
autoPublish: options.autoPublish,
|
|
166
|
+
}),
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const data = await response.json();
|
|
170
|
+
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
spinner.fail(chalk.red(`Push failed: ${data.error || 'Unknown error'}`));
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
spinner.succeed(chalk.green('Patterns pushed successfully!'));
|
|
177
|
+
|
|
178
|
+
console.log(chalk.white('\n Result:\n'));
|
|
179
|
+
console.log(chalk.gray(` Version ID: ${chalk.cyan(data.version?.id || 'N/A')}`));
|
|
180
|
+
console.log(chalk.gray(` Version: ${chalk.cyan(data.version?.version || options.version)}`));
|
|
181
|
+
console.log(chalk.gray(` Published: ${data.published ? chalk.green('Yes') : chalk.yellow('No - run publish manually')}`));
|
|
182
|
+
console.log('');
|
|
183
|
+
console.log(chalk.green(` ${data.message}\n`));
|
|
184
|
+
|
|
185
|
+
} catch (error) {
|
|
186
|
+
spinner.fail(chalk.red('Failed to connect to server'));
|
|
187
|
+
console.log(chalk.gray(`\n Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Interactive push command
|
|
194
|
+
*/
|
|
195
|
+
export async function pushPatternsInteractive(): Promise<void> {
|
|
196
|
+
console.log(chalk.blue('\n CodeBakers Push Patterns\n'));
|
|
197
|
+
|
|
198
|
+
// Get version
|
|
199
|
+
const version = await prompt(chalk.cyan(' Version (e.g., 4.5): '));
|
|
200
|
+
if (!version) {
|
|
201
|
+
console.log(chalk.red('\n Version is required.\n'));
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Get changelog
|
|
206
|
+
const changelog = await prompt(chalk.cyan(' Changelog (optional): '));
|
|
207
|
+
|
|
208
|
+
// Ask about auto-publish
|
|
209
|
+
const autoPublishAnswer = await prompt(chalk.cyan(' Auto-publish? (y/N): '));
|
|
210
|
+
const autoPublish = autoPublishAnswer.toLowerCase() === 'y';
|
|
211
|
+
|
|
212
|
+
// Get source path
|
|
213
|
+
const sourcePathAnswer = await prompt(chalk.cyan(' Source path (Enter for current directory): '));
|
|
214
|
+
const sourcePath = sourcePathAnswer || process.cwd();
|
|
215
|
+
|
|
216
|
+
await pushPatterns({
|
|
217
|
+
version,
|
|
218
|
+
changelog: changelog || undefined,
|
|
219
|
+
autoPublish,
|
|
220
|
+
sourcePath,
|
|
221
|
+
});
|
|
222
|
+
}
|
package/src/commands/setup.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { createInterface } from 'readline';
|
|
|
4
4
|
import { execSync } from 'child_process';
|
|
5
5
|
import { setApiKey, getApiKey, getApiUrl, syncServiceKeys, SERVICE_KEY_LABELS, type ServiceName } from '../config.js';
|
|
6
6
|
import { validateApiKey, formatApiError, checkForUpdates, getCliVersion, type ApiError } from '../lib/api.js';
|
|
7
|
+
import { showQuickStartGuide, formatFriendlyError, getNetworkError, getAuthError } from '../lib/progress.js';
|
|
7
8
|
|
|
8
9
|
function prompt(question: string): Promise<string> {
|
|
9
10
|
const rl = createInterface({
|
|
@@ -67,8 +68,16 @@ export async function setup(): Promise<void> {
|
|
|
67
68
|
} catch (error) {
|
|
68
69
|
spinner.fail('Invalid API key');
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
// Use friendly error formatting
|
|
72
|
+
if (error && typeof error === 'object' && 'code' in error) {
|
|
73
|
+
const code = (error as { code: string }).code;
|
|
74
|
+
if (code === 'NETWORK_ERROR') {
|
|
75
|
+
console.log(formatFriendlyError(getNetworkError()));
|
|
76
|
+
} else if (code === 'UNAUTHORIZED' || code === 'INVALID_FORMAT') {
|
|
77
|
+
console.log(formatFriendlyError(getAuthError()));
|
|
78
|
+
} else if ('recoverySteps' in error) {
|
|
79
|
+
console.log(chalk.red(`\n ${formatApiError(error as ApiError)}\n`));
|
|
80
|
+
}
|
|
72
81
|
} else {
|
|
73
82
|
const message = error instanceof Error ? error.message : 'API key validation failed';
|
|
74
83
|
console.log(chalk.red(`\n ${message}\n`));
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { upgrade } from './commands/upgrade.js';
|
|
|
18
18
|
import { config } from './commands/config.js';
|
|
19
19
|
import { audit } from './commands/audit.js';
|
|
20
20
|
import { heal, healWatch } from './commands/heal.js';
|
|
21
|
+
import { pushPatterns, pushPatternsInteractive } from './commands/push-patterns.js';
|
|
21
22
|
|
|
22
23
|
// Show welcome message when no command is provided
|
|
23
24
|
function showWelcome(): void {
|
|
@@ -68,7 +69,7 @@ const program = new Command();
|
|
|
68
69
|
program
|
|
69
70
|
.name('codebakers')
|
|
70
71
|
.description('CodeBakers CLI - Production patterns for AI-assisted development')
|
|
71
|
-
.version('
|
|
72
|
+
.version('2.9.0');
|
|
72
73
|
|
|
73
74
|
// Primary command - one-time setup
|
|
74
75
|
program
|
|
@@ -162,6 +163,27 @@ program
|
|
|
162
163
|
}
|
|
163
164
|
});
|
|
164
165
|
|
|
166
|
+
// Admin commands
|
|
167
|
+
program
|
|
168
|
+
.command('push-patterns')
|
|
169
|
+
.description('Push pattern files to the server (admin only)')
|
|
170
|
+
.option('-v, --version <version>', 'Version number (e.g., 4.5)')
|
|
171
|
+
.option('-c, --changelog <message>', 'Changelog message')
|
|
172
|
+
.option('-p, --publish', 'Auto-publish after push')
|
|
173
|
+
.option('-s, --source <path>', 'Source directory (default: current directory)')
|
|
174
|
+
.action(async (options) => {
|
|
175
|
+
if (options.version) {
|
|
176
|
+
await pushPatterns({
|
|
177
|
+
version: options.version,
|
|
178
|
+
changelog: options.changelog,
|
|
179
|
+
autoPublish: options.publish,
|
|
180
|
+
sourcePath: options.source,
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
await pushPatternsInteractive();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
165
187
|
// MCP Server commands
|
|
166
188
|
program
|
|
167
189
|
.command('serve')
|