big update
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
const net = require('net');
|
||||
const through = require('through2');
|
||||
const colors = require('ansi-colors');
|
||||
const log = require('fancy-log');
|
||||
|
||||
|
||||
const _colors = {
|
||||
'[DEBUG]': colors.white,
|
||||
'[INFO]': colors.cyan,
|
||||
'[ERROR]': colors.red,
|
||||
'Called from ': colors.red,
|
||||
'[WARNING]': colors.yellow,
|
||||
};
|
||||
|
||||
@@ -23,58 +21,20 @@ const getColor = (line) => {
|
||||
|
||||
class Debug {
|
||||
|
||||
static log (line, color) {
|
||||
if (color === undefined) {
|
||||
color = getColor(line) || colors.white;
|
||||
}
|
||||
if (line[0] === '\t') {
|
||||
console.log(color(line));
|
||||
} else {
|
||||
const result = line.split(' ');
|
||||
console.log(colors.gray(result.slice(0, 4).join(' ')) + ' ' + color(result.slice(4).join(' ')));
|
||||
}
|
||||
};
|
||||
|
||||
constructor() {
|
||||
this.host = 'localhost';
|
||||
this.port = 6000 + Math.floor(Math.random() * 1000);
|
||||
this.color = colors.white;
|
||||
this.log = this.log.bind(this);
|
||||
}
|
||||
|
||||
macro() {
|
||||
return [
|
||||
`CompilationOption.set('debug.address','${this.host}')`,
|
||||
`CompilationOption.set('debug.port','${this.port}')`,
|
||||
];
|
||||
};
|
||||
|
||||
run() {
|
||||
const debug = this;
|
||||
return through.obj(function (file, enc, callback) {
|
||||
if (this.disabled) {
|
||||
this.emit('end');
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
let color = colors.white;
|
||||
const server = net.createServer((socket) => {
|
||||
socket.on("data", (data) => {
|
||||
const lines = data.toString().split('\n');
|
||||
for (let line of lines) if (line.length > 2) {
|
||||
const newColor = getColor(line);
|
||||
if (newColor != null) color = newColor;
|
||||
Debug.log(line, color);
|
||||
}
|
||||
});
|
||||
socket.on("close", () => {
|
||||
socket.destroy();
|
||||
server.close();
|
||||
this.emit('end');
|
||||
callback();
|
||||
});
|
||||
});
|
||||
log(colors.green('[debug]'), colors.cyan('listen on'), colors.magenta(`${debug.host}:${debug.port}`));
|
||||
server.listen(debug.port, debug.host);
|
||||
})
|
||||
log(line) {
|
||||
const newColor = getColor(line);
|
||||
if (newColor) this.color = newColor;
|
||||
if (line[0] === '\t' || line.startsWith('Called from ')) {
|
||||
console.log(this.color(line));
|
||||
} else {
|
||||
const result = line.split(' ');
|
||||
console.log(colors.gray(result.slice(0, 4).join(' ')) + ' ' + this.color(result.slice(4).join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user