This repository has been archived by the owner on Feb 16, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gekkoStream wrapper for plugins; hooked up to budfox
- Loading branch information
Showing
9 changed files
with
238 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Small writable stream wrapper that | ||
// passes data to all `candleProcessors`. | ||
|
||
var Writable = require('stream').Writable; | ||
var _ = require('lodash'); | ||
|
||
var Gekko = function(candleProcessors) { | ||
this.candleProcessors = candleProcessors; | ||
Writable.call(this, {objectMode: true}); | ||
} | ||
|
||
Gekko.prototype = Object.create(Writable.prototype, { | ||
constructor: { value: Gekko } | ||
}); | ||
|
||
Gekko.prototype._write = function(chunk, encoding, callback) { | ||
_.each(this.candleProcessors, function(p) { | ||
p.processCandle(chunk); | ||
}); | ||
|
||
callback(); | ||
} | ||
|
||
module.exports = Gekko; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
|
||
var util = require(__dirname + '/util'); | ||
|
||
var log = require(util.dirs().core + 'log'); | ||
|
||
var config = util.getConfig(); | ||
var pluginDir = util.dirs().plugins; | ||
var gekkoMode = util.gekkoMode(); | ||
|
||
var pluginHelper = { | ||
// Checks whether we can load a module | ||
|
||
// @param Object plugin | ||
// plugin config object | ||
// @return String | ||
// error message if we can't | ||
// use the module. | ||
cannotLoad: function(plugin) { | ||
// verify plugin dependencies are installed | ||
if(_.has(plugin, 'dependencies')) | ||
_.each(plugin.dependencies, function(dep) { | ||
try { | ||
require(dep.module); | ||
} | ||
catch(e) { | ||
return [ | ||
'The plugin', | ||
module.slug, | ||
'expects the module', | ||
dep.module, | ||
'to be installed.', | ||
'However it is not, install', | ||
'it by running: \n\n', | ||
'\tnpm install', | ||
dep.module + '@' + dep.version | ||
]; | ||
} | ||
}); | ||
}, | ||
// loads a plugin | ||
// | ||
// @param Object plugin | ||
// plugin config object | ||
// @param Function next | ||
// callback | ||
load: function(plugin, next) { | ||
|
||
plugin.config = config[plugin.slug]; | ||
|
||
if(!plugin.config) | ||
log.warn( | ||
'unable to find', | ||
plugin.slug, | ||
'in the config. Is your config up to date?' | ||
); | ||
|
||
if(!plugin.config || !plugin.config.enabled) | ||
return next(); | ||
|
||
log.info('Setting up:'); | ||
log.info('\t', plugin.name); | ||
log.info('\t', plugin.description); | ||
|
||
var cannotLoad = pluginHelper.cannotLoad(plugin); | ||
if(cannotLoad) | ||
return next(cannotLoad); | ||
|
||
var Constructor = require(pluginDir + plugin.slug); | ||
|
||
if(plugin.async) { | ||
var instance = new Constructor(util.defer(function(err) { | ||
next(err, instance); | ||
})); | ||
instance.meta = plugin; | ||
} else { | ||
var instance = new Constructor; | ||
instance.meta = plugin; | ||
_.defer(function() { | ||
next(null, instance); | ||
}); | ||
} | ||
|
||
if(!plugin.silent) | ||
log.info('\n'); | ||
} | ||
} | ||
|
||
module.exports = pluginHelper; |
Oops, something went wrong.