Skip to content

Commit

Permalink
[minor dist] Added LICENSE. Refactor forever.js to be more DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Sep 28, 2010
1 parent 9243dee commit f916359
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2009 Charlie Robbins

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
25 changes: 11 additions & 14 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,26 @@ Forever.prototype.run = function () {
var self = this, child = spawn('node', this.options.options);
this.child = child;

// Hook all stream data
// And process it
function hookStream(streamType) {
child[streamType].on('data', function (data) {
// Hook all stream data and process it
function listenTo (stream) {
child[stream].on('data', function (data) {
// If we haven't been silenced, write to the process stdout stream
if (!self.options.silent) {
process[streamType].write(data);
process.stdout.write(data);
}

// If we have been given an output file for stdout, write to it
if (self.options[streamType]) {
self[streamType].write(data);
// If we have been given an output file for the stream, write to it
if (self.options[stream]) {
self[stream].write(data);
}

self.emit(streamType, null, data);
self.emit(stream, null, data);
});

// Chaining
return hookStream;
}

// Hook stdout and stderr
hookStream('stdout')('stderr');
// Listen to stdout and stderr
listenTo('stdout');
listenTo('stderr');

child.on('exit', function (code) {
self.times++;
Expand Down

0 comments on commit f916359

Please sign in to comment.