change name and add readme.md
This commit is contained in:
parent
ea2823bf1d
commit
a8fe30d140
56
README.md
56
README.md
@ -1,8 +1,8 @@
|
|||||||
# TConsole
|
# Termlog
|
||||||
Bring browser console to your terminal
|
Bring browser console to your terminal
|
||||||
|
|
||||||
### What it does
|
### What it does
|
||||||
TConsole send the browser console log to your terminal.
|
termlog send the browser console log to your terminal.
|
||||||
|
|
||||||
It also comes with a __nodejs__ REPL so you can do some basic draft code
|
It also comes with a __nodejs__ REPL so you can do some basic draft code
|
||||||
|
|
||||||
@ -10,36 +10,54 @@ It also comes with a __nodejs__ REPL so you can do some basic draft code
|
|||||||
While you developing your front-end app and you have to switch back and forth between IDE and browser.
|
While you developing your front-end app and you have to switch back and forth between IDE and browser.
|
||||||
|
|
||||||
# How to use it?
|
# How to use it?
|
||||||
There are two ways and it depends on your preferences
|
There are 2 ways and it depends on your preferences
|
||||||
|
|
||||||
## Recommended way
|
## Recommended way
|
||||||
1. Install the `tconsole` binary : `npm install --save-dev tconsole` ( you also can install globally with `npm install -g tconsole` )
|
1. Install the `termlog` binary : `npm install --save-dev termlog` ( you also can install globally with `npm install -g termlog` )
|
||||||
2. Go to the entry file of your project (I.e: app.jsx for React.js or main.js for vue.js)
|
2. Start server `npx termlog` or `termlog` if you install globally
|
||||||
3. Insert these two lines:
|
3. Go to the entry file of your project (I.e: app.jsx for React or main.js for Vue)
|
||||||
`
|
4. Insert these two lines:
|
||||||
import tconsole from "t-console";
|
```
|
||||||
tconsole();
|
import termlog from "termlog"
|
||||||
`
|
termlog()
|
||||||
4. You should now see your console log stream to this terminal
|
```
|
||||||
|
4. You should now see log being streamed to your terminal
|
||||||
|
|
||||||
__Note__: with this approach you might want to remove two lines above in production.
|
__Note__: with this approach you might want to remove two lines above in production.
|
||||||
|
|
||||||
By default tconsole will __not__ run if it detects production mode using `NODE_ENV`, but you shouldn't rely on that.
|
By default termlog will __not__ run if it detects production mode using `NODE_ENV`, but you shouldn't rely on that.
|
||||||
|
|
||||||
## I don't want to add dependencies to my project
|
## I don't want to add dependencies to my project
|
||||||
1. Install the `tconsole` binary : `npm install -g tconsole`
|
1. Install the `termlog` binary : `npm install -g termlog`
|
||||||
2. Start the server `tconsole`
|
2. Start server `termlog`
|
||||||
3. Go to your browser and open the console window
|
3. Go to your browser and open the console window
|
||||||
4. Copy all code except for the last export line from [index.js](index.js) file to console
|
4. Copy code inside [index.js](index.js) file __without__ the last export line into console
|
||||||
5. Enter `tconsole()` in side console
|
5. Enter `termlog()` into console
|
||||||
6. You should now see your console log stream to this terminal
|
6. You should now see log being streamed to your terminal
|
||||||
|
|
||||||
|
|
||||||
__Note__: with this approach you have to do all steps 3-6 every-time you refresh your browser tab.
|
__Note__: with this approach you have to do all steps 3-6 every-time you refresh your browser tab.
|
||||||
|
|
||||||
## Advanced options
|
## Advanced options
|
||||||
|
With `tconsole` command:
|
||||||
|
- `--out path`: save log to file
|
||||||
|
- `--port port`: Change server port
|
||||||
|
- `--addr addr`: Change server address
|
||||||
|
|
||||||
|
|
||||||
|
With `tconsole` package:
|
||||||
|
|
||||||
|
`tconsole({
|
||||||
|
host: "localhost",
|
||||||
|
port: 3456
|
||||||
|
})`
|
||||||
|
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
Tconsole have 2 components:
|
||||||
|
- [server.js](cli.js) - a websocket server to receive log from browser and display it
|
||||||
|
- [index.js](index.js) - tconsole package to import in your front end app. This package will override the default behavior of console object and send log to the server
|
||||||
|
|
||||||
## Future release
|
## Future release
|
||||||
- [ ] Install using `<script/>` tag
|
- [ ] Install using `<script/>` tag
|
||||||
- [ ] (Maybe) An extension to start tconsole on browser so we don't have to install dependencies
|
- [ ] (Maybe) An extension to start termlog on browser so we don't have to install dependencies
|
||||||
- [ ] (If possible) Browser console REPL instead of nodejs REPL
|
- [ ] (If possible) Browser console REPL instead of nodejs REPL
|
||||||
|
10
index.js
10
index.js
@ -34,7 +34,7 @@ const release = (defaultConsole) => {
|
|||||||
ws = null;
|
ws = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tconsole = (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;
|
if (process && process.env.NODE_ENV && process.env.NODE_ENV !== 'development') return;
|
||||||
|
|
||||||
@ -51,17 +51,17 @@ const tconsole = (options = {}) => {
|
|||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
configure(ws, defaultConsole);
|
configure(ws, defaultConsole);
|
||||||
console.log('[TCONSOLE]: Connected');
|
console.log('[TERMLOG]: Connected');
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = (event) => {
|
ws.onclose = (event) => {
|
||||||
release(defaultConsole);
|
release(defaultConsole);
|
||||||
console.log("[TCONSOLE]: Disconnected", event.message);
|
console.log("[TERMLOG]: Disconnected", event.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.onerror = (event) => {
|
ws.onerror = (event) => {
|
||||||
release(defaultConsole);
|
release(defaultConsole);
|
||||||
console.error("[TCONSOLE]: Disconnected", event.message);
|
console.error("[TERMLOG]: Disconnected", event.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,4 +83,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 termlog;
|
||||||
|
10
package.json
10
package.json
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "tConsole",
|
"name": "termlog",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Console log to terminal",
|
"description": "Console log to terminal",
|
||||||
"type": "main",
|
"type": "main",
|
||||||
@ -8,19 +8,19 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/qnkhuat/TConsole.git"
|
"url": "git+https://github.com/qnkhuat/termlog.git"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"tconsole": "cli.js"
|
"tconsole": "server.js"
|
||||||
},
|
},
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Ngoc Khuat <qn.khuat@gmail.com>",
|
"author": "Ngoc Khuat <qn.khuat@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/qnkhuat/TConsole/issues"
|
"url": "https://github.com/qnkhuat/termlog/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/qnkhuat/TConsole#readme",
|
"homepage": "https://github.com/qnkhuat/termlog#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.5",
|
||||||
|
@ -81,7 +81,7 @@ const startServer = (options) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
conn.on("close", (event) => {
|
conn.on("close", (event) => {
|
||||||
out("[TCONSOLE]: Closed", conn);
|
out("[TERMLOG]: Closed", conn);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -124,7 +124,7 @@ const startServer = (options) => {
|
|||||||
const args = minimist(process.argv.slice(2));
|
const args = minimist(process.argv.slice(2));
|
||||||
if ("help" in args) {
|
if ("help" in args) {
|
||||||
console.log(`
|
console.log(`
|
||||||
TConsole - Console to your terminal
|
Termlog - Console log to terminal
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user