Skip to content

Commit 5f6e2e4

Browse files
author
parkerziegler
committed
Migrate to using neo-blessed as underlying blessed renderer.
1 parent 473b794 commit 5f6e2e4

18 files changed

+200
-147
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "formidable/configurations/es6-node",
2+
"extends": ["formidable/configurations/es6-node", "plugin:prettier/recommended"],
33
"rules": {
44
"func-style": "off",
55
"arrow-parens": ["error", "as-needed"]

bin/webpack-dashboard.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const program = new commander.Command("webpack-dashboard");
1313
const pkg = require("../package.json");
1414

1515
// Wrap up side effects in a script.
16-
const main = module.exports = opts => { // eslint-disable-line max-statements, complexity
16+
// eslint-disable-next-line max-statements, complexity
17+
const main = (module.exports = opts => {
1718
opts = opts || {};
1819
const argv = typeof opts.argv === "undefined" ? process.argv : opts.argv;
1920

@@ -72,17 +73,21 @@ const main = module.exports = opts => { // eslint-disable-line max-statements, c
7273
});
7374

7475
child.stdout.on("data", data => {
75-
dashboard.setData([{
76-
type: "log",
77-
value: data.toString("utf8")
78-
}]);
76+
dashboard.setData([
77+
{
78+
type: "log",
79+
value: data.toString("utf8")
80+
}
81+
]);
7982
});
8083

8184
child.stderr.on("data", data => {
82-
dashboard.setData([{
83-
type: "log",
84-
value: data.toString("utf8")
85-
}]);
85+
dashboard.setData([
86+
{
87+
type: "log",
88+
value: data.toString("utf8")
89+
}
90+
]);
8691
});
8792

8893
process.on("exit", () => {
@@ -95,7 +100,7 @@ const main = module.exports = opts => { // eslint-disable-line max-statements, c
95100
});
96101
});
97102
}
98-
};
103+
});
99104

