UNPKG

tdd-guard

Version:

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

71 lines (70 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GuardManager = void 0; const FileStorage_1 = require("../storage/FileStorage"); const minimatch_1 = require("minimatch"); const guardSchemas_1 = require("../contracts/schemas/guardSchemas"); class GuardManager { storage; minimatchOptions = { matchBase: true, // allows *.ext to match in any directory nobrace: false, // enables brace expansion {a,b} dot: true, // allows patterns to match files/dirs starting with . }; static DEFAULT_IGNORE_PATTERNS = [ '*.md', '*.txt', '*.log', '*.json', '*.yml', '*.yaml', '*.xml', '*.html', '*.css', '*.rst', ]; constructor(storage) { this.storage = storage ?? new FileStorage_1.FileStorage(); } async isEnabled() { const config = await this.getConfig(); return config?.guardEnabled ?? true; } async enable() { await this.setGuardEnabled(true); } async disable() { await this.setGuardEnabled(false); } async getIgnorePatterns() { const config = await this.getConfig(); return config?.ignorePatterns ?? GuardManager.DEFAULT_IGNORE_PATTERNS; } async shouldIgnoreFile(filePath) { const patterns = await this.getIgnorePatterns(); return patterns.some((pattern) => (0, minimatch_1.minimatch)(filePath, pattern, this.minimatchOptions)); } async setGuardEnabled(enabled) { const existingConfig = await this.getConfig(); const config = { ...existingConfig, guardEnabled: enabled, }; await this.storage.saveConfig(JSON.stringify(config)); } async getConfig() { const configString = await this.storage.getConfig(); if (!configString) { return null; } try { const parsed = JSON.parse(configString); return guardSchemas_1.GuardConfigSchema.parse(parsed); } catch { // Return null for invalid JSON or schema validation errors return null; } } } exports.GuardManager = GuardManager;