create-alta-app 2.2.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +63 -21
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { execSync } from 'node:child_process';
|
|
4
4
|
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import prompts from 'prompts';
|
|
7
8
|
import ora from 'ora';
|
|
@@ -13,7 +14,17 @@ const ALTA_SERVICE_URL = 'https://ikbbbmmzxeemjwzrzsmt.supabase.co/functions/v1/
|
|
|
13
14
|
const ALTA_FINALIZE_URL = 'https://ikbbbmmzxeemjwzrzsmt.supabase.co/functions/v1/finalize-project';
|
|
14
15
|
|
|
15
16
|
function run(cmd, cwd) {
|
|
16
|
-
execSync(cmd, { cwd, stdio: '
|
|
17
|
+
execSync(cmd, { cwd, stdio: 'pipe' });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function runVerbose(cmd, cwd) {
|
|
21
|
+
try {
|
|
22
|
+
return execSync(cmd, { cwd, stdio: 'pipe', encoding: 'utf-8' });
|
|
23
|
+
} catch (err) {
|
|
24
|
+
const stderr = err.stderr?.toString() || '';
|
|
25
|
+
const stdout = err.stdout?.toString() || '';
|
|
26
|
+
throw new Error(stderr || stdout || err.message);
|
|
27
|
+
}
|
|
17
28
|
}
|
|
18
29
|
|
|
19
30
|
function canRun(cmd) {
|
|
@@ -362,6 +373,9 @@ async function main() {
|
|
|
362
373
|
try {
|
|
363
374
|
credentials = await createProject(projectName, response.password);
|
|
364
375
|
spinnerCloud.succeed(pc.green('Cloud projects created'));
|
|
376
|
+
console.log(` ${pc.dim('Supabase:')} ${credentials.supabaseUrl || 'N/A'}`);
|
|
377
|
+
console.log(` ${pc.dim('Vercel:')} ${credentials.vercelUrl || 'N/A'}`);
|
|
378
|
+
console.log(` ${pc.dim('Vercel token:')} ${credentials.vercelToken ? credentials.vercelToken.slice(0, 8) + '...' : pc.red('NOT RECEIVED')}`);
|
|
365
379
|
} catch (err) {
|
|
366
380
|
spinnerCloud.fail(pc.yellow('Could not create cloud projects'));
|
|
367
381
|
console.log(` ${pc.dim(err.message)}`);
|
|
@@ -461,26 +475,49 @@ async function main() {
|
|
|
461
475
|
}
|
|
462
476
|
}
|
|
463
477
|
|
|
464
|
-
// ── Step 6b:
|
|
465
|
-
if (credentials) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
478
|
+
// ── Step 6b: Set Vercel token & link project ──
|
|
479
|
+
if (credentials?.vercelToken) {
|
|
480
|
+
const spinnerVercel = ora({ text: 'Configuring Vercel...', indent: 2 }).start();
|
|
481
|
+
try {
|
|
482
|
+
const tokenPreview = credentials.vercelToken.slice(0, 8) + '...';
|
|
483
|
+
|
|
484
|
+
// Write VERCEL_TOKEN to ~/.zshrc for future shell sessions
|
|
485
|
+
const zshrc = path.join(os.homedir(), '.zshrc');
|
|
486
|
+
const zshrcContent = fs.existsSync(zshrc) ? fs.readFileSync(zshrc, 'utf-8') : '';
|
|
487
|
+
const exportLine = `export VERCEL_TOKEN="${credentials.vercelToken}"`;
|
|
488
|
+
|
|
489
|
+
if (zshrcContent.includes('export VERCEL_TOKEN=')) {
|
|
490
|
+
const updated = zshrcContent.replace(/export VERCEL_TOKEN=.*/, exportLine);
|
|
491
|
+
fs.writeFileSync(zshrc, updated);
|
|
492
|
+
spinnerVercel.text = `Vercel token updated in ~/.zshrc (${tokenPreview})`;
|
|
493
|
+
} else {
|
|
494
|
+
fs.appendFileSync(zshrc, `\n# Vercel CLI token (set by create-alta-app)\n${exportLine}\n`);
|
|
495
|
+
spinnerVercel.text = `Vercel token written to ~/.zshrc (${tokenPreview})`;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// Set in current process so child commands (vercel link, deploy) work immediately
|
|
499
|
+
process.env.VERCEL_TOKEN = credentials.vercelToken;
|
|
500
|
+
spinnerVercel.text = 'Vercel token set in process.env...';
|
|
501
|
+
|
|
502
|
+
// Source ~/.zshrc to load the token into spawned shell subprocesses
|
|
469
503
|
try {
|
|
470
|
-
execSync(
|
|
504
|
+
execSync(`. ${zshrc}`, { shell: '/bin/zsh', stdio: 'ignore', env: { ...process.env, HOME: os.homedir() } });
|
|
505
|
+
spinnerVercel.text = 'Sourced ~/.zshrc — VERCEL_TOKEN loaded';
|
|
471
506
|
} catch {
|
|
472
|
-
|
|
507
|
+
spinnerVercel.text = 'Could not source ~/.zshrc — using process.env instead';
|
|
473
508
|
}
|
|
474
|
-
}
|
|
475
509
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
spinnerVercel.succeed(pc.green('Vercel
|
|
480
|
-
} catch {
|
|
481
|
-
spinnerVercel.warn(pc.yellow('Could not
|
|
482
|
-
console.log(` ${pc.dim('
|
|
510
|
+
// Link the Vercel project
|
|
511
|
+
spinnerVercel.text = `Linking Vercel project: ${projectName}...`;
|
|
512
|
+
runVerbose(`npx vercel link --project ${projectName} --yes --token ${credentials.vercelToken}`, targetDir);
|
|
513
|
+
spinnerVercel.succeed(pc.green('Vercel configured & linked'));
|
|
514
|
+
} catch (err) {
|
|
515
|
+
spinnerVercel.warn(pc.yellow('Could not configure Vercel'));
|
|
516
|
+
console.log(` ${pc.dim('Error: ' + err.message)}`);
|
|
517
|
+
console.log(` ${pc.dim('Run manually: vercel link --project ' + projectName + ' --token $VERCEL_TOKEN')}`);
|
|
483
518
|
}
|
|
519
|
+
} else {
|
|
520
|
+
console.log(` ${pc.yellow('⚠')} No Vercel token received from server — skipping Vercel setup`);
|
|
484
521
|
}
|
|
485
522
|
|
|
486
523
|
// ── Step 7: Write project-specific MCP config ──
|
|
@@ -542,15 +579,20 @@ async function main() {
|
|
|
542
579
|
}
|
|
543
580
|
|
|
544
581
|
// ── Step 9: Deploy to Vercel ──
|
|
545
|
-
if (credentials?.
|
|
582
|
+
if (credentials?.vercelToken) {
|
|
546
583
|
const spinnerDeploy = ora({ text: 'Deploying to Vercel...', indent: 2 }).start();
|
|
547
584
|
try {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
585
|
+
spinnerDeploy.text = `Running: vercel --token ${credentials.vercelToken.slice(0, 8)}... in ${targetDir}`;
|
|
586
|
+
const deployOutput = runVerbose(`npx vercel --yes --token ${credentials.vercelToken}`, targetDir);
|
|
587
|
+
if (deployOutput) console.log(`\n${pc.dim(deployOutput.trim())}`);
|
|
588
|
+
spinnerDeploy.succeed(pc.green(`Deployed to Vercel → ${credentials.vercelUrl || projectName + '.vercel.app'}`));
|
|
589
|
+
} catch (err) {
|
|
551
590
|
spinnerDeploy.warn(pc.yellow('Could not deploy to Vercel'));
|
|
552
|
-
console.log(` ${pc.dim('
|
|
591
|
+
console.log(` ${pc.dim('Error: ' + err.message)}`);
|
|
592
|
+
console.log(` ${pc.dim('Deploy manually: cd ' + projectName + ' && vercel --token $VERCEL_TOKEN')}`);
|
|
553
593
|
}
|
|
594
|
+
} else {
|
|
595
|
+
console.log(` ${pc.dim('Skipping Vercel deploy — no token available')}`);
|
|
554
596
|
}
|
|
555
597
|
|
|
556
598
|
// ── Step 10: Start dev server ──
|