smoonb 0.0.37 → 0.0.40

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.37",
3
+ "version": "0.0.40",
4
4
  "description": "Complete Supabase backup and migration tool - EXPERIMENTAL VERSION - USE AT YOUR OWN RISK",
5
5
  "preferGlobal": false,
6
6
  "preventGlobalInstall": true,
@@ -414,53 +414,68 @@ async function backupEdgeFunctionsWithDocker(projectId, accessToken, backupDir)
414
414
  let successCount = 0;
415
415
  let errorCount = 0;
416
416
 
417
- // ✅ Baixar cada Edge Function DIRETAMENTE para o backup (sem tocar em ./supabase/functions)
417
+ // ✅ Baixar cada Edge Function via Supabase CLI
418
+ // Nota: O CLI ignora o cwd e sempre baixa para supabase/functions
418
419
  for (const func of functions) {
419
420
  try {
420
421
  console.log(chalk.gray(` - Baixando: ${func.name}...`));
421
422
 
422
- // Criar diretório da função DIRETAMENTE no backup
423
+ // Criar diretório da função NO BACKUP
423
424
  const functionTargetDir = path.join(functionsDir, func.name);
424
425
  await ensureDir(functionTargetDir);
425
426
 
426
- // Baixar Edge Function via Supabase CLI DIRETAMENTE para o backup
427
- const { execSync } = require('child_process');
428
- const tempBackupDir = path.join(backupDir, 'temp-supabase-download');
427
+ // Diretório temporário onde o supabase CLI irá baixar (supabase/functions)
428
+ const tempDownloadDir = path.join(process.cwd(), 'supabase', 'functions', func.name);
429
429
 
430
- // Criar estrutura temp para download sem contaminar ./supabase/
431
- await ensureDir(tempBackupDir);
430
+ // Baixar Edge Function via Supabase CLI (sempre vai para supabase/functions)
431
+ const { execSync } = require('child_process');
432
432
 
433
- // Download para diretório temporário
434
433
  execSync(`supabase functions download ${func.name}`, {
435
- cwd: tempBackupDir,
436
434
  timeout: 60000,
437
435
  stdio: 'pipe'
438
436
  });
439
437
 
440
- // Mover de temp para o backup final
441
- const tempFunctionDir = path.join(tempBackupDir, 'supabase', 'functions', func.name);
438
+ // COPIAR arquivos de supabase/functions para o backup
439
+ try {
440
+ const stat = await fs.stat(tempDownloadDir);
441
+ if (stat.isDirectory()) {
442
+ const files = await fs.readdir(tempDownloadDir);
443
+ for (const file of files) {
444
+ const srcPath = path.join(tempDownloadDir, file);
445
+ const dstPath = path.join(functionTargetDir, file);
446
+
447
+ const fileStats = await fs.stat(srcPath);
448
+ if (fileStats.isDirectory()) {
449
+ // Copiar diretórios recursivamente
450
+ await fs.cp(srcPath, dstPath, { recursive: true });
451
+ } else {
452
+ // Copiar arquivos
453
+ await fs.copyFile(srcPath, dstPath);
454
+ }
455
+ }
456
+ }
457
+ } catch (copyError) {
458
+ // Arquivos não foram baixados, continuar
459
+ console.log(chalk.yellow(` ⚠️ Nenhum arquivo encontrado em ${tempDownloadDir}`));
460
+ }
442
461
 
443
- // Verificar se existe usando fs.promises.access
462
+ // LIMPAR supabase/functions após copiar
444
463
  try {
445
- await fs.access(tempFunctionDir);
446
- await copyDir(tempFunctionDir, functionTargetDir);
447
-
448
- // Limpar diretório temporário
449
- await fs.rm(tempBackupDir, { recursive: true, force: true }).catch(() => {});
450
-
451
- console.log(chalk.green(` ✅ ${func.name} baixada com sucesso`));
452
- successCount++;
453
-
454
- downloadedFunctions.push({
455
- name: func.name,
456
- slug: func.name,
457
- version: func.version || 'unknown',
458
- files: await fs.readdir(functionTargetDir).catch(() => [])
459
- });
460
- } catch (innerError) {
461
- throw new Error('Diretório não encontrado após download');
464
+ await fs.rm(tempDownloadDir, { recursive: true, force: true });
465
+ } catch (cleanError) {
466
+ // Ignorar erro de limpeza
462
467
  }
463
468
 
469
+ console.log(chalk.green(` ✅ ${func.name} baixada com sucesso`));
470
+ successCount++;
471
+
472
+ downloadedFunctions.push({
473
+ name: func.name,
474
+ slug: func.name,
475
+ version: func.version || 'unknown',
476
+ files: await fs.readdir(functionTargetDir).catch(() => [])
477
+ });
478
+
464
479
  } catch (error) {
465
480
  console.log(chalk.yellow(` ⚠️ Erro ao baixar ${func.name}: ${error.message}`));
466
481
  errorCount++;