Skip to content

Commit b435d6c

Browse files
Merge pull request #270 from FormidableLabs/task/migrate-neo-blessed
Migrate to using neo-blessed as underlying blessed renderer.
2 parents 473b794 + ad2fca4 commit b435d6c

20 files changed

Lines changed: 219 additions & 164 deletions

.eslintrc.json

Lines changed: 1 addition & 1 deletion
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"]

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: node_js
22

33
node_js:
4-
- "6"
54
- "8"
65
- "10"
76

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,25 @@ That's cool, but it's mostly noise and scrolly and not super helpful. This plugi
1818

1919
### Use
2020

21+
**`webpack-dashboard@^2.1.1` requires Node 8 or above.** Previous versions support down to Node 6.
22+
2123
First, import the plugin and add it to your webpack config, or apply it to your compiler:
2224

2325
```js
2426
// Import the plugin:
25-
var DashboardPlugin = require('webpack-dashboard/plugin');
27+
var DashboardPlugin = require("webpack-dashboard/plugin");
2628

2729
// If you aren't using express, add it to your webpack configs plugins section:
28-
plugins: [
29-
new DashboardPlugin()
30-
]
30+
plugins: [new DashboardPlugin()];
3131

3232
// If you are using an express based dev server, add it with compiler.apply
3333
compiler.apply(new DashboardPlugin());
3434
```
35+
3536
If using a custom port, the port number must be included in the options object here, as well as passed using the -p flag in the call to webpack-dashboard. See how below:
3637

3738
```js
38-
plugins: [
39-
new DashboardPlugin({ port: 3001 })
40-
]
39+
plugins: [new DashboardPlugin({ port: 3001 })];
4140
```
4241

4342
In the latest version, you can either run your app, and run `webpack-dashboard` independently (by installing with `npm install webpack-dashboard -g`) or run webpack-dashboard from your `package.json`. So if your dev server start script previously looked like:
@@ -55,6 +54,7 @@ You would change that to:
5554
"dev": "webpack-dashboard -- node index.js"
5655
}
5756
```
57+
5858
Now you can just run your start script like normal, except now, you are awesome. Not that you weren't before. I'm just saying. More so.
5959

6060
### Run it
@@ -64,8 +64,9 @@ Finally, start your server using whatever command you have set up. Either you ha
6464
Then, sit back and pretend you're an astronaut.
6565

6666
### Supported Operating Systems and Terminals
67+
6768
**macOS →**
68-
Webpack Dashboard works in Terminal, iTerm 2, and Hyper. For mouse events, like scrolling, in Terminal you will need to ensure *View → Enable Mouse Reporting* is enabled. This is supported in macOS El Capitan, Sierra, and High Sierra. In iTerm 2, to select full rows of text hold the <kbd>⌥ Opt</kbd> key. To select a block of text hold the <kbd>⌥ Opt</kbd> + <kbd>⌘ Cmd</kbd> key combination.
69+
Webpack Dashboard works in Terminal, iTerm 2, and Hyper. For mouse events, like scrolling, in Terminal you will need to ensure _View → Enable Mouse Reporting_ is enabled. This is supported in macOS El Capitan, Sierra, and High Sierra. In iTerm 2, to select full rows of text hold the <kbd>⌥ Opt</kbd> key. To select a block of text hold the <kbd>⌥ Opt</kbd> + <kbd>⌘ Cmd</kbd> key combination.
6970

7071
**Windows 10 →** Webpack Dashboard works in Command Prompt, PowerShell, and Linux Subsystem for Windows. Mouse events are not supported at this time, as discussed further in the documentation of the underlying terminal library we use [Blessed](https://github.com/chjj/blessed#windows-compatibility). The main log can be scrolled using the <kbd>↑</kbd>, <kbd>↓</kbd>, <kbd>Page Up</kbd>, and <kbd>Page Down</kbd> keys.
7172

@@ -74,25 +75,27 @@ Webpack Dashboard works in Terminal, iTerm 2, and Hyper. For mouse events, like
7475
### API
7576

7677
#### webpack-dashboard (CLI)
78+
7779
##### Options
7880

79-
- `-c, --color [color]` - Custom ANSI color for your dashboard
80-
- `-m, --minimal` - Runs the dashboard in minimal mode
81-
- `-t, --title [title]` - Set title of terminal window
82-
- `-p, --port [port]` - Custom port for socket communication server
81+
- `-c, --color [color]` - Custom ANSI color for your dashboard
82+
- `-m, --minimal` - Runs the dashboard in minimal mode
83+
- `-t, --title [title]` - Set title of terminal window
84+
- `-p, --port [port]` - Custom port for socket communication server
8385

8486
##### Arguments
8587

8688
`[command]` - The command you want to run, i.e. `webpack-dashboard -- node index.js`
8789

8890
#### Webpack plugin
91+
8992
#### Options
9093

91-
- `host` - Custom host for connection the socket client
92-
- `port` - Custom port for connecting the socket client
93-
- `handler` - Plugin handler method, i.e. `dashboard.setData`
94+
- `host` - Custom host for connection the socket client
95+
- `port` - Custom port for connecting the socket client
96+
- `handler` - Plugin handler method, i.e. `dashboard.setData`
9497

95-
*Note: you can also just pass a function in as an argument, which then becomes the handler, i.e. `new DashboardPlugin(dashboard.setData)`*
98+
_Note: you can also just pass a function in as an argument, which then becomes the handler, i.e. `new DashboardPlugin(dashboard.setData)`_
9699

97100
### Local Development
98101

bin/webpack-dashboard.js

Lines changed: 15 additions & 10 deletions
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

Lines changed: 15 additions & 16 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 9 additions & 4 deletions
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

Lines changed: 35 additions & 30 deletions
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

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/.eslintrc.json

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

0 commit comments

Comments
 (0)