11#!/usr/bin/env node
2+
23"use strict" ;
34
4- var SocketIO = require ( "socket.io" ) ;
5- var spawn = require ( "cross-spawn" ) ;
6- var commander = require ( "commander" ) ;
7- var path = require ( "path" ) ;
5+ const SocketIO = require ( "socket.io" ) ;
6+ const spawn = require ( "cross-spawn" ) ;
7+ const commander = require ( "commander" ) ;
8+ const path = require ( "path" ) ;
89
9- var Dashboard = require ( "../lib/dashboard" ) ;
10- var config = require ( "../lib/config" ) ;
11- var appPkg = require ( path . resolve ( "package.json" ) ) ;
12- var pkg = require ( "../package.json" ) ;
13- var parseSettings = require ( "../lib/parse-settings" ) ;
10+ const Dashboard = require ( "../lib/dashboard" ) ;
11+ const config = require ( "../lib/config" ) ;
12+ const appPkg = require ( path . resolve ( "package.json" ) ) ;
13+ const pkg = require ( "../package.json" ) ;
14+ const parseSettings = require ( "../lib/parse-settings" ) ;
1415
15- var appName = appPkg . name || "node" ;
16- var program = new commander . Command ( pkg . name ) ;
16+ const appName = appPkg . name || "node" ;
17+ const program = new commander . Command ( pkg . name ) ;
1718
1819// Mimic commander syntax errors (with offsets) for consistency
1920/* eslint-disable no-console */
20- var exitWithError = function ( ) {
21- var args = Array . prototype . slice . call ( arguments ) ;
21+ const exitWithError = function ( ) {
22+ const args = Array . prototype . slice . call ( arguments ) ;
2223 console . error ( ) ;
23- console . error . apply ( console , [ " " ] . concat ( args ) ) ;
24+ console . error ( ... [ " " ] . concat ( args ) ) ;
2425 console . error ( ) ;
2526 process . exit ( 1 ) ; // eslint-disable-line no-process-exit
2627} ;
@@ -44,8 +45,8 @@ program.option("-r, --refreshinterval [ms]",
4445
4546program . option ( "-s, --settings [settings]" ,
4647 "Overrides layout settings for given view types" ,
47- function ( settings ) {
48- var res = parseSettings ( settings ) ;
48+ ( settings ) => {
49+ const res = parseSettings ( settings ) ;
4950
5051 if ( res . error ) {
5152 exitWithError ( res . error ) ;
@@ -65,51 +66,54 @@ if (!program.args.length) {
6566 return ;
6667}
6768
68- var command = program . args [ 0 ] ;
69- var args = program . args . slice ( 1 ) ;
69+ const command = program . args [ 0 ] ;
70+ const args = program . args . slice ( 1 ) ;
7071
71- var port = program . port ;
72+ const port = program . port ;
7273
7374process . env [ config . PORT_KEY ] = port ;
7475process . env [ config . REFRESH_INTERVAL_KEY ] = program . refreshinterval ;
7576process . env [ config . BLOCKED_THRESHOLD_KEY ] = program . eventdelay ;
7677
7778
78- var child = spawn ( command , args , {
79+ const child = spawn ( command , args , {
7980 env : process . env ,
8081 stdio : [ null , null , null , null ] ,
8182 detached : true
8283} ) ;
8384
8485console . log ( "Waiting for client connection on %d..." , port ) ; //eslint-disable-line
8586
86- var server = new SocketIO ( port ) ;
87+ const server = new SocketIO ( port ) ;
8788
88- var dashboard = new Dashboard ( {
89- appName : appName ,
90- program : program ,
89+ const dashboard = new Dashboard ( {
90+ appName,
91+ program,
9192 layoutsFile : program . layouts ,
9293 settings : program . settings
9394} ) ;
9495
95- server . on ( "connection" , function ( socket ) {
96- socket . on ( "metrics" , function ( data ) {
97- dashboard . onEvent ( { type : "metrics" , data : JSON . parse ( data ) } ) ;
96+ server . on ( "connection" , ( socket ) => {
97+ socket . on ( "metrics" , ( data ) => {
98+ dashboard . onEvent ( { type : "metrics" ,
99+ data : JSON . parse ( data ) } ) ;
98100 } ) ;
99101
100- socket . on ( "error" , function ( err ) {
102+ socket . on ( "error" , ( err ) => {
101103 exitWithError ( "Received error from agent, exiting: " , err ) ;
102104 } ) ;
103105} ) ;
104106
105- child . stdout . on ( "data" , function ( data ) {
106- dashboard . onEvent ( { type : "stdout" , data : data . toString ( "utf8" ) } ) ;
107+ child . stdout . on ( "data" , ( data ) => {
108+ dashboard . onEvent ( { type : "stdout" ,
109+ data : data . toString ( "utf8" ) } ) ;
107110} ) ;
108111
109- child . stderr . on ( "data" , function ( data ) {
110- dashboard . onEvent ( { type : "stderr" , data : data . toString ( "utf8" ) } ) ;
112+ child . stderr . on ( "data" , ( data ) => {
113+ dashboard . onEvent ( { type : "stderr" ,
114+ data : data . toString ( "utf8" ) } ) ;
111115} ) ;
112116
113- process . on ( "exit" , function ( ) {
117+ process . on ( "exit" , ( ) => {
114118 process . kill ( process . platform === "win32" ? child . pid : - child . pid ) ;
115119} ) ;
0 commit comments