Skip to content

Commit

Permalink
[dist] Up-to-date linting with JSHint. Fixes #419.
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Nov 4, 2014
1 parent 1d863ba commit 3865596
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 51 deletions.
67 changes: 35 additions & 32 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ function getAllPids(processes) {
//
// ### function stopOrRestart (action, event, format, target)
// #### @action {string} Action that is to be sent to target(s).
// #### @event {string} Event that will be emitted on success.
// #### @event {string} Event that will be emitted on success.
// #### @format {boolean} Indicated if we should CLI format the returned output.
// #### @target {string} Index or script name to stop. Optional.
// #### @target {string} Index or script name to stop. Optional.
// #### If not provided -> action will be sent to all targets.
// Returns emitter that you can use to handle events on failure or success (i.e 'error' or <event>)
//
Expand Down Expand Up @@ -225,9 +225,9 @@ function stopOrRestart(action, event, format, target) {

//
// ### function stopByPid(event, format, pid)
// #### @event {string} Event that will be emitted on success.
// #### @event {string} Event that will be emitted on success.
// #### @format {boolean} Indicated if we should CLI format the returned output.
// #### @pid {string} Pid of the process to stop. Optional.
// #### @pid {string} Pid of the process to stop. Optional.
// Returns emitter that you can use to handle events on failure or success (i.e 'error' or <event>)
//
function stopByPid(event, format, pid) {
Expand Down Expand Up @@ -473,7 +473,7 @@ forever.startDaemon = function (script, options) {
options.logFile = forever.logFilePath(options.logFile || forever.config.get('logFile') || options.uid + '.log');
options.pidFile = forever.pidFilePath(options.pidFile || forever.config.get('pidFile') || options.uid + '.pid');

var monitor, outFD, errFD, workerPath;
var monitor, outFD, errFD, monitorPath;

//
// This log file is forever's log file - the user's outFile and errFile
Expand Down Expand Up @@ -576,7 +576,7 @@ forever.restart = function (target, format) {
// ### function stopbypid (target, format)
// #### @pid {string} Pid of process to stop.
// #### @format {boolean} Indicated if we should CLI format the returned output.
// Stops the process with specified pid
// Stops the process with specified pid
//
forever.stopbypid = function (pid, format) {
// stopByPid only capable of stopping, but can't restart
Expand Down Expand Up @@ -629,20 +629,20 @@ forever.tail = function (target, options, callback) {
options.stream = false;
}

length = options.length || forever.config.get('loglength');
stream = options.stream || forever.config.get('logstream');

var that = this,
blanks = function (e, i, a) { return e !== '' },
title = function (e, i, a) { return e.match(/^==>/) },
args = ['-n', length],
var that = this,
length = options.length || forever.config.get('loglength'),
stream = options.stream || forever.config.get('logstream'),
blanks = function (e, i, a) { return e !== ''; },
title = function (e, i, a) { return e.match(/^==>/); },
args = ['-n', length],
logs;

if (stream) args.unshift('-f');
if (stream) { args.unshift('-f'); }

function tailProcess(procs, next) {
var map = {},
count = 0;
var count = 0,
map = {},
tail;

procs.forEach(function (proc) {
args.push(proc.logFile);
Expand All @@ -658,20 +658,20 @@ forever.tail = function (target, options, callback) {
tail.stdio[2].setEncoding('utf8');

tail.stdio[1].on('data', function (data) {
chunk = data.split('\n\n');
var chunk = data.split('\n\n');
chunk.forEach(function (logs) {
var logs = logs.split('\n').filter(blanks),
file = logs.filter(title),
lines,
proc;

file.length
? proc = map[file[0].split(' ')[1]]
: proc = map[procs[0].logFile];
proc = file.length
? map[file[0].split(' ')[1]]
: map[procs[0].logFile];

count === 1
? lines = logs
: lines = logs.slice(1);
lines = count !== 1
? logs.slice(1)
: logs;

lines.forEach(function (line) {
callback(null, { file: proc.file, pid: proc.pid, line: line });
Expand Down Expand Up @@ -710,14 +710,13 @@ forever.tail = function (target, options, callback) {
// Finds the process with the specified index.
//
forever.findById = function (id, processes) {
if (!processes) return null;
if (!processes) { return null; }

var procs = processes.filter(function (p) {
return p.id == id;
});

if (procs.length === 0) procs = null;

if (procs.length === 0) { procs = null; }
return procs;
};

Expand All @@ -728,9 +727,11 @@ forever.findById = function (id, processes) {
// Finds the process with the specified index.
//
forever.findByIndex = function (index, processes) {
var indexAsNum = parseInt(index, 10);
var indexAsNum = parseInt(index, 10),
proc;

if (indexAsNum == index) {
var proc = processes && processes[indexAsNum];
proc = processes && processes[indexAsNum];
}
return proc ? [proc] : null;
};
Expand All @@ -742,16 +743,18 @@ forever.findByIndex = function (index, processes) {
// Finds the process with the specified script name.
//
forever.findByScript = function (script, processes) {
if (!processes) return null;
if (!processes) { return null; }

// make script absolute.
script.indexOf('/') != 0 && (script = path.resolve(process.cwd(), script));
if (script.indexOf('/') != 0) {
script = path.resolve(process.cwd(), script);
}

var procs = processes.filter(function (p) {
return p.file === script || path.join(p.spawnWith.cwd, p.file) === script;
});

if (procs.length === 0) procs = null;

if (procs.length === 0) { procs = null; }
return procs;
};

Expand Down
8 changes: 4 additions & 4 deletions lib/forever/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ var getOptions = cli.getOptions = function (file) {
].join(' '));
}

options.sourceDir = options.sourceDir || (file && file[0] !== '/' ? process.cwd() : '/');
options.sourceDir = options.sourceDir || (file && file[0] !== '/' ? process.cwd() : '/');
options.workingDir = options.workingDir || options.sourceDir;
options.spawnWith = {cwd: options.workingDir};
options.spawnWith = { cwd: options.workingDir };

return options;
}
};

//
// ### function cleanLogs
Expand Down Expand Up @@ -540,7 +540,7 @@ app.cmd(/columns set (.*)/, cli.setColumns = function (columns) {
});

app.cmd('columns reset', cli.resetColumns = function () {
columns = 'uid command script forever pid logfile uptime'
var columns = 'uid command script forever pid logfile uptime';

forever.log.info('Setting columns: ' + columns.magenta);

Expand Down
17 changes: 11 additions & 6 deletions lib/forever/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var events = require('events'),

var Worker = exports.Worker = function (options) {
events.EventEmitter.call(this);
options || (options = {});
options = options || {};

this.monitor = options.monitor;
this.sockPath = options.sockPath || forever.config.get('sockPath');
Expand Down Expand Up @@ -38,7 +38,7 @@ Worker.prototype.start = function (callback) {
function workerProtocol(socket) {
socket.on('error', function() {
socket.destroy();
})
});

socket.data(['ping'], function () {
socket.send(['pong']);
Expand Down Expand Up @@ -68,7 +68,9 @@ Worker.prototype.start = function (callback) {
socket.data(['stop'], function () {
self.monitor.once('stop', function () {
socket.send(['stop', 'ok']);
self.exitOnStop && process.exit();
if (self.exitOnStop) {
process.exit();
}
});

if (process.platform === 'win32') {
Expand Down Expand Up @@ -100,15 +102,18 @@ Worker.prototype.start = function (callback) {
// `listening` listener doesn't take error as the first parameter
//
self.emit('start');
callback && callback(null, self._sockFile);
if (callback) {
callback(null, self._sockFile);
}
});

self._socket.on('error', function (err) {
if (err.code === 'EADDRINUSE') {
return findAndStart();
}

callback && callback(err);
else if (callback) {
callback(err);
}
});

//
Expand Down
7 changes: 4 additions & 3 deletions test/core/daemonic-inheritance-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ vows.describe('forever/core/startDaemon').addBatch({
"When using forever" : {
"the startDaemon() method with customized configuration" : {
topic: function () {
!fs.existsSync(myRoot) && fs.mkdirSync(myRoot);
if (!fs.existsSync(myRoot)) {
fs.mkdirSync(myRoot);
}

forever.load({root:myRoot});

forever.startDaemon(path.join(__dirname, '..', 'fixtures', 'log-on-interval.js'));
setTimeout(function (that) {
forever.list(false, that.callback);
}, 2000, this)
//forever.tail(0, { length: 1 }, that.callback);
}, 2000, this);
},
"should respond with 1 process": function (err, procs) {
assert.isNull(err);
Expand Down
4 changes: 2 additions & 2 deletions test/core/start-stop-relative-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ vows.describe('forever/core/start-stop-peaceful').addBatch({
]);
setTimeout(function (that) {
forever.list(false, that.callback);
}, 2000, this)
}, 2000, this);
},
"the startup should works fine": function (err, procs) {
assert.isNull(err);
Expand All @@ -49,7 +49,7 @@ vows.describe('forever/core/start-stop-peaceful').addBatch({
]);
setTimeout(function (that) {
forever.list(false, that.callback);
}, 2000, this)
}, 2000, this);
},
"the shut down should works fine": function (err, procs) {
assert.isNull(err);
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macros.assertTimes = function (script, times, options) {
"should emit 'exit' when completed": function (err, child) {
assert.equal(child.times, times);
}
}
};
};

macros.spawn = function (args, options) {
Expand Down Expand Up @@ -61,7 +61,7 @@ macros.spawn = function (args, options) {

macros.list = function (options) {
options.topic = function () {
forever.list(false, this.callback)
forever.list(false, this.callback);
};
return options;
};
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/mocks/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ MonitorMock.prototype.__defineGetter__('data', function () {
return {
uid: '_uid',
command: 'node'
}
};
});

MonitorMock.prototype.kill = MonitorMock.prototype.stop = function (forceStop) {
Expand Down
2 changes: 1 addition & 1 deletion test/worker/multiple-workers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function assertRunning(port, i) {
"stop the child process": function () {
children[i].stop();
}
}
};
}

vows.describe('forever/workers/multiple').addBatch({
Expand Down

0 comments on commit 3865596

Please sign in to comment.