smoonb 0.0.38 → 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 +38 -5
package/package.json
CHANGED
package/src/commands/backup.js
CHANGED
|
@@ -414,25 +414,58 @@ 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
|
+
// Diretório temporário onde o supabase CLI irá baixar (supabase/functions)
|
|
428
|
+
const tempDownloadDir = path.join(process.cwd(), 'supabase', 'functions', func.name);
|
|
429
|
+
|
|
430
|
+
// Baixar Edge Function via Supabase CLI (sempre vai para supabase/functions)
|
|
427
431
|
const { execSync } = require('child_process');
|
|
428
432
|
|
|
429
|
-
// Download DIRETO para o diretório de destino (sem intermediários)
|
|
430
433
|
execSync(`supabase functions download ${func.name}`, {
|
|
431
|
-
cwd: functionTargetDir,
|
|
432
434
|
timeout: 60000,
|
|
433
435
|
stdio: 'pipe'
|
|
434
436
|
});
|
|
435
437
|
|
|
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
|
+
}
|
|
461
|
+
|
|
462
|
+
// ✅ LIMPAR supabase/functions após copiar
|
|
463
|
+
try {
|
|
464
|
+
await fs.rm(tempDownloadDir, { recursive: true, force: true });
|
|
465
|
+
} catch (cleanError) {
|
|
466
|
+
// Ignorar erro de limpeza
|
|
467
|
+
}
|
|
468
|
+
|
|
436
469
|
console.log(chalk.green(` ✅ ${func.name} baixada com sucesso`));
|
|
437
470
|
successCount++;
|
|
438
471
|
|