UNPKG

mcp-casual-interview

Version:

MCP server for casual interview preparation workflow management

121 lines 3.81 kB
import { promises as fs } from 'fs'; import path from 'path'; import os from 'os'; import { ok, err } from 'neverthrow'; // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // File System Operations // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ /** * Get the data directory for storing application files */ export const getDataDirectory = () => { const homeDir = os.homedir(); return path.join(homeDir, '.mcp-casual-interview'); }; /** * Ensure directory exists, creating it if necessary */ export const ensureDirectory = async (dirPath) => { try { await fs.mkdir(dirPath, { recursive: true }); return ok(undefined); } catch (cause) { return err({ type: 'DirectoryCreationFailed', message: `ディレクトリの作成に失敗しました: ${dirPath}`, path: dirPath, cause }); } }; /** * Save data to JSON file */ export const saveJsonFile = async (filePath, data) => { try { const dir = path.dirname(filePath); const ensureResult = await ensureDirectory(dir); if (ensureResult.isErr()) { return err(ensureResult.error); } const jsonData = JSON.stringify(data, null, 2); await fs.writeFile(filePath, jsonData, 'utf-8'); return ok(undefined); } catch (cause) { return err({ type: 'FileWriteError', message: `ファイルの書き込みに失敗しました: ${filePath}`, path: filePath, cause }); } }; /** * Read JSON file and parse it */ export const readJsonFile = async (filePath) => { try { const fileContent = await fs.readFile(filePath, 'utf-8'); try { const data = JSON.parse(fileContent); return ok(data); } catch (parseError) { return err({ type: 'JsonParseError', message: `JSONの解析に失敗しました: ${filePath}`, path: filePath, cause: parseError }); } } catch (cause) { const nodeError = cause; if (nodeError.code === 'ENOENT') { return err({ type: 'FileNotFound', message: `ファイルが見つかりません: ${filePath}`, path: filePath, cause }); } if (nodeError.code === 'EACCES') { return err({ type: 'PermissionDenied', message: `ファイルへのアクセス権限がありません: ${filePath}`, path: filePath, cause }); } return err({ type: 'FileReadError', message: `ファイルの読み込みに失敗しました: ${filePath}`, path: filePath, cause }); } }; /** * Check if file exists */ export const fileExists = async (filePath) => { try { await fs.access(filePath); return ok(true); } catch (cause) { const nodeError = cause; if (nodeError.code === 'ENOENT') { return ok(false); } return err({ type: 'Unknown', message: `ファイル存在確認に失敗しました: ${filePath}`, path: filePath, cause }); } }; //# sourceMappingURL=filesystem.js.map