Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic tests + various infrastructure. #208

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ extends:
- formidable/configurations/es6-node
rules:
func-style: off
arrow-parens: off
arrow-parens: [error, as-needed]
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ node_modules

# misc
.DS_Store
npm-debug.log
npm-debug.log
.nyc_output
.coverage
8 changes: 8 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"reporter": [
"html",
"lcov",
"text-summary"
],
"report-dir": "./.coverage"
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ branches:

script:
- yarn --version
- yarn run check
- yarn run check-ci
142 changes: 76 additions & 66 deletions bin/webpack-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,83 +9,93 @@ const SocketIO = require("socket.io");
const DEFAULT_PORT = 9838;

const program = new commander.Command("webpack-dashboard");

const pkg = require("../package.json");
program.version(pkg.version);
program.option("-c, --color [color]", "Dashboard color");
program.option("-m, --minimal", "Minimal mode");
program.option("-t, --title [title]", "Terminal window title");
program.option("-p, --port [port]", "Socket listener port");
program.usage("[options] -- [script] [arguments]");
program.parse(process.argv);

let logFromChild = true;
let child;

if (!program.args.length) {
logFromChild = false;
}

if (logFromChild) {
const command = program.args[0];
const args = program.args.slice(1);
const env = process.env;

env.FORCE_COLOR = true;
// Wrap up side effects in a script.
const main = module.exports = opts => { // eslint-disable-line max-statements
opts = opts || {};
const argv = typeof opts.argv === "undefined" ? process.argv : opts.argv;

program.version(pkg.version);
program.option("-c, --color [color]", "Dashboard color");
program.option("-m, --minimal", "Minimal mode");
program.option("-t, --title [title]", "Terminal window title");
program.option("-p, --port [port]", "Socket listener port");
program.usage("[options] -- [script] [arguments]");
program.parse(argv);

let logFromChild = true;
let child;

if (!program.args.length) {
logFromChild = false;
}

if (logFromChild) {
const command = program.args[0];
const args = program.args.slice(1);
const env = process.env;

env.FORCE_COLOR = true;

child = spawn(command, args, {
env,
stdio: [null, null, null, null],
detached: true
});
}

child = spawn(command, args, {
env,
stdio: [null, null, null, null],
detached: true
const dashboard = new Dashboard({
color: program.color || "green",
minimal: program.minimal || false,
title: program.title || null
});
}

const dashboard = new Dashboard({
color: program.color || "green",
minimal: program.minimal || false,
title: program.title || null
});
const port = program.port || DEFAULT_PORT;
const server = opts.server || new SocketIO(port);

const port = program.port || DEFAULT_PORT;
const server = new SocketIO(port);

server.on("error", (err) => {
// eslint-disable-next-line no-console
console.log(err);
});
server.on("error", err => {
// eslint-disable-next-line no-console
console.log(err);
});

if (logFromChild) {
server.on("connection", (socket) => {
socket.emit("mode", { minimal: program.minimal || false });
if (logFromChild) {
server.on("connection", socket => {
socket.emit("mode", { minimal: program.minimal || false });

socket.on("message", (message) => {
if (message.type !== "log") {
dashboard.setData(message);
}
socket.on("message", message => {
if (message.type !== "log") {
dashboard.setData(message);
}
});
});
});

child.stdout.on("data", (data) => {
dashboard.setData([{
type: "log",
value: data.toString("utf8")
}]);
});
child.stdout.on("data", data => {
dashboard.setData([{
type: "log",
value: data.toString("utf8")
}]);
});

child.stderr.on("data", (data) => {
dashboard.setData([{
type: "log",
value: data.toString("utf8")
}]);
});
child.stderr.on("data", data => {
dashboard.setData([{
type: "log",
value: data.toString("utf8")
}]);
});

process.on("exit", () => {
process.kill(process.platform === "win32" ? child.pid : -child.pid);
});
} else {
server.on("connection", (socket) => {
socket.on("message", (message) => {
dashboard.setData(message);
process.on("exit", () => {
process.kill(process.platform === "win32" ? child.pid : -child.pid);
});
});
} else {
server.on("connection", socket => {
socket.on("message", message => {
dashboard.setData(message);
});
});
}
};

if (require.main === module) {
main();
}
Loading