bug fixes
This commit is contained in:
parent
f2a95e291a
commit
985e3811e3
14 changed files with 758 additions and 78 deletions
|
|
@ -1,7 +1,9 @@
|
|||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
module.exports = {
|
||||
load,
|
||||
const pluginCodes = {
|
||||
TICKER: 'ticker',
|
||||
EXCHANGE: 'exchange',
|
||||
WALLET: 'wallet',
|
||||
|
|
@ -9,9 +11,10 @@ module.exports = {
|
|||
EMAIL: 'email'
|
||||
}
|
||||
|
||||
module.exports = _.assign({load, loadSchemas}, pluginCodes)
|
||||
|
||||
function load (type, pluginCode) {
|
||||
const me = module.exports
|
||||
if (!_.includes(type, [me.TICKER, me.EXCHANGE, me.WALLET, me.SMS, me.EMAIL])) {
|
||||
if (!_.includes(type, _.values(pluginCodes))) {
|
||||
throw new Error(`Unallowed plugin type: ${type}`)
|
||||
}
|
||||
|
||||
|
|
@ -21,3 +24,11 @@ function load (type, pluginCode) {
|
|||
|
||||
return require(`./plugins/${type}/${pluginCode}/${pluginCode}`)
|
||||
}
|
||||
|
||||
function loadSchemas () {
|
||||
const schemasRoot = path.resolve(__dirname, '..', 'schemas')
|
||||
const schemaFiles = fs.readdirSync(schemasRoot)
|
||||
const stripJson = fileName => fileName.slice(0, -5)
|
||||
const readSchema = fileName => JSON.parse(fs.readFileSync(path.resolve(schemasRoot, fileName)))
|
||||
return _.zipObject(_.map(stripJson, schemaFiles), _.map(readSchema, schemaFiles))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue