UNPKG

@boundless-oss/atlas

Version:

Atlas - MCP Server for comprehensive startup project management

84 lines 2.69 kB
import { promises as fs } from 'fs'; export class NodeFileSystemAdapter { fs = fs; async writeFile(path, content, encoding) { await this.fs.writeFile(path, content, { encoding: encoding }); } async readFile(path, encoding) { return await this.fs.readFile(path, { encoding: encoding }); } async mkdir(path, options) { await this.fs.mkdir(path, options); } async access(path) { await this.fs.access(path); } async readdir(path) { return await this.fs.readdir(path); } } export class InMemoryFileSystemAdapter { files = new Map(); directories = new Set(); async writeFile(path, content, encoding) { const dir = path.substring(0, path.lastIndexOf('/')); if (dir && !this.directories.has(dir)) { throw new Error(`ENOENT: no such file or directory, open '${path}'`); } this.files.set(path, content); } async readFile(path, encoding) { const content = this.files.get(path); if (content === undefined) { throw new Error(`ENOENT: no such file or directory, open '${path}'`); } return content; } async mkdir(path, options) { if (options?.recursive) { const parts = path.split('/').filter(p => p); let currentPath = ''; for (const part of parts) { currentPath = currentPath ? `${currentPath}/${part}` : `/${part}`; this.directories.add(currentPath); } } else { this.directories.add(path); } } async access(path) { if (!this.files.has(path) && !this.directories.has(path)) { throw new Error(`ENOENT: no such file or directory, access '${path}'`); } } async readdir(path) { if (!this.directories.has(path)) { throw new Error(`ENOENT: no such file or directory, scandir '${path}'`); } const files = []; for (const [filePath] of this.files) { const dir = filePath.substring(0, filePath.lastIndexOf('/')); if (dir === path) { const fileName = filePath.substring(filePath.lastIndexOf('/') + 1); files.push(fileName); } } return files; } // Test helper methods clear() { this.files.clear(); this.directories.clear(); } hasFile(path) { return this.files.has(path); } hasDirectory(path) { return this.directories.has(path); } getFileContent(path) { return this.files.get(path); } } //# sourceMappingURL=file-system-adapter.js.map