@tryloop/oats
Version:
🌾 OATS - OpenAPI TypeScript Sync. The missing link between your OpenAPI specs and TypeScript applications. Automatically watch, generate, and sync TypeScript clients from your API definitions.
72 lines • 2.1 kB
JavaScript
import chalk from 'chalk';
import { PlatformUtils } from './platform.js';
import { Logger, LogLevel } from './logger.js';
export class DebugManager {
static isDebugMode = false;
/**
* Initialize debug mode based on environment or config
*/
static init(debug) {
this.isDebugMode = debug || process.env['OATS_DEBUG'] === 'true';
if (this.isDebugMode) {
Logger.setLogLevel(LogLevel.DEBUG);
console.log(chalk.magenta('🐛 Debug mode enabled'));
this.printPlatformInfo();
}
}
/**
* Check if debug mode is enabled
*/
static isEnabled() {
return this.isDebugMode;
}
/**
* Print platform debug information
*/
static printPlatformInfo() {
const info = PlatformUtils.getDebugInfo();
console.log(chalk.dim('Platform Information:'));
console.log(chalk.dim(JSON.stringify(info, null, 2)));
}
/**
* Debug log helper
*/
static log(message, data) {
if (this.isDebugMode) {
const timestamp = new Date().toISOString();
console.log(chalk.gray(`[${timestamp}] ${message}`));
if (data) {
console.log(chalk.gray(JSON.stringify(data, null, 2)));
}
}
}
/**
* Create a debug section
*/
static section(title) {
if (this.isDebugMode) {
console.log(chalk.cyan(`\n=== ${title} ===`));
}
}
/**
* Time a function execution
*/
static async time(label, fn) {
if (!this.isDebugMode) {
return fn();
}
const start = Date.now();
try {
const result = await fn();
const duration = Date.now() - start;
console.log(chalk.gray(`⏱️ ${label}: ${duration}ms`));
return result;
}
catch (error) {
const duration = Date.now() - start;
console.log(chalk.red(`⏱️ ${label}: ${duration}ms (failed)`));
throw error;
}
}
}
//# sourceMappingURL=debug.js.map