Merge branch '280-config-revamp' of github.com:NuSkooler/enigma-bbs into 280-config-revamp

This commit is contained in:
Bryan Ashby
2020-07-06 21:31:26 -06:00
43 changed files with 4249 additions and 4865 deletions

View File

@@ -1055,6 +1055,14 @@ function peg$parse(input, options) {
}
const points = user.getPropertyAsNumber(UserProps.AchievementTotalPoints) || 0;
return !isNan(value) && points >= value;
},
PV : function userPropValue() {
if (!user || !Array.isArray(value) || value.length !== 2) {
return false;
}
const [propName, propValue] = value;
const actualPropValue = user.getProperty(propName);
return actualPropValue === propValue;
}
}[acsCode](value);
} catch (e) {

View File

@@ -12,7 +12,12 @@ exports.Config = class Config extends ConfigLoader {
super(options);
}
static create(baseConfigPath, cb) {
static create(baseConfigPath, options, cb) {
if (!cb && _.isFunction(options)) {
cb = options;
options = {};
}
const replacePaths = [
'loginServers.ssh.algorithms.kex',
'loginServers.ssh.algorithms.cipher',
@@ -24,7 +29,7 @@ exports.Config = class Config extends ConfigLoader {
'args', 'sendArgs', 'recvArgs', 'recvArgsNonBatch',
];
const options = {
const configOptions = Object.assign({}, options, {
defaultConfig : DefaultConfig,
defaultsCustomizer : (defaultVal, configVal, key, path) => {
if (Array.isArray(defaultVal) && Array.isArray(configVal)) {
@@ -43,9 +48,9 @@ exports.Config = class Config extends ConfigLoader {
Events.emit(Events.getSystemEvents().ConfigChanged);
}
},
};
});
systemConfigInstance = new Config(options);
systemConfigInstance = new Config(configOptions);
systemConfigInstance.init(baseConfigPath, err => {
if (err) {
return cb(err);

View File

@@ -13,12 +13,14 @@ module.exports = class ConfigLoader {
defaultConfig = {},
defaultsCustomizer = null,
onReload = null,
keepWsc = false,
} =
{
hotReload : true,
defaultConfig : {},
defaultsCustomizer : null,
onReload : null,
keepWsc : false,
}
)
{
@@ -28,6 +30,7 @@ module.exports = class ConfigLoader {
this.defaultConfig = defaultConfig;
this.defaultsCustomizer = defaultsCustomizer;
this.onReload = onReload;
this.keepWsc = keepWsc;
}
init(baseConfigPath, cb) {
@@ -158,7 +161,8 @@ module.exports = class ConfigLoader {
let value = process.env[varName];
if (!value) {
return;
// console is about as good as we can do here
return console.info(`WARNING: environment variable "${varName}" from spec "${spec}" not found!`);
}
if ('array' === array) {
@@ -176,6 +180,7 @@ module.exports = class ConfigLoader {
const options = {
filePath,
hotReload : this.hotReload,
keepWsc : this.keepWsc,
callback : this._configFileChanged.bind(this),
};

View File

@@ -9,9 +9,9 @@ const paths = require('path');
exports.getConfigPath = getConfigPath;
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);
if (paths.isAbsolute(filePath)) {
return filePath;
}
return filePath;
return paths.join(Config().paths.config, filePath);
}

View File

@@ -37,7 +37,7 @@ function getMenuConfig(client, name, cb) {
menuConfig.promptConfig = client.currentTheme.prompts[menuConfig.prompt];
return callback(null, menuConfig);
}
return callback(Error.DoesNotExist(`No prompt entry for "${menuConfig.prompt}"`));
return callback(Errors.DoesNotExist(`No prompt entry for "${menuConfig.prompt}"`));
}
return callback(null, menuConfig);
}

View File

@@ -60,13 +60,14 @@ exports.getModule = class MessageListModule extends MessageAreaConfTempSwitcher(
this.menuMethods = {
selectMessage : (formData, extraArgs, cb) => {
if(MciViewIds.allViews.msgList === formData.submitId) {
this.initialFocusIndex = formData.value.message;
// 'messageIndex' or older deprecated 'message' member
this.initialFocusIndex = _.get(formData, 'value.messageIndex', formData.value.message);
const modOpts = {
extraArgs : {
messageAreaTag : this.getSelectedAreaTag(formData.value.message),
messageAreaTag : this.getSelectedAreaTag(this.initialFocusIndex),
messageList : this.config.messageList,
messageIndex : formData.value.message,
messageIndex : this.initialFocusIndex,
lastMessageNextExit : true,
}
};
@@ -107,7 +108,9 @@ exports.getModule = class MessageListModule extends MessageAreaConfTempSwitcher(
if(MciViewIds.allViews.msgList != formData.submitId) {
return cb(null);
}
const messageIndex = _.get(formData, 'value.message');
// newer 'messageIndex' or older deprecated value
const messageIndex = _.get(formData, 'value.messageIndex', formData.value.message);
return this.promptDeleteMessageConfirm(messageIndex, cb);
},
deleteMessageYes : (formData, extraArgs, cb) => {

View File

@@ -64,14 +64,14 @@ function getDefaultConfigPath() {
}
function getConfigPath() {
const baseConfigPath = argv.config ? argv.config : config.getDefaultPath();
const baseConfigPath = argv.config ? argv.config : config.Config.getDefaultPath();
return baseConfigPath + 'config.hjson';
}
function initConfig(cb) {
const configPath = getConfigPath();
config.init(configPath, { keepWsc : true, hotReload : false }, cb);
config.Config.create(configPath, { keepWsc : true, hotReload : false }, cb);
}
function initConfigAndDatabases(cb) {

View File

@@ -227,26 +227,44 @@ function buildNewConfig() {
if(err) { return;
}
const bn = sanatizeFilename(config.general.boardName)
const boardName = sanatizeFilename(config.general.boardName)
.replace(/[^a-z0-9_-]/ig, '_')
.replace(/_+/g, '_')
.toLowerCase();
const menuFile = `${bn}-menu.hjson`;
copyFileSyncSilent(
paths.join(__dirname, '../../misc/menu_template.in.hjson'),
paths.join(__dirname, '../../config/', menuFile),
fs.constants.COPYFILE_EXCL
const includeFilesIn = [
'message_base.in.hjson',
'private_mail.in.hjson',
'login.in.hjson',
'new_user.in.hjson',
'doors.in.hjson',
'file_base.in.hjson',
];
let includeFiles = [];
includeFilesIn.forEach(incFile => {
const outName = `${boardName}-${incFile.replace('.in', '')}`;
includeFiles.push(outName);
copyFileSyncSilent(
paths.join(__dirname, '../../misc/menu_templates', incFile),
paths.join(__dirname, '../../config/menus', outName),
fs.constants.COPYFILE_EXCL
);
});
// We really only need includes to be replaced
const mainTemplate = fs.readFileSync(paths.join(__dirname, '../../misc/menu_templates/main.in.hjson'), 'utf8')
.replace(/%INCLUDE_FILES%/g, includeFiles.join('\n\t\t')); // cheesy, but works!
const menuFile = `${boardName}-main.hjson`;
fs.writeFileSync(
paths.join(__dirname, '../../config/menus', menuFile),
mainTemplate,
'utf8'
);
const promptFile = `${bn}-prompt.hjson`;
copyFileSyncSilent(
paths.join(__dirname, '../../misc/prompt_template.in.hjson'),
paths.join(__dirname, '../../config/', promptFile),
fs.constants.COPYFILE_EXCL
);
config.general.menuFile = menuFile;
config.general.promptFile = promptFile;
config.general.menuFile = paths.join(__dirname, '../../config/menus/', menuFile);
if(writeConfig(config, configPath)) {
console.info('Configuration generated');

View File

@@ -121,7 +121,7 @@ exports.ThemeManager = class ThemeManager {
onReload : err => {
if (!err) {
// this particular theme has changed
this._themeLoaded(themeId, err => {
this._themeLoaded(themeId, themeConfig, err => {
if (!err) {
Events.emit(
Events.getSystemEvents().ThemeChanged,

View File

@@ -171,7 +171,7 @@ exports.getModule = class UserConfigModule extends MenuModule {
},
function prepareAvailableThemes(callback) {
self.availThemeInfo = _.sortBy([...theme.getAvailableThemes()].map(entry => {
const theme = entry[1];
const theme = entry[1].get();
return {
themeId : theme.info.themeId,
name : theme.info.name,