diff options
Diffstat (limited to 'server/src/scripts/configLib')
-rw-r--r-- | server/src/scripts/configLib/SetupWizard.js | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/server/src/scripts/configLib/SetupWizard.js b/server/src/scripts/configLib/SetupWizard.js index bd6ef24..ac2f3a0 100644 --- a/server/src/scripts/configLib/SetupWizard.js +++ b/server/src/scripts/configLib/SetupWizard.js @@ -1,40 +1,36 @@ +import { + start as _start, + get, +} from 'prompt'; + /** * Server setup wizard, quick server setup and all that jazz. . . - * - * Version: v2.0.0 - * Developer: Marzavec ( https://github.com/marzavec ) - * License: WTFPL ( http://www.wtfpl.net/txt/copying/ ) - * + * @author Marzavec ( https://github.com/marzavec ) + * @version v2.0.0 + * @license WTFPL ( http://www.wtfpl.net/txt/copying/ ) */ - -const fse = require('fs-extra'); -const prompt = require('prompt'); -const path = require('path'); - class SetupWizard { /** * Create a `SetupWizard` instance for initializing the server's config.json - * * @param {Object} serverConfig reference to the server config class */ - constructor (serverConfig) { + constructor(serverConfig) { this.serverConfig = serverConfig; } /** * Roll a d20 and begin the wizarding process - * */ - async start () { + async start() { // load the current config to use as defaults, if available - let currentConfig = await this.serverConfig.load() || {}; + const currentConfig = await this.serverConfig.load() || {}; // auto generate the salt if not currrently created - currentConfig.tripSalt = currentConfig.tripSalt || - [...Array(Math.floor(Math.random()*1024)+1024)].map(i=>(~~(Math.random()*36)).toString(36)).join(''); + currentConfig.tripSalt = currentConfig.tripSalt + || [...Array(Math.floor(Math.random() * 1024) + 1024)].map(() => (~~(Math.random() * 36)).toString(36)).join(''); // load the setup questions & set their defaults - let questions = require('../setupSchema/Questions.js'); + const questions = require('../setupSchema/Questions.js'); questions.properties = this.setQuestionDefaults(questions.properties, currentConfig); // force password re-entry @@ -45,19 +41,18 @@ class SetupWizard { require('../setupSchema/Banner.js'); // let's start playing 20 questions - prompt.start(); - prompt.get(questions, (err, result) => this.finalize(err, result)); + _start(); + get(questions, (err, result) => this.finalize(err, result)); } /** * Compares the currently loaded config with the stock questions, adds a default * and required option to the question - * * @param {Object} questions the set of questions from /setupSchema * @param {Object} currentConfig the current server options */ - setQuestionDefaults (questions, currentConfig) { - Object.keys(questions).forEach(qName => { + setQuestionDefaults(questions, currentConfig) { + Object.keys(questions).forEach((qName) => { if (typeof currentConfig[qName] !== 'undefined') { questions[qName].default = currentConfig[qName]; questions[qName].required = false; @@ -76,7 +71,7 @@ class SetupWizard { * @param {Object} err any errors generated by Prompt * @param {Object} result the answers / new config setup */ - async finalize (err, result) { + async finalize(err, result) { // output errors and die if needed if (err) { console.error(err); @@ -87,7 +82,7 @@ class SetupWizard { if (typeof result.mods === 'undefined') { result.mods = []; } - + // If we should log errors with the err stack when they occur. // See: CommandManager.js if (typeof result.logErrDetailed === 'undefined') { @@ -110,4 +105,4 @@ class SetupWizard { } } -module.exports = SetupWizard; +export default SetupWizard; |