cli run will prefer data file now, improved console coloring

This commit is contained in:
dswbx
2025-02-18 10:11:59 +01:00
parent bd362607ae
commit e12ed1e4b3
5 changed files with 63 additions and 12 deletions

View File

@@ -1,3 +1,6 @@
import { isDebug } from "core";
import c from "picocolors";
import type { Formatter } from "picocolors/types";
const _SPEEDUP = process.env.LOCAL;
const DEFAULT_WAIT = _SPEEDUP ? 0 : 250;
@@ -54,3 +57,31 @@ export async function* typewriter(
}
}
}
function ifString(args: any[], c: Formatter) {
return args.map((a) => (typeof a === "string" ? c(a) : a));
}
const originalConsole = {
log: console.log,
info: console.info,
debug: console.debug,
warn: console.warn,
error: console.error
};
export const $console = {
log: (...args: any[]) => originalConsole.info(c.gray("[LOG] "), ...ifString(args, c.dim)),
info: (...args: any[]) => originalConsole.info(c.cyan("[INFO] "), ...args),
debug: (...args: any[]) => isDebug() && originalConsole.info(c.yellow("[DEBUG]"), ...args),
warn: (...args: any[]) => originalConsole.info(c.yellow("[WARN] "), ...ifString(args, c.yellow)),
error: (...args: any[]) => originalConsole.info(c.red("[ERROR]"), ...ifString(args, c.red))
};
export function replaceConsole() {
console.log = $console.log;
console.info = $console.info;
console.debug = $console.debug;
console.warn = $console.warn;
console.error = $console.error;
}