UNPKG

@benyue1978/soloflow-mcp

Version:

A Model Context Protocol (MCP) server for project document management with 32 comprehensive prompts covering the complete software development lifecycle

76 lines 3.06 kB
import { join } from 'path'; import { validateProjectRoot, ensureSoloflowDirectory } from '../context.js'; import { SOLOFLOW_MDC_CONTENT } from '../resources/soloflow-content.js'; import { GIT_COMMIT_MDC_CONTENT } from '../resources/git-commit-content.js'; /** * Initialize project configuration */ export async function initHandler(args) { const { projectRoot } = args; // Validate project root const validation = validateProjectRoot(projectRoot); if (!validation.isValid) { throw new Error(validation.error); } const createdFiles = []; const skippedFiles = []; try { const fs = await import('fs/promises'); // Ensure .soloflow directory exists await ensureSoloflowDirectory(projectRoot); // Create .cursor/rules directory const cursorRulesDir = join(projectRoot, '.cursor', 'rules'); try { await fs.access(cursorRulesDir); } catch { await fs.mkdir(cursorRulesDir, { recursive: true }); } // Create soloflow.mdc file const soloflowMdcPath = join(cursorRulesDir, 'soloflow.mdc'); try { await fs.access(soloflowMdcPath); skippedFiles.push('.cursor/rules/soloflow.mdc'); } catch { await fs.writeFile(soloflowMdcPath, SOLOFLOW_MDC_CONTENT, 'utf-8'); createdFiles.push('.cursor/rules/soloflow.mdc'); } // Create git_commit.mdc file const gitCommitMdcPath = join(cursorRulesDir, 'git_commit.mdc'); try { await fs.access(gitCommitMdcPath); skippedFiles.push('.cursor/rules/git_commit.mdc'); } catch { await fs.writeFile(gitCommitMdcPath, GIT_COMMIT_MDC_CONTENT, 'utf-8'); createdFiles.push('.cursor/rules/git_commit.mdc'); } // Generate detailed message let message = ''; if (createdFiles.length > 0) { message += `✅ Created files: ${createdFiles.join(', ')}\\n`; } if (skippedFiles.length > 0) { message += `⚠️ Skipped existing files: ${skippedFiles.join(', ')}\\n`; message += ` These files already exist and were not overwritten.\\n`; } if (createdFiles.length === 0 && skippedFiles.length === 0) { message = 'ℹ️ No files were created or modified.'; } else if (createdFiles.length > 0 && skippedFiles.length === 0) { message += '🎉 Project initialization completed successfully!'; } else if (createdFiles.length === 0 && skippedFiles.length > 0) { message += 'ℹ️ Project is already initialized. All required files exist.'; } else { message += '🔄 Project initialization completed with some existing files preserved.'; } return { ok: true, createdFiles, skippedFiles, message }; } catch (error) { throw new Error(`Error initializing project: ${error}`); } } //# sourceMappingURL=init.js.map