create-alta-app 1.7.3 → 1.8.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.
Files changed (2) hide show
  1. package/index.mjs +78 -33
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -11,6 +11,7 @@ import pc from 'picocolors';
11
11
  const TEMPLATE_REPO = 'adiel-hub/alta-boilerplate';
12
12
  const BRANCH = 'main';
13
13
  const ALTA_SERVICE_URL = 'https://ikbbbmmzxeemjwzrzsmt.supabase.co/functions/v1/create-project';
14
+ const ALTA_FINALIZE_URL = 'https://ikbbbmmzxeemjwzrzsmt.supabase.co/functions/v1/finalize-project';
14
15
 
15
16
  function run(cmd, cwd) {
16
17
  execSync(cmd, { cwd, stdio: 'ignore' });
@@ -430,13 +431,88 @@ async function main() {
430
431
  credentials = null;
431
432
  }
432
433
 
433
- // ── Step 4: Write project config (committed to git no .env needed) ──
434
+ // ── Step 4: Setup shell credentials (needed for polling in next step) ──
435
+ const shellRc = path.join(os.homedir(), '.zshrc');
436
+ const tokensToSet = {
437
+ SUPABASE_ACCESS_TOKEN: 'sbp_66e351be37d4e570fe4347ea7c78bbebc8988219',
438
+ };
439
+
440
+ try {
441
+ let rcContent = fs.existsSync(shellRc) ? fs.readFileSync(shellRc, 'utf-8') : '';
442
+
443
+ for (const [key, value] of Object.entries(tokensToSet)) {
444
+ const regex = new RegExp(`^export ${key}=.*$`, 'm');
445
+ const line = `export ${key}=${value}`;
446
+
447
+ if (regex.test(rcContent)) {
448
+ rcContent = rcContent.replace(regex, line);
449
+ } else {
450
+ rcContent += `\n# Alta\n${line}\n`;
451
+ }
452
+ process.env[key] = value;
453
+ }
454
+
455
+ const spinnerShell = ora({ text: 'Setting up shell credentials...', indent: 2 }).start();
456
+ fs.writeFileSync(shellRc, rcContent);
457
+ spinnerShell.succeed(pc.green('Shell credentials configured'));
458
+ } catch {
459
+ console.log(` ${pc.dim('Could not update ~/.zshrc — add SUPABASE_ACCESS_TOKEN manually')}`);
460
+ }
461
+
462
+ // ── Step 5: Wait for Supabase project to provision & get anon key ──
463
+ let anonKey = '';
464
+ if (credentials) {
465
+ const spinnerKeys = ora({ text: 'Waiting for Supabase project to provision...', indent: 2 }).start();
466
+ const token = process.env.SUPABASE_ACCESS_TOKEN;
467
+ const ref = credentials.supabaseProjectRef;
468
+
469
+ for (let i = 0; i < 24; i++) {
470
+ await new Promise((r) => setTimeout(r, 5000));
471
+ try {
472
+ const res = await fetch(`https://api.supabase.com/v1/projects/${ref}/api-keys`, {
473
+ headers: { Authorization: `Bearer ${token}` },
474
+ });
475
+ if (res.ok) {
476
+ const keys = await res.json();
477
+ const found = keys.find((k) => k.name === 'anon');
478
+ if (found) {
479
+ anonKey = found.api_key;
480
+ break;
481
+ }
482
+ }
483
+ } catch {}
484
+ }
485
+
486
+ if (anonKey) {
487
+ spinnerKeys.succeed(pc.green('Supabase project ready'));
488
+
489
+ // Finalize: disable email confirmation, set shared secrets, set Vercel anon key
490
+ try {
491
+ await fetch(ALTA_FINALIZE_URL, {
492
+ method: 'POST',
493
+ headers: {
494
+ 'Content-Type': 'application/json',
495
+ 'x-api-key': response.password,
496
+ },
497
+ body: JSON.stringify({
498
+ projectRef: ref,
499
+ anonKey,
500
+ vercelProjectId: credentials.vercelProjectId || '',
501
+ }),
502
+ });
503
+ } catch {}
504
+ } else {
505
+ spinnerKeys.warn(pc.yellow('Keys not ready yet — check Supabase dashboard'));
506
+ }
507
+ }
508
+
509
+ // ── Step 5: Write project config ──
434
510
  if (credentials) {
435
511
  const spinnerEnv = ora({ text: 'Writing project config...', indent: 2 }).start();
436
512
  const altaConfig = {
437
513
  supabaseProjectRef: credentials.supabaseProjectRef,
438
514
  supabaseUrl: credentials.supabaseUrl,
439
- supabaseAnonKey: credentials.supabaseAnonKey,
515
+ supabaseAnonKey: anonKey,
440
516
  vercelProjectName: projectName,
441
517
  vercelUrl: credentials.vercelUrl || '',
442
518
  };
@@ -462,37 +538,6 @@ async function main() {
462
538
  console.log(` ${pc.dim(`Then run: cd ${projectName} && pnpm install`)}`);
463
539
  }
464
540
 
465
- // ── Step 6: Setup shell credentials (like AWS sandbox keys in ~/.zshrc) ──
466
- const shellRc = path.join(os.homedir(), '.zshrc');
467
- const tokensToSet = {
468
- SUPABASE_ACCESS_TOKEN: 'sbp_66e351be37d4e570fe4347ea7c78bbebc8988219',
469
- };
470
-
471
- try {
472
- let rcContent = fs.existsSync(shellRc) ? fs.readFileSync(shellRc, 'utf-8') : '';
473
- let changed = false;
474
-
475
- for (const [key, value] of Object.entries(tokensToSet)) {
476
- const regex = new RegExp(`^export ${key}=.*$`, 'm');
477
- const line = `export ${key}=${value}`;
478
-
479
- if (regex.test(rcContent)) {
480
- rcContent = rcContent.replace(regex, line);
481
- } else {
482
- rcContent += `\n# Alta\n${line}\n`;
483
- }
484
- process.env[key] = value;
485
- }
486
- changed = true;
487
-
488
- if (changed) {
489
- const spinnerShell = ora({ text: 'Setting up shell credentials...', indent: 2 }).start();
490
- fs.writeFileSync(shellRc, rcContent);
491
- spinnerShell.succeed(pc.green('Shell credentials configured'));
492
- }
493
- } catch {
494
- console.log(` ${pc.dim('Could not update ~/.zshrc — add SUPABASE_ACCESS_TOKEN manually')}`);
495
- }
496
541
 
497
542
  // ── Step 7: Write project-specific MCP config ──
498
543
  if (credentials) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-alta-app",
3
- "version": "1.7.3",
3
+ "version": "1.8.0",
4
4
  "description": "Create a new Alta project",
5
5
  "bin": {
6
6
  "create-alta-app": "./index.mjs"