fix formatting
This commit is contained in:
@@ -3,28 +3,95 @@ import path from 'path';
|
|||||||
import { log } from './utils.js';
|
import { log } from './utils.js';
|
||||||
|
|
||||||
// Structure matches project conventions (see scripts/init.js)
|
// Structure matches project conventions (see scripts/init.js)
|
||||||
export function setupMCPConfiguration(brandDir) {
|
export function setupMCPConfiguration(configDir) {
|
||||||
const mcpPath = path.join(brandDir, 'mcp.json');
|
const mcpPath = path.join(configDir, 'mcp.json');
|
||||||
const mcpConfig = {
|
// New MCP config to be added - references the installed package
|
||||||
"task-master-ai": {
|
const newMCPServer = {
|
||||||
command: "npx",
|
'task-master-ai': {
|
||||||
args: ["-y", "--package=task-master-ai", "task-master-ai"],
|
command: 'npx',
|
||||||
env: {
|
args: ['-y', '--package=task-master-ai', 'task-master-ai'],
|
||||||
ANTHROPIC_API_KEY: "ANTHROPIC_API_KEY_HERE",
|
env: {
|
||||||
PERPLEXITY_API_KEY: "PERPLEXITY_API_KEY_HERE",
|
ANTHROPIC_API_KEY: 'ANTHROPIC_API_KEY_HERE',
|
||||||
OPENAI_API_KEY: "OPENAI_API_KEY_HERE",
|
PERPLEXITY_API_KEY: 'PERPLEXITY_API_KEY_HERE',
|
||||||
GOOGLE_API_KEY: "GOOGLE_API_KEY_HERE",
|
OPENAI_API_KEY: 'OPENAI_API_KEY_HERE',
|
||||||
XAI_API_KEY: "XAI_API_KEY_HERE",
|
GOOGLE_API_KEY: 'GOOGLE_API_KEY_HERE',
|
||||||
OPENROUTER_API_KEY: "OPENROUTER_API_KEY_HERE",
|
XAI_API_KEY: 'XAI_API_KEY_HERE',
|
||||||
MISTRAL_API_KEY: "MISTRAL_API_KEY_HERE",
|
OPENROUTER_API_KEY: 'OPENROUTER_API_KEY_HERE',
|
||||||
AZURE_OPENAI_API_KEY: "AZURE_OPENAI_API_KEY_HERE"
|
MISTRAL_API_KEY: 'MISTRAL_API_KEY_HERE',
|
||||||
}
|
AZURE_OPENAI_API_KEY: 'AZURE_OPENAI_API_KEY_HERE',
|
||||||
}
|
OLLAMA_API_KEY: 'OLLAMA_API_KEY_HERE'
|
||||||
};
|
}
|
||||||
try {
|
}
|
||||||
fs.writeFileSync(mcpPath, JSON.stringify(mcpConfig, null, 2));
|
};
|
||||||
log('success', `Created MCP configuration: ${mcpPath}`);
|
// Create config directory if it doesn't exist
|
||||||
} catch (e) {
|
if (!fs.existsSync(configDir)) {
|
||||||
log('warn', `Failed to create MCP configuration at ${mcpPath}: ${e.message}`);
|
fs.mkdirSync(configDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
if (fs.existsSync(mcpPath)) {
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
'MCP configuration file already exists, checking for existing task-master-ai...'
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
// Read existing config
|
||||||
|
const mcpConfig = JSON.parse(fs.readFileSync(mcpPath, 'utf8'));
|
||||||
|
// Initialize mcpServers if it doesn't exist
|
||||||
|
if (!mcpConfig.mcpServers) {
|
||||||
|
mcpConfig.mcpServers = {};
|
||||||
|
}
|
||||||
|
// Check if any existing server configuration already has task-master-ai in its args
|
||||||
|
const hasMCPString = Object.values(mcpConfig.mcpServers).some(
|
||||||
|
(server) =>
|
||||||
|
server.args &&
|
||||||
|
server.args.some(
|
||||||
|
(arg) => typeof arg === 'string' && arg.includes('task-master-ai')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (hasMCPString) {
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
'Found existing task-master-ai MCP configuration in mcp.json, leaving untouched'
|
||||||
|
);
|
||||||
|
return; // Exit early, don't modify the existing configuration
|
||||||
|
}
|
||||||
|
// Add the task-master-ai server if it doesn't exist
|
||||||
|
if (!mcpConfig.mcpServers['task-master-ai']) {
|
||||||
|
mcpConfig.mcpServers['task-master-ai'] = newMCPServer['task-master-ai'];
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
'Added task-master-ai server to existing MCP configuration'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log('info', 'task-master-ai server already configured in mcp.json');
|
||||||
|
}
|
||||||
|
// Write the updated configuration
|
||||||
|
fs.writeFileSync(mcpPath, JSON.stringify(mcpConfig, null, 4));
|
||||||
|
log('success', 'Updated MCP configuration file');
|
||||||
|
} catch (error) {
|
||||||
|
log('error', `Failed to update MCP configuration: ${error.message}`);
|
||||||
|
// Create a backup before potentially modifying
|
||||||
|
const backupPath = `${mcpPath}.backup-${Date.now()}`;
|
||||||
|
if (fs.existsSync(mcpPath)) {
|
||||||
|
fs.copyFileSync(mcpPath, backupPath);
|
||||||
|
log('info', `Created backup of existing mcp.json at ${backupPath}`);
|
||||||
|
}
|
||||||
|
// Create new configuration
|
||||||
|
const newMCPConfig = {
|
||||||
|
mcpServers: newMCPServer
|
||||||
|
};
|
||||||
|
fs.writeFileSync(mcpPath, JSON.stringify(newMCPConfig, null, 4));
|
||||||
|
log(
|
||||||
|
'warn',
|
||||||
|
'Created new MCP configuration file (backup of original file was created if it existed)'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If mcp.json doesn't exist, create it
|
||||||
|
const newMCPConfig = {
|
||||||
|
mcpServers: newMCPServer
|
||||||
|
};
|
||||||
|
fs.writeFileSync(mcpPath, JSON.stringify(newMCPConfig, null, 4));
|
||||||
|
log('success', 'Created MCP configuration file');
|
||||||
|
}
|
||||||
|
log('info', 'MCP server will use the installed task-master-ai package');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import { log } from './utils.js';
|
|||||||
// Import the shared MCP configuration helper
|
// Import the shared MCP configuration helper
|
||||||
import { setupMCPConfiguration } from './mcp-utils.js';
|
import { setupMCPConfiguration } from './mcp-utils.js';
|
||||||
|
|
||||||
|
|
||||||
// Import Roo Code conversionConfig and fileMap from profiles
|
// Import Roo Code conversionConfig and fileMap from profiles
|
||||||
import { conversionConfig, fileMap } from '../profiles/roo.js';
|
import { conversionConfig, fileMap } from '../profiles/roo.js';
|
||||||
|
|
||||||
@@ -100,7 +99,11 @@ function updateFileReferences(content) {
|
|||||||
* Main transformation function that applies all conversions
|
* Main transformation function that applies all conversions
|
||||||
*/
|
*/
|
||||||
// Main transformation function that applies all conversions, now brand-generic
|
// Main transformation function that applies all conversions, now brand-generic
|
||||||
function transformCursorToBrandRules(content, conversionConfig, globalReplacements = []) {
|
function transformCursorToBrandRules(
|
||||||
|
content,
|
||||||
|
conversionConfig,
|
||||||
|
globalReplacements = []
|
||||||
|
) {
|
||||||
// Apply all transformations in appropriate order
|
// Apply all transformations in appropriate order
|
||||||
let result = content;
|
let result = content;
|
||||||
result = replaceBasicTerms(result, conversionConfig);
|
result = replaceBasicTerms(result, conversionConfig);
|
||||||
@@ -137,7 +140,11 @@ function convertCursorRuleToBrandRule(sourcePath, targetPath, profile) {
|
|||||||
const content = fs.readFileSync(sourcePath, 'utf8');
|
const content = fs.readFileSync(sourcePath, 'utf8');
|
||||||
|
|
||||||
// Transform content
|
// Transform content
|
||||||
const transformedContent = transformCursorToBrandRules(content, conversionConfig, globalReplacements);
|
const transformedContent = transformCursorToBrandRules(
|
||||||
|
content,
|
||||||
|
conversionConfig,
|
||||||
|
globalReplacements
|
||||||
|
);
|
||||||
|
|
||||||
// Ensure target directory exists
|
// Ensure target directory exists
|
||||||
const targetDir = path.dirname(targetPath);
|
const targetDir = path.dirname(targetPath);
|
||||||
@@ -168,7 +175,7 @@ function convertCursorRuleToBrandRule(sourcePath, targetPath, profile) {
|
|||||||
function convertAllCursorRulesToBrandRules(projectDir, profile) {
|
function convertAllCursorRulesToBrandRules(projectDir, profile) {
|
||||||
const { fileMap, brandName, rulesDir } = profile;
|
const { fileMap, brandName, rulesDir } = profile;
|
||||||
// Use assets/rules as the source of rules instead of .cursor/rules
|
// Use assets/rules as the source of rules instead of .cursor/rules
|
||||||
const cursorRulesDir = path.join(projectDir, 'assets', 'rules');
|
const cursorRulesDir = path.join(projectDir, 'assets', 'rules');
|
||||||
const brandRulesDir = path.join(projectDir, rulesDir);
|
const brandRulesDir = path.join(projectDir, rulesDir);
|
||||||
|
|
||||||
if (!fs.existsSync(cursorRulesDir)) {
|
if (!fs.existsSync(cursorRulesDir)) {
|
||||||
@@ -220,42 +227,48 @@ const cursorRulesDir = path.join(projectDir, 'assets', 'rules');
|
|||||||
* @returns {boolean} - True if removal succeeded, false otherwise
|
* @returns {boolean} - True if removal succeeded, false otherwise
|
||||||
*/
|
*/
|
||||||
function removeBrandRules(projectDir, profile) {
|
function removeBrandRules(projectDir, profile) {
|
||||||
const { brandName, rulesDir } = profile;
|
const { brandName, rulesDir } = profile;
|
||||||
const brandRulesDir = path.join(projectDir, rulesDir);
|
const brandRulesDir = path.join(projectDir, rulesDir);
|
||||||
const brandDir = path.dirname(brandRulesDir);
|
const brandDir = path.dirname(brandRulesDir);
|
||||||
// Also remove the mcp.json file if it exists in the brand directory
|
// Also remove the mcp.json file if it exists in the brand directory
|
||||||
const mcpPath = path.join(brandDir, 'mcp.json');
|
const mcpPath = path.join(brandDir, 'mcp.json');
|
||||||
if (fs.existsSync(mcpPath)) {
|
if (fs.existsSync(mcpPath)) {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(mcpPath);
|
fs.unlinkSync(mcpPath);
|
||||||
log('info', `Removed MCP configuration: ${mcpPath}`);
|
log('info', `Removed MCP configuration: ${mcpPath}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('warn', `Failed to remove MCP configuration at ${mcpPath}: ${e.message}`);
|
log(
|
||||||
}
|
'warn',
|
||||||
}
|
`Failed to remove MCP configuration at ${mcpPath}: ${e.message}`
|
||||||
// Do not allow removal of the default Cursor rules directory
|
);
|
||||||
if (brandName.toLowerCase() === 'cursor') {
|
}
|
||||||
log('warn', 'Cannot remove default Cursor rules directory. Skipping.');
|
}
|
||||||
return false;
|
// Do not allow removal of the default Cursor rules directory
|
||||||
}
|
if (brandName.toLowerCase() === 'cursor') {
|
||||||
if (fs.existsSync(brandRulesDir)) {
|
log('warn', 'Cannot remove default Cursor rules directory. Skipping.');
|
||||||
fs.rmSync(brandRulesDir, { recursive: true, force: true });
|
return false;
|
||||||
log('info', `Removed rules directory: ${brandRulesDir}`);
|
}
|
||||||
// Check if parent brand folder is empty
|
if (fs.existsSync(brandRulesDir)) {
|
||||||
if (
|
fs.rmSync(brandRulesDir, { recursive: true, force: true });
|
||||||
fs.existsSync(brandDir) &&
|
log('info', `Removed rules directory: ${brandRulesDir}`);
|
||||||
path.basename(brandDir) !== '.cursor' &&
|
// Check if parent brand folder is empty
|
||||||
fs.readdirSync(brandDir).length === 0
|
if (
|
||||||
) {
|
fs.existsSync(brandDir) &&
|
||||||
fs.rmdirSync(brandDir);
|
path.basename(brandDir) !== '.cursor' &&
|
||||||
log('info', `Removed empty brand folder: ${brandDir}`);
|
fs.readdirSync(brandDir).length === 0
|
||||||
}
|
) {
|
||||||
return true;
|
fs.rmdirSync(brandDir);
|
||||||
} else {
|
log('info', `Removed empty brand folder: ${brandDir}`);
|
||||||
log('warn', `Rules directory not found: ${brandRulesDir}`);
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
} else {
|
||||||
|
log('warn', `Rules directory not found: ${brandRulesDir}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { convertAllCursorRulesToBrandRules, convertCursorRuleToBrandRule, removeBrandRules };
|
export {
|
||||||
|
convertAllCursorRulesToBrandRules,
|
||||||
|
convertCursorRuleToBrandRule,
|
||||||
|
removeBrandRules
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user