2022-06-19 00:25:21 +00:00
|
|
|
import colors from "chalk";
|
|
|
|
import read from "read";
|
2016-04-16 11:32:38 +00:00
|
|
|
|
2017-11-22 06:39:32 +00:00
|
|
|
function timestamp() {
|
2020-03-21 20:55:36 +00:00
|
|
|
const datetime = new Date().toISOString().split(".")[0].replace("T", " ");
|
2018-09-20 11:15:05 +00:00
|
|
|
|
|
|
|
return colors.dim(datetime);
|
2016-04-16 11:32:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const log = {
|
2018-03-20 05:54:04 +00:00
|
|
|
/* eslint-disable no-console */
|
2022-06-19 00:25:21 +00:00
|
|
|
error(...args: string[]) {
|
2018-03-20 05:54:04 +00:00
|
|
|
console.error(timestamp(), colors.red("[ERROR]"), ...args);
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
warn(...args: string[]) {
|
2018-03-20 05:54:04 +00:00
|
|
|
console.error(timestamp(), colors.yellow("[WARN]"), ...args);
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
info(...args: string[]) {
|
2018-03-20 05:54:04 +00:00
|
|
|
console.log(timestamp(), colors.blue("[INFO]"), ...args);
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
debug(...args: string[]) {
|
2018-03-20 05:54:04 +00:00
|
|
|
console.log(timestamp(), colors.green("[DEBUG]"), ...args);
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
raw(...args: string[]) {
|
2018-03-20 05:54:04 +00:00
|
|
|
console.log(...args);
|
|
|
|
},
|
|
|
|
/* eslint-enable no-console */
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
prompt(
|
|
|
|
options: {prompt?: string; default?: string; text: string; silent?: boolean},
|
|
|
|
callback: (error, result, isDefault) => void
|
|
|
|
): void {
|
2018-03-20 05:54:04 +00:00
|
|
|
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
|
|
|
|
read(options, callback);
|
|
|
|
},
|
2016-12-15 06:13:43 +00:00
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
export default log;
|