Skip to content

Commit d81b7f0

Browse files
committed
Fixed monitor eslint issues
1 parent 35ec687 commit d81b7f0

File tree

8 files changed

+135
-132
lines changed

8 files changed

+135
-132
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"tab",
99
{ "SwitchCase": 1 }
1010
],
11-
"no-tabs": ["error", { "allowIndentationTabs": true }],
11+
"no-tabs": ["off"],
1212
"no-unused-vars": "off",
1313
"semi": ["error", "always"],
1414
"object-curly-spacing": ["error", "always"],

packages/monitor/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ export * from './lib/monitor-options';
99
export default LaunchpadMonitor;
1010

1111
export const launch = async (config) => {
12-
const monitor = new LaunchpadMonitor(config.monitor || config);
13-
await monitor.connect();
14-
await monitor.start();
12+
const monitor = new LaunchpadMonitor(config.monitor || config);
13+
await monitor.connect();
14+
await monitor.start();
1515

16-
onExit(async () => {
17-
await monitor.stop();
18-
await monitor.disconnect();
19-
});
16+
onExit(async () => {
17+
await monitor.stop();
18+
await monitor.disconnect();
19+
});
2020
};
2121

2222
launchFromCli(import.meta, {
23-
relativePaths: ['launchpad-monitor/index.js', '.bin/launchpad-monitor'],
23+
relativePaths: ['launchpad-monitor/index.js', '.bin/launchpad-monitor']
2424
})
25-
.then(launch)
26-
.catch((err) => {
27-
if (err) {
28-
console.error('Launch error', err);
29-
process.exit(1);
30-
}
31-
});
25+
.then(launch)
26+
.catch((err) => {
27+
if (err) {
28+
console.error('Launch error', err);
29+
process.exit(1);
30+
}
31+
});

packages/monitor/lib/app-log-router.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import pm2 from "pm2";
2-
import path from "path";
3-
import { Tail } from "tail";
4-
import autoBind from "auto-bind";
5-
import { SubEmitterSocket } from "axon"; // used by PM2
6-
import { Logger, LogManager } from "@bluecadet/launchpad-utils";
7-
import { AppOptions, AppLogOptions, LogModes } from "./monitor-options.js";
1+
import pm2 from 'pm2';
2+
import path from 'path';
3+
import { Tail } from 'tail';
4+
import autoBind from 'auto-bind';
5+
import { SubEmitterSocket } from 'axon'; // used by PM2
6+
import { Logger, LogManager } from '@bluecadet/launchpad-utils';
7+
import { AppOptions, AppLogOptions, LogModes } from './monitor-options.js';
88

99
class LogRelay {
1010
/**
@@ -39,10 +39,10 @@ class LogRelay {
3939
appOptions.pm2.error_file = appOptions.pm2.error;
4040

4141
if (
42-
appOptions.pm2.output !== "/dev/null" ||
43-
appOptions.pm2.error !== "/dev/null"
42+
appOptions.pm2.output !== '/dev/null' ||
43+
appOptions.pm2.error !== '/dev/null'
4444
) {
45-
logger.warn("Launchpad is unable to rotate log files generated by pm2");
45+
logger.warn('Launchpad is unable to rotate log files generated by pm2');
4646
logger.warn(
4747
"Set log mode to 'bus' and unset pm2 output/error properties to hide this warning."
4848
);
@@ -59,7 +59,7 @@ class LogRelay {
5959
*/
6060
handleEvent(_eventType, _eventData) {
6161
// implement this fn in all child classes
62-
throw new Error("not implemented");
62+
throw new Error('not implemented');
6363
}
6464
}
6565

