archunit
Version:
ArchUnit TypeScript is an architecture testing library, to specify and assert architecture rules in your TypeScript app
138 lines • 4.03 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColorUtils = void 0;
/**
* ANSI color codes for terminal output formatting
* Inspired by popular testing frameworks like Jest, Mocha, and Vitest
*/
class ColorUtils {
/**
* Check if colors should be disabled (CI environments, non-TTY, etc.)
*/
static get shouldUseColors() {
// Check for common environment variables that indicate no color support
if (process.env.NO_COLOR || process.env.CI === 'true') {
return false;
}
// Check if stdout is a TTY (terminal)
if (process.stdout && typeof process.stdout.isTTY === 'boolean') {
return process.stdout.isTTY;
}
// Default to true for better developer experience
return true;
}
/**
* Apply color formatting if colors are supported
*/
static colorize(text, colorCode) {
if (!this.shouldUseColors) {
return text;
}
return `${colorCode}${text}${this.RESET}`;
}
// Public color methods
static red(text) {
return this.colorize(text, this.RED);
}
static green(text) {
return this.colorize(text, this.GREEN);
}
static yellow(text) {
return this.colorize(text, this.YELLOW);
}
static blue(text) {
return this.colorize(text, this.BLUE);
}
static magenta(text) {
return this.colorize(text, this.MAGENTA);
}
static cyan(text) {
return this.colorize(text, this.CYAN);
}
static gray(text) {
return this.colorize(text, this.GRAY);
}
static dim(text) {
return this.colorize(text, this.DIM);
}
static bold(text) {
return this.colorize(text, this.BOLD);
}
static redBold(text) {
return this.colorize(text, this.BOLD + this.RED);
}
static greenBold(text) {
return this.colorize(text, this.BOLD + this.GREEN);
}
/**
* Format a clickable file path with colors
* File path in blue, line:column numbers in gray/dim
*/
static formatFilePath(filePath) {
// Split the path and line:column info
const parts = filePath.split(':');
if (parts.length >= 3) {
// We have file:line:column format
const file = parts.slice(0, -2).join(':'); // Handle paths with colons and ensure forward slashes
const line = parts[parts.length - 2];
const column = parts[parts.length - 1];
return `${this.blue(file)}${this.gray(`:${line}:${column}`)}`;
}
// Fallback: just color the whole path blue and ensure forward slashes
return this.blue(filePath);
}
/**
* Format a violation number (e.g., "1.", "2.")
*/
static formatViolationNumber(number) {
return this.redBold(number);
}
/**
* Format a violation type/category
*/
static formatViolationType(type) {
return this.red(type);
}
/**
* Format rule descriptions
*/
static formatRule(rule) {
return this.yellow(rule);
}
/**
* Format metric values
*/
static formatMetricValue(value) {
return this.cyan(value);
}
/**
* Format success messages
*/
static formatSuccess(message) {
return this.green(message);
}
/**
* Format error summary headers
*/
static formatErrorSummary(message) {
return this.redBold(message);
}
}
exports.ColorUtils = ColorUtils;
// Color codes
ColorUtils.RESET = '\x1b[0m';
ColorUtils.BOLD = '\x1b[1m';
ColorUtils.DIM = '\x1b[2m';
// Text colors
ColorUtils.RED = '\x1b[31m';
ColorUtils.GREEN = '\x1b[32m';
ColorUtils.YELLOW = '\x1b[33m';
ColorUtils.BLUE = '\x1b[34m';
ColorUtils.MAGENTA = '\x1b[35m';
ColorUtils.CYAN = '\x1b[36m';
ColorUtils.WHITE = '\x1b[37m';
ColorUtils.GRAY = '\x1b[90m';
// Background colors
ColorUtils.BG_RED = '\x1b[41m';
ColorUtils.BG_GREEN = '\x1b[42m';
//# sourceMappingURL=color-utils.js.map