apple-hig-mcp
Version:
High-performance MCP server providing instant access to Apple's Human Interface Guidelines via hybrid static/dynamic content delivery
54 lines • 1.59 kB
JavaScript
/**
* File System Service Implementation
* Single Responsibility: Handle all file system operations
*/
import { promises as fs } from 'fs';
import path from 'path';
export class FileSystemService {
async writeFile(filePath, content) {
// Ensure directory exists
const dir = path.dirname(filePath);
await this.mkdir(dir, { recursive: true });
await fs.writeFile(filePath, content, 'utf-8');
}
async readFile(filePath) {
return await fs.readFile(filePath, 'utf-8');
}
async mkdir(dirPath, options) {
await fs.mkdir(dirPath, options);
}
async readdir(dirPath) {
return await fs.readdir(dirPath);
}
async exists(filePath) {
try {
await fs.access(filePath);
return true;
}
catch {
return false;
}
}
async stat(filePath) {
return await fs.stat(filePath);
}
/**
* Calculate total size of directory recursively
*/
async calculateDirectorySize(dirPath) {
let totalSize = 0;
const files = await fs.readdir(dirPath, { withFileTypes: true });
for (const file of files) {
const fullPath = path.join(dirPath, file.name);
if (file.isDirectory()) {
totalSize += await this.calculateDirectorySize(fullPath);
}
else {
const stats = await fs.stat(fullPath);
totalSize += stats.size;
}
}
return totalSize;
}
}
//# sourceMappingURL=file-system.service.js.map