UNPKG

@boundless-oss/atlas

Version:

Atlas - MCP Server for comprehensive startup project management

106 lines 3.66 kB
import { promises as fs } from 'fs'; import path from 'path'; export class NodeFileSystemAdapter { async readdir(dirPath) { return await fs.readdir(dirPath, { withFileTypes: true }); } async stat(filePath) { return await fs.stat(filePath); } async access(filePath) { await fs.access(filePath); } async readFile(filePath, encoding) { return await fs.readFile(filePath, { encoding: encoding }); } async writeFile(filePath, content) { await fs.writeFile(filePath, content); } } export class InMemoryFileSystemAdapter { directories = new Map(); files = new Map(); dirStats = new Set(); constructor() { // Initialize with root directory this.directories.set('/', []); this.dirStats.add('/'); } async readdir(dirPath) { const normalizedPath = path.normalize(dirPath); const entries = this.directories.get(normalizedPath); if (!entries) { throw new Error(`ENOENT: no such file or directory, scandir '${dirPath}'`); } return entries; } async stat(filePath) { const normalizedPath = path.normalize(filePath); return { isDirectory: () => this.dirStats.has(normalizedPath) }; } async access(filePath) { const normalizedPath = path.normalize(filePath); if (!this.files.has(normalizedPath) && !this.dirStats.has(normalizedPath)) { throw new Error(`ENOENT: no such file or directory, access '${filePath}'`); } } async readFile(filePath, encoding) { const normalizedPath = path.normalize(filePath); const content = this.files.get(normalizedPath); if (content === undefined) { throw new Error(`ENOENT: no such file or directory, open '${filePath}'`); } return content; } async writeFile(filePath, content) { const normalizedPath = path.normalize(filePath); this.files.set(normalizedPath, content); } // Test helper methods addDirectory(dirPath, entries) { const normalizedPath = path.normalize(dirPath); // Add the directory itself this.dirStats.add(normalizedPath); // Create mock directory entries const mockEntries = entries.map(entry => ({ name: entry.name, isDirectory: () => entry.isDirectory })); this.directories.set(normalizedPath, mockEntries); // Add subdirectories to dirStats entries.forEach(entry => { if (entry.isDirectory) { const subPath = path.join(normalizedPath, entry.name); this.dirStats.add(subPath); } }); } addGitDirectory(dirPath) { const normalizedPath = path.normalize(dirPath); const gitPath = path.join(normalizedPath, '.git'); // Mark the .git path as accessible this.dirStats.add(gitPath); // Also update parent directory entries if it exists const parentEntries = this.directories.get(normalizedPath); if (parentEntries) { const hasGit = parentEntries.some(e => e.name === '.git'); if (!hasGit) { parentEntries.push({ name: '.git', isDirectory: () => true }); } } } clear() { this.directories.clear(); this.files.clear(); this.dirStats.clear(); // Re-initialize with root this.directories.set('/', []); this.dirStats.add('/'); } } //# sourceMappingURL=file-system-adapter.js.map