UNPKG

structure-validation

Version:

A Node.js CLI tool for validating codebase folder and file structure using a clean declarative configuration. Part of the guardz ecosystem for comprehensive TypeScript development.

104 lines 4.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidationOrchestrator = void 0; const ValidationService_1 = require("../../domain/services/ValidationService"); const ConfigService_1 = require("./ConfigService"); const FileDiscoveryService_1 = require("./FileDiscoveryService"); const GitService_1 = require("./GitService"); const ProgressIndicator_1 = require("../../infrastructure/output/ProgressIndicator"); /** * Application service that orchestrates the validation process */ class ValidationOrchestrator { constructor(configPath) { this.validationService = new ValidationService_1.ValidationService(); this.configService = new ConfigService_1.ConfigService(configPath); this.fileDiscoveryService = new FileDiscoveryService_1.FileDiscoveryService(); this.gitService = new GitService_1.GitService(); this.progressIndicator = new ProgressIndicator_1.ProgressIndicator(); } /** * Get file discovery service with config root */ async getFileDiscoveryService() { const config = await this.configService.loadConfig(); if (config.root) { return new FileDiscoveryService_1.FileDiscoveryService(process.cwd(), config.root); } return this.fileDiscoveryService; } /** * Validate all files in the codebase */ async validateAllFiles(verifyRoot = false) { this.progressIndicator.showFileDiscovery(); const fileDiscoveryService = await this.getFileDiscoveryService(); const config = await this.configService.loadConfig(); const files = await fileDiscoveryService.discoverAllFiles(); this.progressIndicator.start(files.length, 'Validating all files'); const result = this.validationService.validateFiles(files, config.rules, verifyRoot); this.progressIndicator.complete(); return result; } /** * Validate files based on scope */ async validateFilesByScope(scope, verifyRoot = false) { const fileDiscoveryService = await this.getFileDiscoveryService(); const config = await this.configService.loadConfig(); if (scope === 'all') { return this.validateAllFiles(verifyRoot); } // Check if we're in a git repository const isGitRepo = await this.gitService.isGitRepository(); if (!isGitRepo) { throw new Error(`--${scope} option requires a git repository`); } this.progressIndicator.showGitProgress(`Getting ${scope} files`); let gitDiff; switch (scope) { case 'staged': gitDiff = await this.gitService.getStagedFiles(); break; case 'changes': gitDiff = await this.gitService.getAllChangedFiles(); break; default: throw new Error(`Invalid scope: ${scope}`); } if (!gitDiff.hasChanges) { console.log('✅ No files to validate'); return { isValid: true, errors: [], suggestions: [] }; } this.progressIndicator.showFileDiscovery(); const files = await fileDiscoveryService.discoverFilesFromPaths(gitDiff.changedFiles); this.progressIndicator.start(files.length, `Validating ${scope} files`); const result = this.validationService.validateFiles(files, config.rules, verifyRoot); this.progressIndicator.complete(); return result; } /** * Validate specific files */ async validateSpecificFiles(filePaths, verifyRoot = false) { const fileDiscoveryService = await this.getFileDiscoveryService(); const config = await this.configService.loadConfig(); const files = await fileDiscoveryService.discoverFilesFromPaths(filePaths); this.progressIndicator.start(files.length, 'Validating specific files'); const result = this.validationService.validateFiles(files, config.rules, verifyRoot); this.progressIndicator.complete(); return result; } /** * Check if we're in a git repository */ async isGitRepository() { return this.gitService.isGitRepository(); } } exports.ValidationOrchestrator = ValidationOrchestrator; //# sourceMappingURL=ValidationOrchestrator.js.map