Skip to content

Commit bdfe717

Browse files
committed
Modernize
1 parent 1de374a commit bdfe717

File tree

19 files changed

+7523
-2100
lines changed

19 files changed

+7523
-2100
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* marking logs
2020
* pausing logs
2121
* number of unread logs in favicon
22-
* themes (default, dark)
22+
* Dark mode
2323
* [highlighting](#highlighting)
2424
* search (`Tab` to focus, `Esc` to clear)
2525
* set filter from url parameter `filter`
@@ -43,7 +43,6 @@
4343
-p, --port <port> listening port, default 9001
4444
-n, --number <number> starting lines number, default 10
4545
-l, --lines <lines> number on lines stored in browser, default 2000
46-
-t, --theme <theme> name of the theme (default, dark)
4746
-d, --daemonize run as daemon
4847
-U, --user <username> Basic Authentication username, option works only along with -P option
4948
-P, --password <password> Basic Authentication password, option works only along with -U option

index.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const cookie = require('cookie');
44
const cookieParser = require('cookie-parser');
55
const crypto = require('crypto');
66
const path = require('path');
7-
const SocketIO = require('socket.io');
7+
const { Server } = require('socket.io');
88
const fs = require('fs');
99
const untildify = require('untildify');
1010
const tail = require('./lib/tail');
@@ -22,26 +22,27 @@ if (program.args.length === 0) {
2222
console.error('Arguments needed, use --help');
2323
process.exit();
2424
}
25+
const options = program.opts();
2526

2627
/**
2728
* Init usage statistics
2829
*/
29-
const stats = usageStats(!program.disableUsageStats, program);
30+
const stats = usageStats(!options.disableUsageStats, options);
3031
stats.track('runtime', 'init');
3132
stats.time('runtime', 'runtime');
32-
33+
3334
/**
3435
* Validate params
3536
*/
36-
const doAuthorization = !!(program.user && program.password);
37-
const doSecure = !!(program.key && program.certificate);
37+
const doAuthorization = !!(options.user && options.password);
38+
const doSecure = !!(options.key && options.certificate);
3839
const sessionSecret = String(+new Date()) + Math.random();
3940
const files = program.args.join(' ');
4041
const filesNamespace = crypto.createHash('md5').update(files).digest('hex');
41-
const urlPath = program.urlPath.replace(/\/$/, ''); // remove trailing slash
42+
const urlPath = options.urlPath.replace(/\/$/, ''); // remove trailing slash
4243

43-
if (program.daemonize) {
44-
daemonize(__filename, program, {
44+
if (options.daemonize) {
45+
daemonize(__filename, options, {
4546
doAuthorization,
4647
doSecure,
4748
});
@@ -52,31 +53,30 @@ if (program.daemonize) {
5253
const appBuilder = connectBuilder(urlPath);
5354
if (doAuthorization) {
5455
appBuilder.session(sessionSecret);
55-
appBuilder.authorize(program.user, program.password);
56+
appBuilder.authorize(options.user, options.password);
5657
}
5758
appBuilder
5859
.static(path.join(__dirname, 'web', 'assets'))
5960
.index(
6061
path.join(__dirname, 'web', 'index.html'),
6162
files,
62-
filesNamespace,
63-
program.theme
63+
filesNamespace
6464
);
6565

6666
const builder = serverBuilder();
6767
if (doSecure) {
68-
builder.secure(program.key, program.certificate);
68+
builder.secure(options.key, options.certificate);
6969
}
7070
const server = builder
7171
.use(appBuilder.build())
72-
.port(program.port)
73-
.host(program.host)
72+
.port(options.port)
73+
.host(options.host)
7474
.build();
7575

7676
/**
7777
* socket.io setup
7878
*/
79-
const io = new SocketIO({ path: `${urlPath}/socket.io` });
79+
const io = new Server({ path: `${urlPath}/socket.io` });
8080
io.attach(server);
8181

8282
if (doAuthorization) {
@@ -106,13 +106,13 @@ if (program.daemonize) {
106106
* Setup UI highlights
107107
*/
108108
let highlightConfig;
109-
if (program.uiHighlight) {
109+
if (options.uiHighlight) {
110110
let presetPath;
111111

112-
if (!program.uiHighlightPreset) {
112+
if (!options.uiHighlightPreset) {
113113
presetPath = path.join(__dirname, 'preset', 'default.json');
114114
} else {
115-
presetPath = path.resolve(untildify(program.uiHighlightPreset));
115+
presetPath = path.resolve(untildify(options.uiHighlightPreset));
116116
}
117117

118118
if (fs.existsSync(presetPath)) {
@@ -126,21 +126,21 @@ if (program.daemonize) {
126126
* When connected send starting data
127127
*/
128128
const tailer = tail(program.args, {
129-
buffer: program.number,
129+
buffer: options.number,
130130
});
131131

132132
const filesSocket = io.of(`/${filesNamespace}`).on('connection', (socket) => {
133-
socket.emit('options:lines', program.lines);
133+
socket.emit('options:lines', options.lines);
134134

135-
if (program.uiHideTopbar) {
135+
if (options.uiHideTopbar) {
136136
socket.emit('options:hide-topbar');
137137
}
138138

139-
if (!program.uiIndent) {
139+
if (!options.uiIndent) {
140140
socket.emit('options:no-indent');
141141
}
142142

143-
if (program.uiHighlight) {
143+
if (options.uiHighlight) {
144144
socket.emit('options:highlightConfig', highlightConfig);
145145
}
146146

lib/daemonize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const daemon = require('daemon-fix41');
3+
const daemon = require('daemonize-process');
44
const fs = require('fs');
55

66
const defaultOptions = {

lib/options_parser.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ program
2323
Number,
2424
2000
2525
)
26-
.option(
27-
'-t, --theme <theme>',
28-
'name of the theme (default, dark)',
29-
String,
30-
'default'
31-
)
3226
.option('-d, --daemonize', 'run as daemon')
3327
.option(
3428
'-U, --user <username>',

lib/stats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const ua = require('universal-analytics');
44
const isDocker = require('is-docker');
55
const Configstore = require('configstore');
6-
const uuidv4 = require('uuid/v4');
6+
const { v4: uuidv4 } = require('uuid');
77
const pkg = require('../package.json');
88

99
const trackingID = 'UA-129582046-1';

0 commit comments

Comments
 (0)