pr-sizewise
Version:
A CLI tool that measures and reports pull request sizes for GitHub and GitLab, helping teams maintain manageable code changes.
115 lines • 3.09 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
exports.createLogger = createLogger;
exports.createDefaultLogger = createDefaultLogger;
const chalk_1 = __importDefault(require("chalk"));
const errors_1 = require("./errors");
/**
* Enhanced logger that respects the verbose configuration
*/
class Logger {
constructor(config) {
const isVerbose = config.logging?.verbose ?? true;
// Always log errors and warnings, but only log info if verbose is enabled
this.error = console.error.bind(console);
this.warn = console.warn.bind(console);
this.log = isVerbose ? console.log.bind(console) : () => { };
}
/**
* Log info messages (respects verbose setting)
*/
info(...args) {
this.log(...args);
}
/**
* Log success messages (respects verbose setting)
*/
success(...args) {
this.log(chalk_1.default.green('✅'), ...args);
}
/**
* Log warning messages (always shown)
*/
warning(...args) {
this.warn(chalk_1.default.yellow('⚠'), ...args);
}
/**
* Log error messages with proper formatting and error codes
*/
logError(context, error) {
const { message, code } = (0, errors_1.handleError)(error);
this.error(chalk_1.default.red('❌'), chalk_1.default.red(context), chalk_1.default.dim(`[${code}]`), '\n', chalk_1.default.red(message));
}
/**
* Log a blank line
*/
blank() {
this.log('');
}
/**
* Log a section header
*/
header(text) {
this.blank();
this.log(chalk_1.default.bold(text));
this.log(chalk_1.default.dim('─'.repeat(text.length)));
}
/**
* Log a subheader
*/
subheader(text) {
this.blank();
this.log(chalk_1.default.bold(text));
this.log(chalk_1.default.dim('─'.repeat(20)));
}
/**
* Log a JSON object
*/
json(data) {
this.log(JSON.stringify(data, null, 2));
}
/**
* Log a dimmed message
*/
dim(...args) {
this.log(chalk_1.default.dim(...args));
}
}
exports.Logger = Logger;
/**
* Create a logger instance for the given configuration
*/
function createLogger(config) {
return new Logger(config);
}
/**
* Create a logger instance with default configuration
*/
function createDefaultLogger() {
return new Logger({
thresholds: {
small: {
files: 5,
lines: 50,
directories: 2,
},
medium: {
files: 10,
lines: 200,
directories: 4,
},
large: {
files: 20,
lines: 500,
directories: 8,
},
},
excludePatterns: [],
logging: { verbose: true },
});
}
//# sourceMappingURL=logger.js.map