Skip to content

Commit 248e2d1

Browse files
committed
wip es6 -> es5
1 parent 0d37356 commit 248e2d1

File tree

12 files changed

+346
-355
lines changed

12 files changed

+346
-355
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
---
22
extends:
3-
- "formidable/configurations/es6-node"
3+
- "formidable/configurations/es5-node"

bin/nodejs-dashboard.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env node
22
"use strict";
33

4-
const SocketIO = require("socket.io");
5-
const spawn = require("cross-spawn");
6-
const commander = require("commander");
7-
const path = require("path");
4+
var SocketIO = require("socket.io");
5+
var spawn = require("cross-spawn");
6+
var commander = require("commander");
7+
var path = require("path");
88

9-
const Dashboard = require("../lib/dashboard");
10-
const config = require("../lib/config");
11-
const appPkg = require(path.resolve("package.json"));
12-
const pkg = require("../package.json");
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");
1313

14-
const appName = appPkg.name || "node";
15-
const program = new commander.Command(pkg.name);
14+
var appName = appPkg.name || "node";
15+
var program = new commander.Command(pkg.name);
1616

1717
program.version(pkg.version);
1818
program.option("-p, --port [port]", "Socket listener port");
@@ -25,46 +25,46 @@ if (!program.args.length) {
2525
return;
2626
}
2727

28-
const command = program.args[0];
29-
const args = program.args.slice(1);
28+
var command = program.args[0];
29+
var args = program.args.slice(1);
3030

31-
const port = program.port || config.PORT;
32-
const eventDelay = program.eventdelay || config.BLOCKED_THRESHOLD;
31+
var port = program.port || config.PORT;
32+
var eventDelay = program.eventdelay || config.BLOCKED_THRESHOLD;
3333

3434
process.env[config.PORT_KEY] = port;
3535
process.env[config.BLOCKED_THRESHOLD_KEY] = eventDelay;
3636

