- Set up TypeScript project with strict mode - Configure tsup build system (ESM output) - Configure vitest for testing (36 tests passing) - Configure ESLint with flat config for TypeScript - Implement Commander.js CLI with all 4 commands: - init: Configure API keys with validation - new: Create new Ralph Method project (stub) - validate: Validate PROMPT.md files - research: Research topics via Perplexity (stub) - Implement config management: - Keys stored in ~/.ralph-generator/config.json - File permissions set to 600 - Environment variables override file config - Implement logging utility with verbosity levels - Implement atomic file writes utility All Phase 1 acceptance criteria met. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
68 lines
1.4 KiB
TypeScript
68 lines
1.4 KiB
TypeScript
import chalk from 'chalk';
|
|
|
|
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
|
|
const LOG_LEVELS: Record<LogLevel, number> = {
|
|
debug: 0,
|
|
info: 1,
|
|
warn: 2,
|
|
error: 3,
|
|
};
|
|
|
|
let currentLevel: LogLevel = 'info';
|
|
|
|
export function setLogLevel(level: LogLevel): void {
|
|
currentLevel = level;
|
|
}
|
|
|
|
export function getLogLevel(): LogLevel {
|
|
return currentLevel;
|
|
}
|
|
|
|
function shouldLog(level: LogLevel): boolean {
|
|
return LOG_LEVELS[level] >= LOG_LEVELS[currentLevel];
|
|
}
|
|
|
|
export function debug(message: string, ...args: unknown[]): void {
|
|
if (shouldLog('debug')) {
|
|
console.log(chalk.gray(`[DEBUG] ${message}`), ...args);
|
|
}
|
|
}
|
|
|
|
export function info(message: string, ...args: unknown[]): void {
|
|
if (shouldLog('info')) {
|
|
console.log(chalk.blue(`[INFO] ${message}`), ...args);
|
|
}
|
|
}
|
|
|
|
export function warn(message: string, ...args: unknown[]): void {
|
|
if (shouldLog('warn')) {
|
|
console.log(chalk.yellow(`[WARN] ${message}`), ...args);
|
|
}
|
|
}
|
|
|
|
export function error(message: string, ...args: unknown[]): void {
|
|
if (shouldLog('error')) {
|
|
console.error(chalk.red(`[ERROR] ${message}`), ...args);
|
|
}
|
|
}
|
|
|
|
export function success(message: string, ...args: unknown[]): void {
|
|
console.log(chalk.green(message), ...args);
|
|
}
|
|
|
|
export function log(message: string, ...args: unknown[]): void {
|
|
console.log(message, ...args);
|
|
}
|
|
|
|
export const logger = {
|
|
debug,
|
|
info,
|
|
warn,
|
|
error,
|
|
success,
|
|
log,
|
|
setLevel: setLogLevel,
|
|
getLevel: getLogLevel,
|
|
};
|