sfcc-dev-mcp
Version:
MCP server for Salesforce B2C Commerce Cloud development assistance including logs, debugging, and development tools
74 lines • 1.93 kB
JavaScript
/**
* File System Service Interface and Implementation
*
* Provides an abstraction layer over Node.js file system operations
* to enable easier testing and better dependency injection.
*/
import * as fs from 'fs/promises';
/**
* Production implementation of file system service
*/
export class FileSystemService {
async exists(path) {
try {
await fs.access(path);
return true;
}
catch {
return false;
}
}
async mkdir(path, options) {
await fs.mkdir(path, options);
}
async writeFile(path, content) {
await fs.writeFile(path, content);
}
async readFile(path) {
return await fs.readFile(path, 'utf-8');
}
async access(path) {
await fs.access(path);
}
}
/**
* Mock implementation for testing
*/
export class MockFileSystemService {
mockFiles = new Map();
mockDirectories = new Set();
// Mock methods for testing setup
setMockFile(path, content) {
this.mockFiles.set(path, content);
}
setMockDirectory(path) {
this.mockDirectories.add(path);
}
clearMocks() {
this.mockFiles.clear();
this.mockDirectories.clear();
}
// Service implementation
async exists(path) {
return this.mockFiles.has(path) || this.mockDirectories.has(path);
}
async mkdir(path, _options) {
this.mockDirectories.add(path);
}
async writeFile(path, content) {
this.mockFiles.set(path, content);
}
async readFile(path) {
const content = this.mockFiles.get(path);
if (content === undefined) {
throw new Error(`File not found: ${path}`);
}
return content;
}
async access(path) {
if (!(await this.exists(path))) {
throw new Error(`Path not accessible: ${path}`);
}
}
}
//# sourceMappingURL=file-system-service.js.map