37-
const child = spawn(command, args, {
37+
var child = spawn(command, args, {
3838
env: process.env,
3939
stdio: [null, null, null, null],
4040
detached: true
4141
});
4242

43-
console.log(`Waiting for client connection on ${port}...`); //eslint-disable-line
43+
console.log("Waiting for client connection on %d...", port); //eslint-disable-line
4444

45-
const server = new SocketIO(port);
45+
var server = new SocketIO(port);
4646

47-
const dashboard = new Dashboard({ appName, program });
47+
var dashboard = new Dashboard({ appName: appName, program: program });
4848

49-
server.on("connection", (socket) => {
50-
socket.on("metrics", (data) => {
49+
server.on("connection", function (socket) {
50+
socket.on("metrics", function (data) {
5151
dashboard.onEvent({ type: "metrics", data: JSON.parse(data) });
5252
});
5353

54-
socket.on("error", (err) => {
54+
socket.on("error", function (err) {
5555
console.error("Received error from agent, exiting: ", err); //eslint-disable-line
5656
process.exit(1); //eslint-disable-line
5757
});
5858
});
5959

60-
child.stdout.on("data", (data) => {
60+
child.stdout.on("data", function (data) {
6161
dashboard.onEvent({ type: "stdout", data: data.toString("utf8") });
6262
});
6363

64-
child.stderr.on("data", (data) => {
64+
child.stderr.on("data", function (data) {
6565
dashboard.onEvent({ type: "stderr", data: data.toString("utf8") });
6666
});
6767

68-
process.on("exit", () => {
68+
process.on("exit", function () {
6969
process.kill(process.platform === "win32" ? child.pid : -child.pid);
7070
});

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"use strict";
2-
const dashboardAgent = require("./lib/dashboard-agent");
2+
var dashboardAgent = require("./lib/dashboard-agent");
33

44
module.exports = dashboardAgent();

lib/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
22

3-
const pkg = require("../package.json");
3+
var pkg = require("../package.json");
44

55
module.exports = {
66
PORT: 9838,
7-
PORT_KEY: `${pkg.name}_PORT`,
7+
PORT_KEY: pkg.name + "_PORT",
88
BLOCKED_THRESHOLD: 10,
9-
BLOCKED_THRESHOLD_KEY: `${pkg.name}_BLOCKED_THRESHOLD`
9+
BLOCKED_THRESHOLD_KEY: pkg.name + "_BLOCKED_THRESHOLD"
1010
};

lib/dashboard-agent.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
"use strict";
22

3-
const SocketIO = require("socket.io-client");
4-
const blocked = require("blocked");
5-
const pusage = require("pidusage");
6-
const os = require("os");
7-
const _ = require("lodash");
8-
const config = require("./config");
9-
10-
const dashboardAgent = () => {
11-
const options = {
3+
var SocketIO = require("socket.io-client");
4+
var blocked = require("blocked");
5+
var pusage = require("pidusage");
6+
var os = require("os");
7+
var _ = require("lodash");
8+
var config = require("./config");
9+
10+
var dashboardAgent = function () {
11+
var options = {
1212
port: process.env[config.PORT_KEY],
1313
blockedThreshold: process.env[config.BLOCKED_THRESHOLD_KEY],
1414
refreshInterval: 1000
1515
};
1616

17-
const socket = new SocketIO(`http://localhost:${options.port}`);
17+
var socket = new SocketIO("http://localhost:" + options.port);
1818

19-
const eventLoop = {
19+
var eventLoop = {
2020
delay: 0,
2121
high: 0
2222
};
2323

24-
const _delayed = (delay) => {
24+
var _delayed = function (delay) {
2525
eventLoop.high = Math.max(eventLoop.high, delay);
2626
eventLoop.delay = delay;
2727
};
2828

2929
blocked(_delayed, { threshold: options.blockedThreshold });
3030

31-
const _getStats = (cb) => {
32-
const metrics = {
33-
eventLoop,
31+
var _getStats = function (cb) {
32+
var metrics = {
33+
eventLoop: eventLoop,
3434
mem: {
3535
systemTotal: os.totalmem()
3636
},
@@ -41,7 +41,7 @@ const dashboardAgent = () => {
4141

4242
_.merge(metrics.mem, process.memoryUsage());
4343

44-
pusage.stat(process.pid, (err, stat) => {
44+
pusage.stat(process.pid, function (err, stat) {
4545

4646
if (err) {
4747
return cb(err);
@@ -53,12 +53,12 @@ const dashboardAgent = () => {
5353

5454
};
5555

56-
const resetEventMetrics = () => {
56+
var resetEventMetrics = function () {
5757
eventLoop.delay = 0;
5858
};
5959

60-
const _emitStats = () => {
61-
_getStats((err, newMetrics) => {
60+
var _emitStats = function () {
61+
_getStats(function (err, newMetrics) {
6262
if (err) {
6363
console.error("Failed to load metrics: ", err); //eslint-disable-line
6464
socket.emit("error", JSON.stringify(err));
@@ -70,22 +70,22 @@ const dashboardAgent = () => {
7070
});
7171
};
7272

73-
const startPump = () => {
73+
var startPump = function () {
7474
options.intervalId = setInterval(_emitStats, options.refreshInterval);
7575
};
7676

77-
const destroy = () => {
77+
var destroy = function () {
7878
socket.close();
7979
clearInterval(options.intervalId);
8080
};
8181

8282
startPump();
8383

8484
return {
85-
_delayed,
86-
_getStats,
87-
_emitStats,
88-
destroy
85+
_delayed: _delayed,
86+
_getStats: _getStats,
87+
_emitStats: _emitStats,
88+
destroy: destroy
8989
};
9090
};
9191

lib/dashboard.js

Lines changed: 50 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,63 @@
11
"use strict";
22

3-
const _ = require("lodash");
4-
const blessed = require("blessed");
5-
6-
const StreamView = require("./views/stream-view");
7-
const EventLoopView = require("./views/eventloop-view");
8-
const MemoryView = require("./views/memory-view");
9-
const CpuView = require("./views/cpu-view");
10-
const EventEmitter = require("events");
11-
12-
class Dashboard {
13-
14-
constructor(options) {
15-
this.screen = blessed.screen({
16-
smartCSR: true,
17-
title: `${options.appName}`
18-
});
19-
20-
this.screen.key(["escape", "q", "C-c"], () => {
21-
process.exit(0); // eslint-disable-line no-process-exit
22-
});
23-
24-
this.eventPump = new EventEmitter();
25-
this._createView();
26-
27-
}
28-
29-
onEvent(event) {
30-
this.eventPump.emit(event.type, event.data);
31-
this.screen.render();
32-
}
3+
var _ = require("lodash");
4+
var blessed = require("blessed");
5+
6+
var StreamView = require("./views/stream-view");
7+
var EventLoopView = require("./views/eventloop-view");
8+
var MemoryView = require("./views/memory-view");
9+
var CpuView = require("./views/cpu-view");
10+
var EventEmitter = require("events");
11+
12+
function Dashboard(options) {
13+
this.screen = blessed.screen({
14+
smartCSR: true,
15+
title: options.appName
16+
});
17+
18+
this.screen.key(["escape", "q", "C-c"], function () {
19+
process.exit(0); // eslint-disable-line no-process-exit
20+
});
21+
22+
this.eventPump = new EventEmitter();
23+
this._createView();
24+
}
3325

34-
_createView() {
35-
// fixes weird scrolling issue
36-
const container = blessed.box({});
37-
this.screen.append(container);
26+
Dashboard.prototype.onEvent = function (event) {
27+
this.eventPump.emit(event.type, event.data);
28+
this.screen.render();
29+
};
3830

39-
const stdoutView = new StreamView({
40-
parent: container,
41-
label: "stdout",
42-
color: "green"
43-
});
31+
Dashboard.prototype._createView = function () {
32+
// fixes weird scrolling issue
33+
var container = blessed.box({});
34+
this.screen.append(container);
4435

45-
this.eventPump.addListener("stdout", stdoutView.onEvent.bind(stdoutView));
36+
var stdoutView = new StreamView({
37+
parent: container,
38+
label: "stdout",
39+
color: "green"
40+
});
4641

47-
const stderrView = new StreamView({
48-
parent: container,
49-
label: "stderr",
50-
color: "red",
51-
top: "50%"
52-
});
42+
this.eventPump.addListener("stdout", stdoutView.onEvent.bind(stdoutView));
5343

54-
this.eventPump.addListener("stderr", stderrView.onEvent.bind(stderrView));
44+
var stderrView = new StreamView({
45+
parent: container,
46+
label: "stderr",
47+
color: "red",
48+
top: "50%"
49+
});
5550

56-
const metrics = [MemoryView, CpuView, EventLoopView];
51+
this.eventPump.addListener("stderr", stderrView.onEvent.bind(stderrView));
5752

58-
_.each(metrics, (Metric) => {
59-
const view = new Metric({ parent: this.screen });
60-
this.eventPump.addListener("metrics", view.onEvent.bind(view));
61-
});
53+
var metrics = [MemoryView, CpuView, EventLoopView];
6254

63-
this.screen.render();
64-
}
55+
_.each(metrics, function (Metric) {
56+
var view = new Metric({ parent: this.screen });
57+
this.eventPump.addListener("metrics", view.onEvent.bind(view));
58+
}.bind(this));
6559

66-
}
60+
this.screen.render();
61+
};
6762

6863
module.exports = Dashboard;

0 commit comments

Comments
 (0)