scai
Version:
> AI-powered CLI tool for commit messages **and** pull request reviews — using local models.
29 lines (28 loc) • 1.02 kB
JavaScript
import fsp from 'fs/promises';
import path from 'path';
import { SCAI_HOME } from '../constants.js';
function getBackupDir() {
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
return path.join(SCAI_HOME, `backup-${timestamp}`);
}
export async function backupScaiFolder() {
const backupDir = getBackupDir();
try {
await fsp.mkdir(backupDir, { recursive: true });
const files = await fsp.readdir(SCAI_HOME);
for (const file of files) {
const srcPath = path.join(SCAI_HOME, file);
const destPath = path.join(backupDir, file);
const stat = await fsp.stat(srcPath);
if (stat.isFile()) {
await fsp.copyFile(srcPath, destPath);
}
}
console.log(`📦 Backed up .scai folder to: ${backupDir}`);
return backupDir;
}
catch (err) {
console.warn('⚠️ Failed to back up .scai folder:', err instanceof Error ? err.message : err);
return null;
}
}