mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-10 22:54:37 +02:00
Initial version of hot-reload of config, menus, and prompts
* Themes use ES6 Map vs object{} * Re-write and re-enable config cache using sane * Events sent for config, prompt, or menu changes * Event sent for theme changes * Theme (or parent menu/prompt) changes cause re-merge and updates to connected clients
This commit is contained in:
parent
1870db7d38
commit
4aab8224ed
8 changed files with 275 additions and 242 deletions
|
@ -1,18 +1,65 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
const Config = require('./config.js').config;
|
||||
const configCache = require('./config_cache.js');
|
||||
const paths = require('path');
|
||||
|
||||
const Config = require('./config.js').config;
|
||||
const ConfigCache = require('./config_cache.js');
|
||||
const Events = require('./events.js');
|
||||
|
||||
// deps
|
||||
const paths = require('path');
|
||||
const async = require('async');
|
||||
|
||||
exports.init = init;
|
||||
exports.getFullConfig = getFullConfig;
|
||||
|
||||
function getFullConfig(filePath, cb) {
|
||||
function getConfigPath(filePath) {
|
||||
// |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;
|
||||
}
|
||||
|
||||
configCache.getConfig(filePath, function loaded(err, configJson) {
|
||||
cb(err, configJson);
|
||||
function init(cb) {
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function getFullConfig(filePath, cb) {
|
||||
ConfigCache.getConfig(getConfigPath(filePath), (err, config) => {
|
||||
return cb(err, config);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue