Skip to content

Commit 3ccf833

Browse files
committed
closes #28: Contributing - code style.
1 parent b78dd9f commit 3ccf833

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2351
-1993
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ coverage
44
*.suo
55

66
npm-debug.log
7+
8+
# Netbeans
9+
/nbproject/

.jshintrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"bitwise":false,
3+
"camelcase":true,
4+
"curly":false,
5+
"eqeqeq":true,
6+
"freeze":true,
7+
"immed":true,
8+
"indent":2,
9+
"latedef":"nofunc",
10+
"laxbreak":true,
11+
"laxcomma":true,
12+
"maxlen":80,
13+
"newcap":true,
14+
"noarg":true,
15+
"node":true,
16+
"trailing":true,
17+
"undef":true
18+
}

.test-jshintrc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"bitwise":false,
3+
"camelcase":true,
4+
"curly":false,
5+
"eqeqeq":true,
6+
"freeze":true,
7+
"immed":true,
8+
"indent":2,
9+
"latedef":"nofunc",
10+
"laxbreak":true,
11+
"laxcomma":true,
12+
"maxlen":80,
13+
"newcap":true,
14+
"noarg":true,
15+
"node":true,
16+
"trailing":true,
17+
"undef":true,
18+
"globals":{
19+
"after":false,
20+
"afterEach":false,
21+
"before":false,
22+
"beforeEach":false,
23+
"describe":false,
24+
"it":false
25+
}
26+
}

bin/cserviced

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
#!/usr/bin/env node
22

3-
var
4-
path = require("path"),
5-
spawn = require("child_process").spawn
6-
;
7-
3+
var path = require("path");
4+
var spawn = require("child_process").spawn;
85
var args = process.argv.slice(2);
96
var cservicePath = path.resolve(__dirname, '..', 'bin', 'cservice');
7+
var cservice;
8+
109
args.splice(0, 0, cservicePath);
1110
args.push("--cli");
1211
args.push("false");
1312

14-
var cservice = spawn(process.execPath, args, {
15-
stdio: "ignore",
16-
detached: true
13+
cservice = spawn(process.execPath, args, {
14+
stdio: "ignore",
15+
detached: true
1716
});
1817

1918
cservice.on('exit', function (code) {
20-
console.error('cluster-service exited: ' + code);
19+
console.error('cluster-service exited: ' + code);
2120
});
2221

2322
cservice.unref(); // unreference so we may exit

cluster-service.js

+37-32
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
var
2-
cluster = require("cluster"),
3-
colors = require("colors"),
4-
locals = require("./lib/defaults")
5-
;
1+
var cluster = require("cluster");
2+
var colors = require("colors");
3+
var locals = require("./lib/defaults");
64

75
module.exports = exports;
86

@@ -14,52 +12,59 @@ exports.results = require("./lib/util").results;
1412
exports.workerReady = require("./lib/worker-ready");
1513

1614
Object.defineProperty(exports, "workers", {
17-
get: require("./lib/workers").get
15+
get: require("./lib/workers").get
1816
});
1917

2018
Object.defineProperty(exports, "isMaster", {
21-
get: function() {
22-
return cluster.isMaster;
23-
}
19+
get: function() {
20+
return cluster.isMaster;
21+
}
2422
});
2523

2624
Object.defineProperty(exports, "isWorker", {
27-
get: function() {
28-
return cluster.isWorker;
29-
}
25+
get: function() {
26+
return cluster.isWorker;
27+
}
3028
});
3129

3230
Object.defineProperty(exports, "options", {
33-
get: function() {
34-
return locals.options;
35-
}
31+
get: function() {
32+
return locals.options;
33+
}
3634
});
3735

3836
Object.defineProperty(exports, "locals", {
39-
get: function() {
40-
return locals;
41-
}
37+
get: function() {
38+
return locals;
39+
}
4240
});
4341

4442
if (cluster.isMaster === true) {
45-
exports.control = require("./lib/control").addControls;
46-
exports.stop = require("./lib/stop");
47-
exports.trigger = require("./lib/trigger");
48-
exports.newWorker = require("./lib/new-worker");
49-
exports.on = require("./lib/on");
43+
exports.control = require("./lib/control").addControls;
44+
exports.stop = require("./lib/stop");
45+
exports.trigger = require("./lib/trigger");
46+
exports.newWorker = require("./lib/new-worker");
47+
exports.on = require("./lib/on");
5048
} else {
51-
exports.on = function() { };
49+
exports.on = function() {
50+
};
5251
}
5352

5453
exports.start = require("./lib/start");
5554

56-
if (cluster.isWorker === true && typeof (cluster.worker.module) === "undefined") {
57-
cluster.worker.module = {}; // intermediate state to prevent 2nd call while async in progress
58-
// load the worker if not already loaded
59-
setTimeout(function() { // async, in case worker loads cluster-service, we need to return before it's avail
60-
cluster.worker.module = require(process.env.worker);
61-
}, 10);
55+
if (
56+
cluster.isWorker === true
57+
&& typeof (cluster.worker.module) === "undefined"
58+
){
59+
// intermediate state to prevent 2nd call while async in progress
60+
cluster.worker.module = {};
61+
// load the worker if not already loaded
62+
// async, in case worker loads cluster-service, we need to return before
63+
// it's avail
64+
setTimeout(function() {
65+
cluster.worker.module = require(process.env.worker);
66+
}, 10);
6267

63-
// start worker monitor to establish two-way relationship with master
64-
require("./lib/workers").monitor();
68+
// start worker monitor to establish two-way relationship with master
69+
require("./lib/workers").monitor();
6570
}

lib/cli.js

+46-47
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,64 @@
1-
var
2-
cservice = require("../cluster-service"),
3-
util = require("util"),
4-
locals = null,
5-
options = null
6-
;
1+
var cservice = require("../cluster-service"),
2+
util = require("util"),
3+
locals = null,
4+
options = null;
75

86
exports.init = function(l, o) {
9-
locals = l;
10-
options = o;
7+
locals = l;
8+
options = o;
119

12-
util.inspect.styles.name = "grey";
10+
util.inspect.styles.name = "grey";
1311

14-
cservice.log("CLI is now available. Enter 'help [enter]' for instructions.".info);
15-
process.stdin.resume();
16-
process.stdin.setEncoding('utf8');
17-
18-
process.stdin.on("data", onCommand);
12+
cservice.log("CLI is now available. Enter 'help [enter]' for instructions.".info);
13+
process.stdin.resume();
14+
process.stdin.setEncoding('utf8');
1915

20-
// wait momentarily before attaching CLI. allows workers a little time to output as needed
21-
setTimeout(function() {
22-
process.stdout.write("cservice> ".cservice);
23-
}, 1000);
16+
process.stdin.on("data", onCommand);
17+
18+
// wait momentarily before attaching CLI. allows workers a little time to output as needed
19+
setTimeout(function() {
20+
process.stdout.write("cservice> ".cservice);
21+
}, 1000);
2422
};
2523

2624
exports.close = function() {
27-
try {
28-
process.stdin.pause();
29-
} catch (ex) {
30-
}
25+
try {
26+
process.stdin.pause();
27+
} catch (ex) {
28+
}
3129
};
3230

3331
function onCommand(question) {
34-
question = question.replace(/[\r\n]/g, "");
35-
var args = require("./util").getArgsFromQuestion(question, " ");
36-
args = [args[0], onCallback].concat(args.slice(1));
37-
38-
if (!locals.events[args[0]]) {
39-
onCallback("Command " + args[0] + " not found. Try 'help'.");
32+
var args;
33+
question = question.replace(/[\r\n]/g, "");
34+
args = require("./util").getArgsFromQuestion(question, " ");
35+
args = [args[0], onCallback].concat(args.slice(1));
36+
37+
if (!locals.events[args[0]]) {
38+
onCallback("Command " + args[0] + " not found. Try 'help'.");
39+
40+
return;
41+
}
4042

41-
return;
42-
}
43-
44-
try {
45-
cservice.trigger.apply(null, args);
46-
} catch(ex) {
47-
cservice.error("Command Error " + args[0], util.inspect(ex, { depth:null } ), ex.stack || new Error().stack);
43+
try {
44+
cservice.trigger.apply(null, args);
45+
} catch (ex) {
46+
cservice.error("Command Error " + args[0], util.inspect(ex, {depth: null}), ex.stack || new Error().stack);
4847

49-
onCallback();
50-
}
48+
onCallback();
49+
}
5150
}
5251

5352
function onCallback(err, result) {
54-
delete locals.reason;
55-
56-
if (err) {
57-
cservice.error("Error: ", err, err.stack ? util.inspect(err.stack, { depth:null, colors: true}) : "");
58-
} else if (result) {
59-
cservice.log(util.inspect(result, { depth: null, colors: true }));
60-
}
53+
delete locals.reason;
54+
55+
if (err) {
56+
cservice.error("Error: ", err, err.stack ? util.inspect(err.stack, {depth: null, colors: true}) : "");
57+
} else if (result) {
58+
cservice.log(util.inspect(result, {depth: null, colors: true}));
59+
}
60+
61+
//cservice.log("");//newline
6162

62-
//cservice.log("");//newline
63-
64-
process.stdout.write("cservice> ".cservice);
63+
process.stdout.write("cservice> ".cservice);
6564
}

lib/commands/exit.js

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
var
2-
util = require("util"),
3-
cservice = require("../../cluster-service")
4-
;
1+
var util = require("util"),
2+
cservice = require("../../cluster-service");
53

64
module.exports = function(evt, cb, cmd) {
7-
if (cmd !== "now") {
8-
cb("Invalid request, 'now' required. Try help exit");
9-
return;
10-
}
5+
if (cmd !== "now") {
6+
cb("Invalid request, 'now' required. Try help exit");
7+
return;
8+
}
119

12-
cservice.log("*** FORCEFUL TERMINATION REQUESTED ***".warn);
13-
cservice.log("Exiting now.".warn);
10+
cservice.log("*** FORCEFUL TERMINATION REQUESTED ***".warn);
11+
cservice.log("Exiting now.".warn);
1412

15-
process.exit(0); // exit master
13+
process.exit(0); // exit master
1614

17-
cb(null, "Exiting now.");
15+
cb(null, "Exiting now.");
1816
};
1917

2018
module.exports.more = function(cb) {
21-
cb(null, {
22-
info: "Forcefully exits the service.",
23-
command: "exit now",
24-
"now": "Required. 'now' to force exit."
25-
});
19+
cb(null, {
20+
info: "Forcefully exits the service.",
21+
command: "exit now",
22+
"now": "Required. 'now' to force exit."
23+
});
2624
};
2725

28-
module.exports.control = function(){
29-
return "local";
26+
module.exports.control = function() {
27+
return "local";
3028
};

lib/commands/health.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
var
2-
cluster = require("cluster")
3-
;
1+
var cluster = require("cluster");
42

53
module.exports = function(evt, cb) {
6-
cb(null, "OK");
4+
cb(null, "OK");
75
};
86

97
module.exports.more = function(cb) {
10-
cb(null, {
11-
command: "health",
12-
info: "Returns health of service. May be overidden by service to expose app-specific data."
13-
});
8+
cb(null, {
9+
command: "health",
10+
info: [
11+
"Returns health of service.",
12+
"May be overidden by service to expose app-specific data."
13+
].join(' ')
14+
});
1415
};

0 commit comments

Comments
 (0)