@gabimoncha/cursor-rules
Version:
A CLI for bootstrapping Cursor rules to a project
128 lines • 3.84 kB
JavaScript
import { intro, log, outro } from '@clack/prompts';
import util from 'node:util';
import pc from 'picocolors';
export const cursorRulesLogLevels = {
FORCE: -1, // always show output
SILENT: 0, // No output
ERROR: 1, // error
WARN: 2, // warn
INFO: 3, // success, info, log, note
DEBUG: 4, // debug, trace
};
class CursorRulesLogger {
level = cursorRulesLogLevels.INFO;
constructor() {
this.init();
}
init() {
this.setLogLevel(cursorRulesLogLevels.INFO);
}
prompt = {
intro: (...args) => {
if (this.level >= cursorRulesLogLevels.INFO) {
intro(pc.bold(this.formatArgs(args)));
}
},
error: (...args) => {
if (this.level >= cursorRulesLogLevels.ERROR) {
log.error(this.formatArgs(args));
}
},
info: (...args) => {
if (this.level >= cursorRulesLogLevels.INFO) {
log.info(this.formatArgs(args));
}
},
message: (...args) => {
if (this.level >= cursorRulesLogLevels.INFO) {
log.message(this.formatArgs(args));
}
},
step: (...args) => {
if (this.level >= cursorRulesLogLevels.INFO) {
log.step(this.formatArgs(args));
}
},
success: (...args) => {
if (this.level >= cursorRulesLogLevels.INFO) {
log.success(this.formatArgs(args));
}
},
warn: (...args) => {
if (this.level >= cursorRulesLogLevels.WARN) {
log.warn(this.formatArgs(args));
}
},
outro: (...args) => {
if (this.level >= cursorRulesLogLevels.INFO) {
outro(pc.bold(this.formatArgs(args)));
}
},
};
setLogLevel(level) {
this.level = level;
}
getLogLevel() {
return this.level;
}
error(...args) {
if (this.level >= cursorRulesLogLevels.ERROR) {
console.error(' ', pc.red(this.formatArgs(args)));
}
}
warn(...args) {
if (this.level >= cursorRulesLogLevels.WARN) {
console.log(' ', pc.yellow(this.formatArgs(args)));
}
}
success(...args) {
if (this.level >= cursorRulesLogLevels.INFO) {
console.log(' ', pc.green(this.formatArgs(args)));
}
}
info(...args) {
if (this.level >= cursorRulesLogLevels.INFO) {
console.log(' ', pc.cyan(this.formatArgs(args)));
}
}
log(...args) {
if (this.level >= cursorRulesLogLevels.INFO) {
console.log(' ', this.formatArgs(args));
}
}
note(...args) {
if (this.level >= cursorRulesLogLevels.INFO) {
console.log(' ', pc.dim(this.formatArgs(args)));
}
}
debug(...args) {
if (this.level >= cursorRulesLogLevels.DEBUG) {
console.log(' ', pc.blue(this.formatArgs(args)));
}
}
trace(...args) {
if (this.level >= cursorRulesLogLevels.DEBUG) {
console.log(' ', pc.gray(this.formatArgs(args)));
}
}
quiet(...args) {
if (this.level <= cursorRulesLogLevels.SILENT) {
console.log(' ', pc.dim(this.formatArgs(args)));
}
}
force(...args) {
if (this.level >= cursorRulesLogLevels.FORCE) {
console.log(' ', this.formatArgs(args));
}
}
formatArgs(args) {
return args
.map((arg) => (typeof arg === 'object' ? util.inspect(arg, { depth: null, colors: true }) : arg))
.join(' ');
}
}
export const logger = new CursorRulesLogger();
export const setLogLevel = (level) => {
logger.setLogLevel(level);
};
//# sourceMappingURL=logger.js.map