add confirmation if removing ALL rules profiles, and add --force flag on rules remove

This commit is contained in:
Joe Danziger
2025-05-26 22:09:45 -04:00
parent bd81d00169
commit 36e8257d08
7 changed files with 318 additions and 5 deletions

View File

@@ -31,4 +31,49 @@ This will remove the entire .[profile] directory for each selected profile.\n\nA
return confirm;
}
export { confirmProfilesRemove };
/**
* Confirm removing ALL remaining profile rules (extremely critical operation)
* @param {string[]} profiles - Array of profile names to remove
* @param {string[]} remainingProfiles - Array of profiles that would be left after removal
* @returns {Promise<boolean>} - Promise resolving to true if user confirms, false otherwise
*/
async function confirmRemoveAllRemainingProfiles(profiles, remainingProfiles) {
const profileList = profiles
.map((p) => p.charAt(0).toUpperCase() + p.slice(1))
.join(', ');
console.log(
boxen(
chalk.red.bold(
`⚠️ CRITICAL WARNING: REMOVING ALL RULES PROFILES ⚠️\n\n` +
`You are about to remove: ${profileList}\n` +
`This will leave your project with NO rules profiles remaining!\n\n` +
`This could significantly impact functionality and development experience:\n` +
`• Loss of IDE-specific rules and conventions\n` +
`• No MCP configurations for AI assistants\n` +
`• Reduced development guidance and best practices\n\n` +
`Are you absolutely sure you want to proceed?`
),
{
padding: 1,
borderColor: 'red',
borderStyle: 'double',
title: '🚨 CRITICAL OPERATION',
titleAlignment: 'center'
}
)
);
const inquirer = await import('inquirer');
const { confirm } = await inquirer.default.prompt([
{
type: 'confirm',
name: 'confirm',
message: 'Type y to confirm removing ALL rules profiles, or n to abort:',
default: false
}
]);
return confirm;
}
export { confirmProfilesRemove, confirmRemoveAllRemainingProfiles };

View File

@@ -0,0 +1,48 @@
/**
* Rules Detection Utility
* Helper functions to detect existing rules profiles in a project
*/
import fs from 'fs';
import path from 'path';
import { RULES_PROFILES } from '../constants/profiles.js';
import { getRulesProfile } from './rule-transformer.js';
/**
* Detect which rules profiles are currently installed in the project
* @param {string} projectRoot - Project root directory
* @returns {string[]} Array of installed profile names
*/
export function getInstalledRulesProfiles(projectRoot) {
const installedProfiles = [];
for (const profileName of RULES_PROFILES) {
const profileConfig = getRulesProfile(profileName);
if (!profileConfig) continue;
// Check if the profile directory exists
const profileDir = path.join(projectRoot, profileConfig.profileDir);
const rulesDir = path.join(projectRoot, profileConfig.rulesDir);
// A profile is considered installed if either the profile dir or rules dir exists
if (fs.existsSync(profileDir) || fs.existsSync(rulesDir)) {
installedProfiles.push(profileName);
}
}
return installedProfiles;
}
/**
* Check if removing the specified profiles would result in no rules profiles remaining
* @param {string} projectRoot - Project root directory
* @param {string[]} profilesToRemove - Array of profile names to remove
* @returns {boolean} True if removal would result in no profiles remaining
*/
export function wouldRemovalLeaveNoProfiles(projectRoot, profilesToRemove) {
const installedProfiles = getInstalledRulesProfiles(projectRoot);
const remainingProfiles = installedProfiles.filter(
(profile) => !profilesToRemove.includes(profile)
);
return remainingProfiles.length === 0 && installedProfiles.length > 0;
}