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.
84 lines • 3.1 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutputFormatter = void 0;
const chalk_1 = __importDefault(require("chalk"));
/**
* Infrastructure service for formatting validation output
*/
class OutputFormatter {
/**
* Format validation result for CLI output
*/
formatResult(result) {
const lines = [];
if (result.isValid) {
lines.push(chalk_1.default.green('✅ All files are properly structured!'));
return lines.join('\n');
}
// Format errors
if (result.errors.length > 0) {
lines.push(chalk_1.default.red(`❌ Found ${result.errors.length} validation error(s):`));
lines.push('');
for (const error of result.errors) {
lines.push(this.formatError(error));
lines.push('');
}
}
// Format suggestions
if (result.suggestions.length > 0) {
lines.push(chalk_1.default.yellow(`💡 ${result.suggestions.length} suggestion(s):`));
lines.push('');
for (const suggestion of result.suggestions) {
lines.push(this.formatSuggestion(suggestion));
lines.push('');
}
}
return lines.join('\n');
}
/**
* Format a validation error
*/
formatError(error) {
const lines = [];
lines.push(chalk_1.default.red(` ${error.file.relativePath}`));
lines.push(chalk_1.default.gray(` ${error.message}`));
if (error.expectedPatterns && error.expectedPatterns.length > 0) {
lines.push(chalk_1.default.gray(` Expected patterns: ${error.expectedPatterns.join(', ')}`));
}
if (error.expectedFolder) {
lines.push(chalk_1.default.gray(` Expected folder: ${error.expectedFolder}/`));
}
return lines.join('\n');
}
/**
* Format a validation suggestion
*/
formatSuggestion(suggestion) {
const lines = [];
lines.push(chalk_1.default.yellow(` ${suggestion.file.relativePath}`));
lines.push(chalk_1.default.gray(` ${suggestion.reason}`));
lines.push(chalk_1.default.cyan(` Move to: ${suggestion.suggestedFolder}/`));
return lines.join('\n');
}
/**
* Format a summary of the validation
*/
formatSummary(result) {
const lines = [];
if (result.isValid) {
lines.push(chalk_1.default.green('✅ Validation passed'));
}
else {
lines.push(chalk_1.default.red(`❌ Validation failed with ${result.errors.length} error(s)`));
if (result.suggestions.length > 0) {
lines.push(chalk_1.default.yellow(`💡 ${result.suggestions.length} suggestion(s) available`));
}
}
return lines.join('\n');
}
}
exports.OutputFormatter = OutputFormatter;
//# sourceMappingURL=OutputFormatter.js.map