2017-11-05 13:04:59 +03:00
|
|
|
var debug = require('ghost-ignition').debug('channels:loader'),
|
|
|
|
_ = require('lodash'),
|
2017-11-10 23:52:50 +03:00
|
|
|
path = require('path'),
|
2017-11-05 13:04:59 +03:00
|
|
|
Channel = require('./Channel'),
|
2017-10-24 19:18:35 +03:00
|
|
|
channels = [];
|
2015-10-25 23:00:29 +03:00
|
|
|
|
2017-10-24 19:18:35 +03:00
|
|
|
function loadConfig() {
|
|
|
|
var channelConfig = {};
|
2015-12-07 23:06:35 +03:00
|
|
|
|
2017-10-24 19:18:35 +03:00
|
|
|
// This is a very dirty temporary hack so that we can test out channels with some Beta testers
|
|
|
|
// If you are reading this code, and considering using it, best reach out to us on Slack
|
|
|
|
// Definitely don't be angry at us if the structure of the JSON changes or this goes away.
|
|
|
|
try {
|
2017-11-10 23:52:50 +03:00
|
|
|
channelConfig = require(path.join(process.cwd(), 'config.channels.json'));
|
2017-10-24 19:18:35 +03:00
|
|
|
} catch (err) {
|
|
|
|
channelConfig = require('./config.channels.json');
|
|
|
|
}
|
|
|
|
|
|
|
|
return channelConfig;
|
|
|
|
}
|
2015-10-25 23:00:29 +03:00
|
|
|
|
2016-02-09 17:14:24 +03:00
|
|
|
module.exports.list = function list() {
|
2017-11-05 13:04:59 +03:00
|
|
|
debug('Load channels start');
|
2017-10-24 19:18:35 +03:00
|
|
|
_.each(loadConfig(), function (channelConfig, channelName) {
|
2017-11-05 13:04:59 +03:00
|
|
|
channels.push(new Channel(channelName, channelConfig));
|
2017-10-24 19:18:35 +03:00
|
|
|
});
|
2016-02-09 17:14:24 +03:00
|
|
|
|
2017-11-05 13:04:59 +03:00
|
|
|
debug('Load channels end');
|
2017-10-24 19:18:35 +03:00
|
|
|
return channels;
|
2016-02-09 17:14:24 +03:00
|
|
|
};
|