2022-11-02 19:48:49 +01:00
|
|
|
const { writeFile, readFile, mkdir } = require('node:fs/promises');
|
|
|
|
const { stdin, stdout } = require('node:process');
|
2022-12-29 14:39:58 +01:00
|
|
|
var readlineSync = require('readline-sync');
|
2022-11-02 19:48:49 +01:00
|
|
|
var name;
|
|
|
|
|
|
|
|
function getTime () {
|
|
|
|
const date_time = new Date();
|
|
|
|
const year = date_time.getFullYear();
|
|
|
|
const month = ("0" + (date_time.getMonth() + 1)).slice(-2);
|
|
|
|
const day = ("0" + date_time.getDate()).slice(-2);
|
|
|
|
const hours = date_time.getHours();
|
|
|
|
const minutes = date_time.getMinutes();
|
|
|
|
const seconds = date_time.getSeconds();
|
|
|
|
return({year, month, day, hours, minutes, seconds})
|
|
|
|
};
|
|
|
|
|
|
|
|
function createLog () {
|
|
|
|
mkdir('./logs', { recursive: true });
|
|
|
|
var time = getTime();
|
|
|
|
name = `${time.year}.${time.month}.${time.day}.${time.hours}.${time.minutes}.${time.seconds}.log`;
|
|
|
|
writeFile(`./logs/${name}`, '');
|
|
|
|
return(name)
|
|
|
|
};
|
|
|
|
|
|
|
|
function log (string) {
|
|
|
|
readFile(`./logs/${name}`, 'utf8')
|
|
|
|
.then(async (err, data) => {
|
|
|
|
if (!data) data = '';
|
|
|
|
data += string + '\n';
|
|
|
|
writeFile(`./logs/${name}`, data);
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
function cin (question, hide) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
var answer = readlineSync.question(`${question} `, {
|
|
|
|
hideEchoBack: hide || false
|
|
|
|
})
|
|
|
|
return resolve(answer);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
return resolve('error');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2023-01-24 17:04:50 +01:00
|
|
|
class createCout {
|
|
|
|
constructor (debugLevel, logs) {
|
|
|
|
this.debug = debugLevel;
|
|
|
|
this.logs = logs;
|
|
|
|
}
|
|
|
|
|
|
|
|
cout (string, debugLevel) {
|
|
|
|
if (!debugLevel) debugLevel = 0;
|
|
|
|
var time = getTime();
|
|
|
|
|
|
|
|
if (this.debug >= debugLevel) {
|
|
|
|
console.log(`[${time.year}.${time.month}.${time.day}-${time.hours}:${time.minutes}:${time.seconds}] | ${String(string)}`);
|
|
|
|
if (this.logs) {
|
|
|
|
log(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
}
|
2022-11-02 19:48:49 +01:00
|
|
|
|
2023-01-24 17:09:13 +01:00
|
|
|
module.exports = { cin, createCout, createLog, log };
|