add option to disable check env and fix bug failed to display single argument

This commit is contained in:
Earther 2021-08-27 17:28:38 +07:00
parent 51d17d40a3
commit 77fba71a8e
3 changed files with 7 additions and 6 deletions

View File

@ -35,17 +35,18 @@ const release = (defaultConsole) => {
const termlog = (options = {}) => { const termlog = (options = {}) => {
// Ensure tconsole doesn't run in production mode // Ensure tconsole doesn't run in production mode
if (process && process.env.NODE_ENV && process.env.NODE_ENV !== 'development') return;
const defaultConsole = Object.assign(Object.create(Object.getPrototypeOf(console)), console);
options = { options = {
host: DEFAULT_HOST, host: DEFAULT_HOST,
port: DEFAULT_PORT, port: DEFAULT_PORT,
ssl: false, ssl: false,
disableEnvironmentCheck: false,
...options, ...options,
} }
if (!options.disableEnvironmentCheck && process && process.env.NODE_ENV && process.env.NODE_ENV !== 'development') return;
const defaultConsole = Object.assign(Object.create(Object.getPrototypeOf(console)), console);
const ws = new WebSocket(`${options.ssl ? "wss" : "ws"}://${options.host}:${options.port}`); const ws = new WebSocket(`${options.ssl ? "wss" : "ws"}://${options.host}:${options.port}`);
ws.onopen = () => { ws.onopen = () => {

View File

@ -1,6 +1,6 @@
{ {
"name": "termlog", "name": "termlog",
"version": "1.1.0", "version": "1.1.1",
"description": "Console log to terminal", "description": "Console log to terminal",
"type": "main", "type": "main",
"scripts": { "scripts": {

View File

@ -28,6 +28,7 @@ const getTime = () => {
} }
const out = (data, color = CWhite) => { const out = (data, color = CWhite) => {
if (!Array.isArray(data)) data = [data];
process.stdout.write(color); process.stdout.write(color);
process.stdout.write(getTime() + " "); process.stdout.write(getTime() + " ");
console.log.apply(console, data); console.log.apply(console, data);
@ -73,7 +74,6 @@ const startServer = (options) => {
const event = JSON.parse(message); const event = JSON.parse(message);
let { type, data } = event; let { type, data } = event;
if (!Array.isArray(data)) data = [data];
if (!SHOWLEVELS.includes(type)) return; if (!SHOWLEVELS.includes(type)) return;
switch (type) { switch (type) {