@@ -103,9 +103,9 @@ class FileLogRelay extends LogRelay {
103103
*/
104104
handleEvent(eventType, eventData) {
105105
switch (eventType) {
106-
case "process:event":
107-
if (eventData.event === "online") this._handleOnline();
108-
else if (eventData.event === "exit") this._handleOffline();
106+
case 'process:event':
107+
if (eventData.event === 'online') this._handleOnline();
108+
else if (eventData.event === 'exit') this._handleOffline();
109109
break;
110110
default:
111111
break;
@@ -116,7 +116,7 @@ class FileLogRelay extends LogRelay {
116116
_handleOnline() {
117117
const tailOptions = {
118118
useWatchFile: true,
119-
fsWatchOptions: { interval: 100 },
119+
fsWatchOptions: { interval: 100 }
120120
};
121121
const outFilepath = this._appOptions.pm2.output;
122122
const errFilepath = this._appOptions.pm2.error;
@@ -144,16 +144,16 @@ class FileLogRelay extends LogRelay {
144144
if (this._logOptions.showStdout) {
145145
this._logger.debug(`Tailing stdout from ${outFilepath}`);
146146
this._outTail = new Tail(outFilepath, tailOptions);
147-
this._outTail.on("line", (data) => this._handleTailOutput(data));
148-
this._outTail.on("error", (data) => this._handleTailError(data, true));
147+
this._outTail.on('line', (data) => this._handleTailOutput(data));
148+
this._outTail.on('error', (data) => this._handleTailError(data, true));
149149
this._outTail.watch();
150150
}
151151

152152
if (this._logOptions.showStderr) {
153153
this._logger.debug(`Tailing stderr from ${errFilepath}`);
154154
this._errTail = new Tail(errFilepath, tailOptions);
155-
this._errTail.on("line", (data) => this._handleTailError(data));
156-
this._errTail.on("error", (data) => this._handleTailError(data, true));
155+
this._errTail.on('line', (data) => this._handleTailError(data));
156+
this._errTail.on('error', (data) => this._handleTailError(data, true));
157157
this._errTail.watch();
158158
}
159159
}
@@ -192,8 +192,8 @@ class BusLogRelay extends LogRelay {
192192
*/
193193
constructor(appOptions, logger) {
194194
// default log outputs to '/dev/null' if not defined
195-
appOptions.pm2.output ??= "/dev/null";
196-
appOptions.pm2.error ??= "/dev/null";
195+
appOptions.pm2.output ??= '/dev/null';
196+
appOptions.pm2.error ??= '/dev/null';
197197

198198
super(appOptions, logger);
199199
}
@@ -204,10 +204,10 @@ class BusLogRelay extends LogRelay {
204204
*/
205205
handleEvent(eventType, eventData) {
206206
switch (eventType) {
207-
case "log:out":
207+
case 'log:out':
208208
this._handleBusLogOut(eventData);
209209
break;
210-
case "log:err":
210+
case 'log:err':
211211
this._handleBusLogErr(eventData);
212212
break;
213213
default:
@@ -296,14 +296,14 @@ export default class AppLogRouter {
296296
* @param {SubEmitterSocket} pm2Bus
297297
*/
298298
connectToBus(pm2Bus) {
299-
pm2Bus.on("*", this._handleEvent);
299+
pm2Bus.on('*', this._handleEvent);
300300
}
301301

302302
/**
303303
* @param {SubEmitterSocket} pm2Bus
304304
*/
305305
disconnectFromBus(pm2Bus) {
306-
pm2Bus.off("*");
306+
pm2Bus.off('*');
307307
}
308308

309309
/**

packages/monitor/lib/launchpad-monitor.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ export class LaunchpadMonitor {
6262
child.stderr.on('data', data => logger.error(data));
6363
child.on('error', error => {
6464
logger.error(`PM2 could not be killed: ${error}`);
65-
reject();
65+
reject(new Error(`PM2 could not be killed: ${error}`));
6666
});
67-
child.on("close", () => {
67+
child.on('close', () => {
6868
logger.info('PM2 has been killed');
6969
resolve();
7070
});
@@ -304,7 +304,7 @@ export class LaunchpadMonitor {
304304
return this._promisify(pm2.stop, pm2, appName)
305305
.then(async appProcess => {
306306
this._logger.info(`...app '${appName}' was stopped.`);
307-
return appProcess
307+
return appProcess;
308308
}).catch(err => {
309309
this._logger.error(`Could not stop app '${appName}':`, err);
310310
throw err;
@@ -340,7 +340,7 @@ export class LaunchpadMonitor {
340340
this._logger.debug(`Daemon is running: ${isRunning}`);
341341
return isRunning;
342342
}).catch(err => {
343-
this._logger.warn(`Could not ping daemon`, err);
343+
this._logger.warn('Could not ping daemon', err);
344344
return false;
345345
});
346346
}
@@ -359,7 +359,7 @@ export class LaunchpadMonitor {
359359
if (Symbol.iterator in Object(appNames)) {
360360
return [...appNames];
361361
}
362-
throw new Error(`appNames must be null, undefined, a string or an iterable array/set of strings`);
362+
throw new Error('appNames must be null, undefined, a string or an iterable array/set of strings');
363363
}
364364

365365
/**
@@ -368,7 +368,7 @@ export class LaunchpadMonitor {
368368
*/
369369
_initAppOptions(options) {
370370
if (!options.pm2 || !options.pm2.name) {
371-
this._logger.error(`PM2 config is incomplete or missing:`, options);
371+
this._logger.error('PM2 config is incomplete or missing:', options);
372372
return options;
373373
}
374374
options.logging = new AppLogOptions(options.logging);
@@ -440,15 +440,18 @@ export class LaunchpadMonitor {
440440
case 'start':
441441
this._logger.debug(`App is starting: ${chalk.yellow(appName)}`);
442442
break;
443-
case 'online':
443+
case 'online': {
444444
this._logger.debug(`App is online: ${chalk.green(appName)}`);
445-
let numLaunches = this._numAppLaunches.has(appName) ?
446-
(this._numAppLaunches.get(appName) + 1) : 1;
445+
let numLaunches = 1;
446+
if (this._numAppLaunches.has(appName)) {
447+
numLaunches = this._numAppLaunches.get(appName) + 1;
448+
}
447449
if (numLaunches > 1) {
448450
await this._applyWindowSettings();
449451
}
450452
this._numAppLaunches.set(appName, numLaunches);
451453
break;
454+
}
452455
case 'exit':
453456
this._logger.debug(`App has exited: ${chalk.red(appName)}`);
454457
break;
@@ -457,7 +460,7 @@ export class LaunchpadMonitor {
457460
break;
458461
}
459462
} catch (err) {
460-
this._logger.error(`Could not process bus event`);
463+
this._logger.error('Could not process bus event');
461464
this._logger.error(err);
462465
}
463466
}
@@ -474,9 +477,8 @@ export class LaunchpadMonitor {
474477
resolve(...results);
475478
}
476479
});
477-
})
480+
});
478481
}
479482
}
480483

481484
export default LaunchpadMonitor;
482-

packages/monitor/lib/monitor-options.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class AppOptions {
4545
constructor({
4646
pm2 = null,
4747
windows = new WindowOptions(),
48-
logging = new AppLogOptions(),
48+
logging = new AppLogOptions()
4949
} = {}) {
5050
/**
5151
* Configure which app to launch and how to monitor it here.
@@ -118,7 +118,7 @@ export const LogModes = {
118118
/**
119119
* Logs directly from the app's stdout/stderr bus. Can result in interrupted logs if the buffer isn't consistently flushed by an app.
120120
*/
121-
LogBusEvents: 'bus',
121+
LogBusEvents: 'bus'
122122
};
123123

124124
/**
@@ -129,7 +129,7 @@ export class AppLogOptions {
129129
logToLaunchpadDir = true,
130130
mode = LogModes.LogBusEvents,
131131
showStdout = true,
132-
showStderr = true,
132+
showStderr = true
133133
} = {}) {
134134
/**
135135
* Route application logs to launchpad's log dir instead of pm2's log dir.
@@ -160,7 +160,6 @@ export class AppLogOptions {
160160
* @default true
161161
*/
162162
this.showStderr = showStderr;
163-
164163
}
165164
}
166165

@@ -196,4 +195,4 @@ export class WindowsApiOptions {
196195

197196
Object.assign(this, rest);
198197
}
199-
}
198+
}

packages/monitor/lib/utils/sort-windows.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export class SortApp {
2525
const sortWindows = async (apps, logger = console, minNodeVersion = undefined) => {
2626
const currNodeVersion = process.version;
2727
if (!semver.satisfies(currNodeVersion, minNodeVersion)) {
28-
return Promise.reject(`Can't sort windows because the current node version '${currNodeVersion}' doesn't satisfy the required version '${minNodeVersion}'. Please upgrade node to apply window settings like foreground/minimize/hide.`);
28+
return Promise.reject(
29+
new Error(`Can't sort windows because the current node version '${currNodeVersion}' doesn't satisfy the required version '${minNodeVersion}'. Please upgrade node to apply window settings like foreground/minimize/hide.`)
30+
);
2931
}
3032

3133
logger.debug(`Applying window settings to ${apps.length} ${apps.length === 1 ? 'app' : 'apps'}`);
@@ -68,7 +70,7 @@ const sortWindows = async (apps, logger = console, minNodeVersion = undefined) =
6870
win.bringToTop();
6971
});
7072

71-
logger.debug(`Done applying window settings.`);
73+
logger.debug('Done applying window settings.');
7274
};
7375

74-
export default sortWindows;
76+
export default sortWindows;

0 commit comments

Comments
 (0)