Initial WIP on better 'oputil config new' for testing

This commit is contained in:
Bryan Ashby 2018-11-07 20:24:05 -07:00
parent 7d74556868
commit 93305d44fc
3 changed files with 130 additions and 57 deletions

View File

@ -10,8 +10,9 @@ const async = require('async');
const _ = require('lodash');
const assert = require('assert');
exports.init = init;
exports.getDefaultPath = getDefaultPath;
exports.init = init;
exports.getDefaultPath = getDefaultPath;
exports.getDefaultConfig = getDefaultConfig;
let currentConfiguration = {};
@ -133,8 +134,8 @@ function getDefaultConfig() {
general : {
boardName : 'Another Fine ENiGMA½ BBS',
// :TODO: closedSystem and loginAttemps prob belong under users{}?
closedSystem : false, // is the system closed to new users?
loginAttempts : 3,
menuFile : 'menu.hjson', // Override to use something else, e.g. demo.hjson. Can be a full path (defaults to ./config)
@ -173,7 +174,7 @@ function getDefaultConfig() {
default : 'luciano_blocktronics',
preLogin : 'luciano_blocktronics',
passwordChar : '*', // TODO: move to user ?
passwordChar : '*',
dateFormat : {
short : 'MM/DD/YYYY',
long : 'ddd, MMMM Do, YYYY',

View File

@ -30,6 +30,10 @@ function getAnswers(questions, cb) {
});
}
const ConfigIncludeKeys = [
'theme',
];
const QUESTIONS = {
Intro : [
{
@ -72,12 +76,6 @@ const QUESTIONS = {
default : 2,
filter : s => s.toLowerCase(),
},
{
name : 'sevenZipExe',
message : '7-Zip executable:',
type : 'list',
choices : [ '7z', '7za', 'None' ]
}
],
MessageConfAndArea : [
@ -149,27 +147,34 @@ function askNewConfigQuestions(cb) {
function promptOverwrite(needPrompt, callback) {
if(needPrompt) {
getAnswers(QUESTIONS.OverwriteConfig, answers => {
callback(answers.overwriteConfig ? null : 'exit');
return callback(answers.overwriteConfig ? null : 'exit');
});
} else {
callback(null);
return callback(null);
}
},
function basic(callback) {
getAnswers(QUESTIONS.Basic, answers => {
config = {
general : {
boardName : answers.boardName,
},
};
const defaultConfig = require('../../core/config.js').getDefaultConfig();
callback(null);
// start by plopping in values we want directly from config.js
const template = hjson.rt.parse(fs.readFileSync(paths.join(__dirname, '../../misc/config_template.in.hjson'), 'utf8'));
const direct = {};
_.each(ConfigIncludeKeys, keyPath => {
_.set(direct, keyPath, _.get(defaultConfig, keyPath));
});
config = _.mergeWith(template, direct);
// we can override/add to it based on user input from this point on...
config.general.boardName = answers.boardName;
return callback(null);
});
},
function msgConfAndArea(callback) {
getAnswers(QUESTIONS.MessageConfAndArea, answers => {
config.messageConferences = {};
const confName = makeMsgConfAreaName(answers.msgConfName);
const areaName = makeMsgConfAreaName(answers.msgAreaName);
@ -180,12 +185,6 @@ function askNewConfigQuestions(cb) {
default : true,
};
config.messageConferences.another_sample_conf = {
name : 'Another Sample Conference',
desc : 'Another conference example. Change me!',
sort : 2,
};
config.messageConferences[confName].areas = {};
config.messageConferences[confName].areas[areaName] = {
name : answers.msgAreaName,
@ -194,51 +193,25 @@ function askNewConfigQuestions(cb) {
default : true,
};
config.messageConferences.another_sample_conf = {
name : 'Another Sample Conference',
desc : 'Another conf sample. Change me!',
areas : {
another_sample_area : {
name : 'Another Sample Area',
desc : 'Another area example. Change me!',
sort : 2
}
}
};
callback(null);
return callback(null);
});
},
function misc(callback) {
getAnswers(QUESTIONS.Misc, answers => {
if('None' !== answers.sevenZipExe) {
config.archivers = {
zip : {
compressCmd : answers.sevenZipExe,
decompressCmd : answers.sevenZipExe,
}
};
}
config.logging.rotatingFile.level = answers.loggingLevel;
config.logging = {
rotatingFile : {
level : answers.loggingLevel,
}
};
callback(null);
return callback(null);
});
}
],
err => {
cb(err, configPath, config);
return cb(err, configPath, config);
}
);
}
function writeConfig(config, path) {
config = hjson.stringify(config, { bracesSameLine : true, spaces : '\t', keepWsc : true, quotes : 'strings' } );
config = hjson.stringify(config, { bracesSameLine : true, space : '\t', keepWsc : true, quotes : 'strings' } );
try {
fs.writeFileSync(path, config, 'utf8');

View File

@ -0,0 +1,99 @@
{
/*
./\/\.' ENiGMA½ System Configuration -/--/-------- - -- -
_____________________ _____ ____________________ __________\_ /
\__ ____/\_ ____ \ /____/ / _____ __ \ / ______/ // /___jp!
// __|___// | \// |// | \// | | \// \ /___ /_____
/____ _____| __________ ___|__| ____| \ / _____ \
---- \______\ -- |______\ ------ /______/ ---- |______\ - |______\ /__/ // ___/
/__ _\
<*> ENiGMA½ // HTTPS://GITHUB.COM/NUSKOOLER/ENIGMA-BBS <*> /__/
-------------------------------------------------------------------------------
General Information
-------------------------------
This configuration is in HJSON (http://hjson.org/) format. Strict to-spec
JSON is also perfectly valid. Use 'hjson' from npm to convert to/from JSON.
See http://hjson.org/ for more information and syntax.
Various editors and IDEs have plugins for the HJSON format which can be
very useful.
Available Configuration
-------------------------------
ENiGMA½ is highly configurable! By default, this file contains common
configuration elements, examples, etc. To see a full list of settings
available to this file, don't be afraid to open up core/config.js and
look around. Do not make changes there however, you may override any
of the configuration from within this file!
See the documentation for more information, and don't be shy to ask
for help!
*/
general: {
// Your BBS Name!
boardName: XXXXX
}
logging: {
// By default, the system will rotate logs.
// Remember you can pipe logs through bunyan to pretty-print:
// > tail -F enigma/logs/enigma-bbs.log | enigma/node_modules/bunyan/bin/bunyan
rotatingFile: {
// If you're having trouble, try setting this to "trace"
level: XXXXX
}
}
theme: {
// Default theme applied to new users. "*" indicates random.
default: XXXXX
// Theme applied before a user has logged in. "*" indicates random.
preLogin: XXXXX
}
// Message conferences and areas are within this block
messageConferences: {
// An entry here prepresents a conference taka aka confTag
another_sample_conf: {
name: "Another Sample Conference"
desc: "Another conf sample. Change me!"
areas: {
// Similar to confTags, this is a areaTag
another_sample_area: {
name: "Another Sample Area"
desc: "Another area example. Change me!"
// The 'sort' key can override natural sort order and can live at the conference and area levels
sort: 2
}
}
}
}
// Archive files and related
archives: {
// External utilities used for import & upload processing archives such
// as .zip, .rar, .arj, etc.
//
// You'll want to have archivers configured for the many old-school archive
// formats that a BBS may encounter!
//
// See config.js for additional configuration
archivers: {
//
// Each key in the "archivers" configuration block represents a specific
// external archive utility. ENiGMA½ has sane configuration by default
// for many archivers, but the tools themselves are likely not yet installed
// on your system!
//
// Please consult the documentation on information as to where to find and
// install these utilities!
//
}
}
}