100105
if (require.main === module) {
101106
main();

dashboard/index.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
const chalk = require("chalk");
4-
const blessed = require("blessed");
4+
const blessed = require("neo-blessed");
55

66
const { formatOutput } = require("../utils/format-output");
77
const { formatModules } = require("../utils/format-modules");
@@ -94,13 +94,12 @@ class Dashboard {
9494

9595
setData(dataArray) {
9696
dataArray
97-
.map(
98-
data =>
99-
data.error
100-
? Object.assign({}, data, {
97+
.map(data =>
98+
data.error
99+
? Object.assign({}, data, {
101100
value: deserializeError(data.value)
102101
})
103-
: data
102+
: data
104103
)
105104
.forEach(data => {
106105
this.actionForMessageType[data.type](data);
@@ -133,14 +132,14 @@ class Dashboard {
133132
let content;
134133

135134
switch (data.value) {
136-
case "Success":
137-
content = `{green-fg}{bold}${data.value}{/}`;
138-
break;
139-
case "Failed":
140-
content = `{red-fg}{bold}${data.value}{/}`;
141-
break;
142-
default:
143-
content = `{bold}${data.value}{/}`;
135+
case "Success":
136+
content = `{green-fg}{bold}${data.value}{/}`;
137+
break;
138+
case "Failed":
139+
content = `{red-fg}{bold}${data.value}{/}`;
140+
break;
141+
default:
142+
content = `{bold}${data.value}{/}`;
144143
}
145144
this.status.setContent(content);
146145
}
@@ -497,8 +496,8 @@ class Dashboard {
497496
tags: true,
498497
padding: this.minimal
499498
? {
500-
left: 1
501-
}
499+
left: 1
500+
}
502501
: 1,
503502
width: this.minimal ? "33%" : "100%",
504503
height: this.minimal ? "100%" : "34%",

examples/simple/src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/* eslint-disable no-console*/
32

43
const hello = () => "hello world";

package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
"test": "mocha 'test/**/*.spec.js'",
1313
"test-cov": "nyc mocha 'test/**/*.spec.js'",
1414
"lint": "eslint .",
15-
"check": "npm run lint && npm run test && npm run check-ts",
16-
"check-ci": "npm run lint && npm run test-cov && npm run check-ts",
15+
"check": "npm run format-check && npm run lint && npm run test && npm run check-ts",
16+
"check-ci": "npm run format-check && npm run lint && npm run test-cov && npm run check-ts",
1717
"check-ts": "tsc index.d.ts --noEmit",
18-
"dev": "cross-env EXAMPLE=duplicates-esm node bin/webpack-dashboard.js -- webpack-cli --config examples/config/webpack.config.js --watch"
18+
"dev": "cross-env EXAMPLE=duplicates-esm node bin/webpack-dashboard.js -- webpack-cli --config examples/config/webpack.config.js --watch",
19+
"format": "prettier --write './{bin,examples,plugin,test,utils}/**/*.js'",
20+
"format-check": "prettier --list-different './{bin,examples,plugin,test,utils}/**/*.js'"
1921
},
2022
"repository": {
2123
"type": "git",
@@ -37,13 +39,13 @@
3739
"webpack": "*"
3840
},
3941
"dependencies": {
40-
"blessed": "^0.1.81",
4142
"commander": "^2.15.1",
4243
"cross-spawn": "^6.0.5",
4344
"filesize": "^3.6.1",
4445
"handlebars": "^4.0.11",
4546
"inspectpack": "^4.0.0",
4647
"most": "^1.7.3",
48+
"neo-blessed": "^0.2.0",
4749
"socket.io": "^2.1.1",
4850
"socket.io-client": "^2.1.1"
4951
},
@@ -53,11 +55,14 @@
5355
"cross-env": "^5.2.0",
5456
"eslint": "^4.19.1",
5557
"eslint-config-formidable": "^4.0.0",
58+
"eslint-config-prettier": "^4.0.0",
5659
"eslint-plugin-filenames": "^1.1.0",
5760
"eslint-plugin-import": "^2.12.0",
61+
"eslint-plugin-prettier": "^3.0.1",
5862
"eslint-plugin-promise": "^3.7.0",
5963
"mocha": "^5.2.0",
6064
"nyc": "^11.8.0",
65+
"prettier": "^1.16.4",
6166
"sinon": "^5.0.7",
6267
"sinon-chai": "^3.0.0",
6368
"typescript": "^3.2.4",

plugin/index.js

+35-30
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@ class DashboardPlugin {
159159

160160
webpackHook(compiler, "done", stats => {
161161
const options = stats.compilation.options;
162-
const statsOptions
163-
= options.devServer && options.devServer.stats
164-
|| options.stats
165-
|| { colors: true };
162+
const statsOptions = (options.devServer && options.devServer.stats) ||
163+
options.stats || { colors: true };
166164

167165
handler([
168166
{
@@ -207,33 +205,40 @@ class DashboardPlugin {
207205
observeMetrics(statsObj) {
208206
const statsToObserve = statsObj.toJson();
209207

210-
const getSizes = stats => actions("sizes", { stats })
211-
.then(instance => instance.getData())
212-
.then(data => ({
213-
type: "sizes",
214-
value: data
215-
}))
216-
.catch(err => ({
217-
type: "sizes",
218-
error: true,
219-
value: serializeError(err)
220-
}));
221-
222-
const getProblems = stats => Promise
223-
.all(INSPECTPACK_PROBLEM_ACTIONS.map(action => actions(action, { stats })
208+
const getSizes = stats =>
209+
actions("sizes", { stats })
224210
.then(instance => instance.getData())
225-
))
226-
.then(datas => ({
227-
type: INSPECTPACK_PROBLEM_TYPE,
228-
value: INSPECTPACK_PROBLEM_ACTIONS.reduce((memo, action, i) => Object.assign({}, memo, {
229-
[action]: datas[i]
230-
}), {})
231-
}))
232-
.catch(err => ({
233-
type: INSPECTPACK_PROBLEM_TYPE,
234-
error: true,
235-
value: serializeError(err)
236-
}));
211+
.then(data => ({
212+
type: "sizes",
213+
value: data
214+
}))
215+
.catch(err => ({
216+
type: "sizes",
217+
error: true,
218+
value: serializeError(err)
219+
}));
220+
221+
const getProblems = stats =>
222+
Promise.all(
223+
INSPECTPACK_PROBLEM_ACTIONS.map(action =>
224+
actions(action, { stats }).then(instance => instance.getData())
225+
)
226+
)
227+
.then(datas => ({
228+
type: INSPECTPACK_PROBLEM_TYPE,
229+
value: INSPECTPACK_PROBLEM_ACTIONS.reduce(
230+
(memo, action, i) =>
231+
Object.assign({}, memo, {
232+
[action]: datas[i]
233+
}),
234+
{}
235+
)
236+
}))
237+
.catch(err => ({
238+
type: INSPECTPACK_PROBLEM_TYPE,
239+
error: true,
240+
value: serializeError(err)
241+
}));
237242

238243
const sizesStream = most.of(statsToObserve).map(getSizes);
239244
const problemsStream = most.of(statsToObserve).map(getProblems);

test/.eslintrc

-4
This file was deleted.

test/.eslintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["formidable/configurations/es6-node-test", "plugin:prettier/recommended"]
3+
}

test/base.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
*/
1111
const sinon = require("sinon");
1212

13-
const blessed = require("blessed");
13+
const blessed = require("neo-blessed");
1414

15-
const base = module.exports = {
15+
const base = (module.exports = {
1616
sandbox: null
17-
};
17+
});
1818

1919
beforeEach(() => {
2020
base.sandbox = sinon.createSandbox({

test/bin/webpack-dashboard.spec.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ const cli = require("../../bin/webpack-dashboard");
66

77
describe("bin/webpack-dashboard", () => {
88
it("can invoke the dashboard cli", () => {
9-
expect(() => cli({
10-
argv: [],
11-
server: {
12-
on: base.sandbox.spy()
13-
}
14-
})).to.not.throw();
9+
expect(() =>
10+
cli({
11+
argv: [],
12+
server: {
13+
on: base.sandbox.spy()
14+
}
15+
})
16+
).to.not.throw();
1517
});
1618
});

0 commit comments

Comments
 (0)