change package name

This commit is contained in:
Earther 2021-08-24 15:53:22 +07:00
parent 1b3ca8a43b
commit 5128b0d530
4 changed files with 18 additions and 14 deletions

2
cli.js
View File

@ -31,7 +31,7 @@ const out = (text, color) => {
}
}
const server = new WebSocket.Server({ port: 8080 });
const server = new WebSocket.Server({ port: 3456 });
server.on('connection', (ws) => {
ws.on('message', (message) => {

9
index.d.ts vendored
View File

@ -1,2 +1,7 @@
export default tconsole;
declare function tconsole(options: any = {}): void;
export default termsole;
interface Options {
host?: string;
port?: number;
ssl?: boolean;
}
declare function termsole(options: Options = {}): void;

View File

@ -4,8 +4,9 @@ let ws = null;
const defaultConsole = Object.assign(Object.create(Object.getPrototypeOf(console)), console);
const configure = (conn) => {
// already configured
if (console.stdlog) return;
// skip if already configured
if (console._tsconsole_configured) return;
console._tsconsole_configured = true;
console.log = (...args) => {
sendWhenConnected(conn, JSON.stringify({ type: 'log', data: Array.from(args) }));
@ -27,29 +28,27 @@ const configure = (conn) => {
defaultConsole.debug.apply(defaultConsole, args);
};
console.log("[TCONSOLE] CONFIGURED");
}
const release = () => {
console = defaultConsole;
console.log("[TCONSOLE]: Released");
ws = null;
}
const tconsole = (options = {}) => {
const termsole = (options = {}) => {
if (ws) return; // already running
options = {
host: "localhost",
port: 8080,
port: 3456,
ssl: false,
...options,
}
ws = new WebSocket(`${options.ssl ? "wss" : "ws"}://${options.host}:${options.port}`);
ws.onopen = () => {
console.log('[TCONSOLE]: connected');
configure(ws);
console.log('[TCONSOLE]: Connected');
};
ws.onclose = (event) => {
@ -81,4 +80,4 @@ const sendWhenConnected = (ws, msg, n = 0, maxTries = 100) => {
}, 10); // wait 10 milisecond for the connection...
}
export default tconsole;
export default termsole;

View File

@ -1,5 +1,5 @@
{
"name": "tconsole",
"name": "termsole",
"version": "1.0.0",
"description": "Console log to terminal",
"type": "main",
@ -15,8 +15,8 @@
},
"preferGlobal": true,
"keywords": [],
"author": "",
"license": "ISC",
"author": "Ngoc Khuat <qn.khuat@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/qnkhuat/TConsole/issues"
},