smoonb 0.0.44 → 0.0.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smoonb",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "description": "Complete Supabase backup and migration tool - EXPERIMENTAL VERSION - USE AT YOUR OWN RISK",
5
5
  "preferGlobal": false,
6
6
  "preventGlobalInstall": true,
@@ -187,7 +187,7 @@ async function askRestoreComponents(backupPath) {
187
187
  questions.push({
188
188
  type: 'confirm',
189
189
  name: 'restoreDatabase',
190
- message: 'Deseja restaurar Database?',
190
+ message: 'Deseja restaurar Database (S/n):',
191
191
  default: true
192
192
  });
193
193
 
@@ -197,7 +197,7 @@ async function askRestoreComponents(backupPath) {
197
197
  questions.push({
198
198
  type: 'confirm',
199
199
  name: 'restoreEdgeFunctions',
200
- message: 'Deseja restaurar Edge Functions?',
200
+ message: 'Deseja restaurar Edge Functions (S/n):',
201
201
  default: true
202
202
  });
203
203
  }
@@ -207,8 +207,8 @@ async function askRestoreComponents(backupPath) {
207
207
  questions.push({
208
208
  type: 'confirm',
209
209
  name: 'restoreAuthSettings',
210
- message: 'Deseja restaurar Auth Settings (interativo)?',
211
- default: true
210
+ message: 'Deseja restaurar Auth Settings (s/N):',
211
+ default: false
212
212
  });
213
213
  }
214
214
 
@@ -218,7 +218,7 @@ async function askRestoreComponents(backupPath) {
218
218
  questions.push({
219
219
  type: 'confirm',
220
220
  name: 'restoreStorage',
221
- message: 'Deseja ver informações de Storage Buckets?',
221
+ message: 'Deseja ver informações de Storage Buckets (s/N):',
222
222
  default: false
223
223
  });
224
224
  }
@@ -230,7 +230,7 @@ async function askRestoreComponents(backupPath) {
230
230
  questions.push({
231
231
  type: 'confirm',
232
232
  name: 'restoreDatabaseSettings',
233
- message: 'Deseja restaurar Database Extensions and Settings?',
233
+ message: 'Deseja restaurar Database Extensions and Settings (s/N):',
234
234
  default: false
235
235
  });
236
236
  }
@@ -240,8 +240,8 @@ async function askRestoreComponents(backupPath) {
240
240
  questions.push({
241
241
  type: 'confirm',
242
242
  name: 'restoreRealtimeSettings',
243
- message: 'Deseja restaurar Realtime Settings (interativo)?',
244
- default: true
243
+ message: 'Deseja restaurar Realtime Settings (s/N):',
244
+ default: false
245
245
  });
246
246
  }
247
247
 
@@ -401,17 +401,25 @@ async function restoreEdgeFunctions(backupPath, targetProject) {
401
401
  console.log(chalk.blue('\n⚡ Restaurando Edge Functions...'));
402
402
 
403
403
  try {
404
+ const fs = require('fs').promises;
404
405
  const { execSync } = require('child_process');
405
406
  const edgeFunctionsDir = path.join(backupPath, 'edge-functions');
406
407
 
407
- if (!fs.existsSync(edgeFunctionsDir)) {
408
+ if (!await fs.access(edgeFunctionsDir).then(() => true).catch(() => false)) {
408
409
  console.log(chalk.yellow(' ⚠️ Nenhuma Edge Function encontrada no backup'));
409
410
  return;
410
411
  }
411
412
 
412
- const functions = fs.readdirSync(edgeFunctionsDir).filter(item =>
413
- fs.statSync(path.join(edgeFunctionsDir, item)).isDirectory()
414
- );
413
+ const items = await fs.readdir(edgeFunctionsDir);
414
+ const functions = [];
415
+
416
+ for (const item of items) {
417
+ const itemPath = path.join(edgeFunctionsDir, item);
418
+ const stats = await fs.stat(itemPath);
419
+ if (stats.isDirectory()) {
420
+ functions.push(item);
421
+ }
422
+ }
415
423
 
416
424
  if (functions.length === 0) {
417
425
  console.log(chalk.yellow(' ⚠️ Nenhuma Edge Function encontrada no backup'));
@@ -420,29 +428,55 @@ async function restoreEdgeFunctions(backupPath, targetProject) {
420
428
 
421
429
  console.log(chalk.gray(` - Encontradas ${functions.length} Edge Function(s)`));
422
430
 
423
- // Link com projeto target
431
+ // COPIAR Edge Functions de backups/backup-XXX/edge-functions para supabase/functions
432
+ const supabaseFunctionsDir = path.join(process.cwd(), 'supabase', 'functions');
433
+
434
+ // Criar diretório supabase/functions se não existir
435
+ await fs.mkdir(supabaseFunctionsDir, { recursive: true });
436
+
437
+ // Limpar supabase/functions antes de copiar
438
+ console.log(chalk.gray(' - Limpando supabase/functions...'));
439
+ try {
440
+ await fs.rm(supabaseFunctionsDir, { recursive: true, force: true });
441
+ await fs.mkdir(supabaseFunctionsDir, { recursive: true });
442
+ } catch (cleanError) {
443
+ // Ignorar erro de limpeza se não existir
444
+ }
445
+
446
+ // Copiar cada Edge Function para supabase/functions
447
+ for (const funcName of functions) {
448
+ const backupFuncPath = path.join(edgeFunctionsDir, funcName);
449
+ const targetFuncPath = path.join(supabaseFunctionsDir, funcName);
450
+
451
+ console.log(chalk.gray(` - Copiando ${funcName} para supabase/functions...`));
452
+
453
+ // Copiar recursivamente
454
+ await copyDirectoryRecursive(backupFuncPath, targetFuncPath);
455
+ }
456
+
424
457
  console.log(chalk.gray(` - Linkando com projeto ${targetProject.targetProjectId}...`));
425
458
 
459
+ // Linkar com o projeto destino
426
460
  try {
427
461
  execSync(`supabase link --project-ref ${targetProject.targetProjectId}`, {
428
462
  stdio: 'pipe',
429
- encoding: 'utf8'
463
+ encoding: 'utf8',
464
+ timeout: 10000
430
465
  });
431
466
  } catch (linkError) {
432
- console.log(chalk.yellow(` ⚠️ Link pode já existir, continuando...`));
467
+ console.log(chalk.yellow(' ⚠️ Link pode já existir, continuando...'));
433
468
  }
434
469
 
435
- // Deploy de cada função
470
+ // Deploy das Edge Functions
436
471
  for (const funcName of functions) {
437
472
  console.log(chalk.gray(` - Deployando ${funcName}...`));
438
473
 
439
474
  try {
440
- const functionPath = path.join(edgeFunctionsDir, funcName);
441
-
442
475
  execSync(`supabase functions deploy ${funcName}`, {
443
- cwd: functionPath,
476
+ cwd: process.cwd(),
444
477
  stdio: 'pipe',
445
- encoding: 'utf8'
478
+ encoding: 'utf8',
479
+ timeout: 120000
446
480
  });
447
481
 
448
482
  console.log(chalk.green(` ✅ ${funcName} deployada com sucesso!`));
@@ -451,11 +485,41 @@ async function restoreEdgeFunctions(backupPath, targetProject) {
451
485
  }
452
486
  }
453
487
 
488
+ // Limpar supabase/functions após deploy
489
+ console.log(chalk.gray(' - Limpando supabase/functions após deploy...'));
490
+ try {
491
+ await fs.rm(supabaseFunctionsDir, { recursive: true, force: true });
492
+ } catch (cleanError) {
493
+ // Ignorar erro de limpeza
494
+ }
495
+
496
+ console.log(chalk.green(' ✅ Edge Functions restauradas com sucesso!'));
497
+
454
498
  } catch (error) {
455
499
  console.error(chalk.red(` ❌ Erro ao restaurar Edge Functions: ${error.message}`));
456
500
  }
457
501
  }
458
502
 
503
+ // Função auxiliar para copiar diretório recursivamente
504
+ async function copyDirectoryRecursive(src, dest) {
505
+ const fs = require('fs').promises;
506
+
507
+ await fs.mkdir(dest, { recursive: true });
508
+
509
+ const entries = await fs.readdir(src, { withFileTypes: true });
510
+
511
+ for (const entry of entries) {
512
+ const srcPath = path.join(src, entry.name);
513
+ const destPath = path.join(dest, entry.name);
514
+
515
+ if (entry.isDirectory()) {
516
+ await copyDirectoryRecursive(srcPath, destPath);
517
+ } else {
518
+ await fs.copyFile(srcPath, destPath);
519
+ }
520
+ }
521
+ }
522
+
459
523
  // Restaurar Storage Buckets (interativo - exibir informações)
460
524
  async function restoreStorageBuckets(backupPath, targetProject) {
461
525
  console.log(chalk.blue('\n📦 Restaurando Storage Buckets...'));