change package name
This commit is contained in:
parent
1b3ca8a43b
commit
5128b0d530
2
cli.js
2
cli.js
@ -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) => {
|
server.on('connection', (ws) => {
|
||||||
ws.on('message', (message) => {
|
ws.on('message', (message) => {
|
||||||
|
9
index.d.ts
vendored
9
index.d.ts
vendored
@ -1,2 +1,7 @@
|
|||||||
export default tconsole;
|
export default termsole;
|
||||||
declare function tconsole(options: any = {}): void;
|
interface Options {
|
||||||
|
host?: string;
|
||||||
|
port?: number;
|
||||||
|
ssl?: boolean;
|
||||||
|
}
|
||||||
|
declare function termsole(options: Options = {}): void;
|
||||||
|
15
index.js
15
index.js
@ -4,8 +4,9 @@ let ws = null;
|
|||||||
const defaultConsole = Object.assign(Object.create(Object.getPrototypeOf(console)), console);
|
const defaultConsole = Object.assign(Object.create(Object.getPrototypeOf(console)), console);
|
||||||
|
|
||||||
const configure = (conn) => {
|
const configure = (conn) => {
|
||||||
// already configured
|
// skip if already configured
|
||||||
if (console.stdlog) return;
|
if (console._tsconsole_configured) return;
|
||||||
|
console._tsconsole_configured = true;
|
||||||
|
|
||||||
console.log = (...args) => {
|
console.log = (...args) => {
|
||||||
sendWhenConnected(conn, JSON.stringify({ type: 'log', data: Array.from(args) }));
|
sendWhenConnected(conn, JSON.stringify({ type: 'log', data: Array.from(args) }));
|
||||||
@ -27,29 +28,27 @@ const configure = (conn) => {
|
|||||||
defaultConsole.debug.apply(defaultConsole, args);
|
defaultConsole.debug.apply(defaultConsole, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("[TCONSOLE] CONFIGURED");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const release = () => {
|
const release = () => {
|
||||||
console = defaultConsole;
|
console = defaultConsole;
|
||||||
console.log("[TCONSOLE]: Released");
|
|
||||||
ws = null;
|
ws = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tconsole = (options = {}) => {
|
const termsole = (options = {}) => {
|
||||||
if (ws) return; // already running
|
if (ws) return; // already running
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 8080,
|
port: 3456,
|
||||||
ssl: false,
|
ssl: false,
|
||||||
...options,
|
...options,
|
||||||
}
|
}
|
||||||
|
|
||||||
ws = new WebSocket(`${options.ssl ? "wss" : "ws"}://${options.host}:${options.port}`);
|
ws = new WebSocket(`${options.ssl ? "wss" : "ws"}://${options.host}:${options.port}`);
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
console.log('[TCONSOLE]: connected');
|
|
||||||
configure(ws);
|
configure(ws);
|
||||||
|
console.log('[TCONSOLE]: Connected');
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = (event) => {
|
ws.onclose = (event) => {
|
||||||
@ -81,4 +80,4 @@ const sendWhenConnected = (ws, msg, n = 0, maxTries = 100) => {
|
|||||||
}, 10); // wait 10 milisecond for the connection...
|
}, 10); // wait 10 milisecond for the connection...
|
||||||
}
|
}
|
||||||
|
|
||||||
export default tconsole;
|
export default termsole;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "tconsole",
|
"name": "termsole",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Console log to terminal",
|
"description": "Console log to terminal",
|
||||||
"type": "main",
|
"type": "main",
|
||||||
@ -15,8 +15,8 @@
|
|||||||
},
|
},
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "Ngoc Khuat <qn.khuat@gmail.com>",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/qnkhuat/TConsole/issues"
|
"url": "https://github.com/qnkhuat/TConsole/issues"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user