2016-01-15 05:56:21 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
2018-06-14 03:02:00 +00:00
|
|
|
|
2018-06-21 01:57:06 +00:00
|
|
|
const Config = require('./config.js').get;
|
2018-06-14 03:02:00 +00:00
|
|
|
const ConfigCache = require('./config_cache.js');
|
|
|
|
const Events = require('./events.js');
|
|
|
|
|
|
|
|
// deps
|
2017-11-22 23:27:33 +00:00
|
|
|
const paths = require('path');
|
2018-06-14 03:02:00 +00:00
|
|
|
const async = require('async');
|
2016-01-15 05:56:21 +00:00
|
|
|
|
2018-06-14 03:02:00 +00:00
|
|
|
exports.init = init;
|
2016-01-15 05:56:21 +00:00
|
|
|
exports.getFullConfig = getFullConfig;
|
|
|
|
|
2018-06-14 03:02:00 +00:00
|
|
|
function getConfigPath(filePath) {
|
2018-06-22 05:15:04 +00:00
|
|
|
// |filePath| is assumed to be in the config path if it's only a file name
|
|
|
|
if('.' === paths.dirname(filePath)) {
|
|
|
|
filePath = paths.join(Config().paths.config, filePath);
|
|
|
|
}
|
|
|
|
return filePath;
|
2018-06-14 03:02:00 +00:00
|
|
|
}
|
2016-01-15 05:56:21 +00:00
|
|
|
|
2018-06-14 03:02:00 +00:00
|
|
|
function init(cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
// pre-cache menu.hjson and prompt.hjson + establish events
|
|
|
|
const changed = ( { fileName, fileRoot } ) => {
|
|
|
|
const reCachedPath = paths.join(fileRoot, fileName);
|
|
|
|
if(reCachedPath === getConfigPath(Config().general.menuFile)) {
|
|
|
|
Events.emit(Events.getSystemEvents().MenusChanged);
|
|
|
|
} else if(reCachedPath === getConfigPath(Config().general.promptFile)) {
|
|
|
|
Events.emit(Events.getSystemEvents().PromptsChanged);
|
|
|
|
}
|
|
|
|
};
|
2018-06-14 03:02:00 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const config = Config();
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function menu(callback) {
|
|
|
|
return ConfigCache.getConfigWithOptions(
|
|
|
|
{
|
|
|
|
filePath : getConfigPath(config.general.menuFile),
|
|
|
|
callback : changed,
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function prompt(callback) {
|
|
|
|
return ConfigCache.getConfigWithOptions(
|
|
|
|
{
|
|
|
|
filePath : getConfigPath(config.general.promptFile),
|
|
|
|
callback : changed,
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
2018-06-14 03:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getFullConfig(filePath, cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
ConfigCache.getConfig(getConfigPath(filePath), (err, config) => {
|
|
|
|
return cb(err, config);
|
|
|
|
});
|
2018-06-14 03:02:00 +00:00
|
|
|
}
|