UNPKG

tdd-guard

Version:

TDD Guard enforces Test-Driven Development principles using Claude Code hooks

86 lines (85 loc) 2.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileStorage = void 0; const Storage_1 = require("./Storage"); const Config_1 = require("../config/Config"); const promises_1 = __importDefault(require("fs/promises")); class FileStorage { config; filePaths; constructor(config) { this.config = config ?? new Config_1.Config(); this.filePaths = { test: this.config.testResultsFilePath, todo: this.config.todosFilePath, modifications: this.config.modificationsFilePath, lint: this.config.lintFilePath, config: this.config.configFilePath, }; } async ensureDirectory() { await promises_1.default.mkdir(this.config.dataDir, { recursive: true }); } async save(type, content) { await this.ensureDirectory(); await promises_1.default.writeFile(this.filePaths[type], content); } async get(type) { try { return await promises_1.default.readFile(this.filePaths[type], 'utf-8'); } catch { return null; } } async saveTest(content) { await this.save('test', content); } async saveTodo(content) { await this.save('todo', content); } async saveModifications(content) { await this.save('modifications', content); } async saveLint(content) { await this.save('lint', content); } async saveConfig(content) { await this.save('config', content); } async getTest() { return this.get('test'); } async getTodo() { return this.get('todo'); } async getModifications() { return this.get('modifications'); } async getLint() { return this.get('lint'); } async getConfig() { return this.get('config'); } async clearTransientData() { await Promise.all(Storage_1.TRANSIENT_DATA.map((fileType) => this.deleteFileIfExists(this.filePaths[fileType]))); } async deleteFileIfExists(filePath) { try { await promises_1.default.unlink(filePath); } catch (error) { // Only ignore ENOENT errors (file not found) if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') { throw error; } } } } exports.FileStorage = FileStorage;