@@ -4,7 +4,7 @@ const cookie = require('cookie');
44const cookieParser = require ( 'cookie-parser' ) ;
55const crypto = require ( 'crypto' ) ;
66const path = require ( 'path' ) ;
7- const SocketIO = require ( 'socket.io' ) ;
7+ const { Server } = require ( 'socket.io' ) ;
88const fs = require ( 'fs' ) ;
99const untildify = require ( 'untildify' ) ;
1010const 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 ) ;
3031stats . track ( 'runtime' , 'init' ) ;
3132stats . 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 ) ;
3839const sessionSecret = String ( + new Date ( ) ) + Math . random ( ) ;
3940const files = program . args . join ( ' ' ) ;
4041const 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
0 commit comments