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 +1 -1
- package/src/commands/backup.js +44 -29
package/package.json
CHANGED
package/src/commands/backup.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
//
|
|
427
|
-
const
|
|
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
|
-
//
|
|
431
|
-
|
|
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
|
-
//
|
|
441
|
-
|
|
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
|
-
//
|
|
462
|
+
// ✅ LIMPAR supabase/functions após copiar
|
|
444
463
|
try {
|
|
445
|
-
await fs.
|
|
446
|
-
|
|
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++;
|