UNPKG

tops-bmad

Version:

CLI tool to install BMAD workflow files into any project with integrated Shai-Hulud 2.0 security scanning

56 lines (50 loc) 1.61 kB
import fs from "fs-extra"; import path from "path"; /** * Removes old BMAD related files and directories * Preserves config.yaml if it exists * @returns {Promise<void>} */ export async function cleanupOldFiles() { // Backup config.yaml if it exists const configPath = path.join(process.cwd(), ".bmad", "bmm", "config.yaml"); let configBackup = null; const configBackupPath = path.join(process.cwd(), "bmad-config-backup.yaml"); if (await fs.pathExists(configPath)) { try { configBackup = await fs.readFile(configPath, "utf8"); await fs.writeFile(configBackupPath, configBackup, "utf8"); } catch (error) { console.warn(`⚠️ Warning: Could not backup config.yaml: ${error.message}`); } } const paths = [ "./bmad", "./.bmad", "./.cursor/rules/bmad", "./bmad-temp", "./bmad-temp-decrypted.zip" ]; for (const p of paths) { try { if (await fs.pathExists(p)) { console.log(`🧹 Removing: ${p}`); await fs.remove(p); } } catch (error) { console.warn(`⚠️ Warning: Could not remove ${p}: ${error.message}`); } } // Restore config.yaml backup if it existed if (configBackup) { try { const configDir = path.join(process.cwd(), ".bmad", "bmm"); await fs.ensureDir(configDir); await fs.writeFile(configPath, configBackup, "utf8"); await fs.remove(configBackupPath); console.log("✅ Preserved existing configuration file"); } catch (error) { console.warn(`⚠️ Warning: Could not restore config.yaml: ${error.message}`); } } }