aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/scripts')
-rw-r--r--server/src/scripts/configLib/SetupWizard.js47
-rw-r--r--server/src/scripts/configure.js18
-rw-r--r--server/src/scripts/setupSchema/Banner.js12
-rw-r--r--server/src/scripts/setupSchema/Questions.js20
4 files changed, 44 insertions, 53 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;
diff --git a/server/src/scripts/configure.js b/server/src/scripts/configure.js
index d7f2bf2..d96e0df 100644
--- a/server/src/scripts/configure.js
+++ b/server/src/scripts/configure.js
@@ -1,21 +1,17 @@
/**
* Server configuration script, to (re)configure server options
- *
- * 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/ )
*/
-'use strict';
-
// import required classes
-const path = require('path');
-const ConfigManager = require('../serverLib/ConfigManager');
-const SetupWizard = require('./configLib/SetupWizard');
+import { join } from 'path';
+import ConfigManager from '../serverLib/ConfigManager';
+import SetupWizard from './configLib/SetupWizard';
// import and initialize configManager & dependencies
-const serverConfig = new ConfigManager(path.join(__dirname, '../..'));
+const serverConfig = new ConfigManager(join(__dirname, '../..'));
const setup = new SetupWizard(serverConfig);
setup.start();
diff --git a/server/src/scripts/setupSchema/Banner.js b/server/src/scripts/setupSchema/Banner.js
index 823f0fe..f13fde7 100644
--- a/server/src/scripts/setupSchema/Banner.js
+++ b/server/src/scripts/setupSchema/Banner.js
@@ -5,8 +5,8 @@
*
*/
-const stripIndents = require('common-tags').stripIndents;
-const chalk = require('chalk');
+import { stripIndents } from 'common-tags';
+import chalk from 'chalk';
// gotta have that sexy console
console.log(stripIndents`
@@ -20,9 +20,9 @@ console.log(stripIndents`
${chalk.white('Note:')} ${chalk.green('npm/yarn run config')} will re-run this utility.
You will now be asked for the following:
- - ${chalk.magenta(' Salt')}, the salt for username trip
- - ${chalk.magenta('Admin Name')}, the initial admin username
- - ${chalk.magenta('Admin Pass')}, the initial admin password
- - ${chalk.magenta(' Port')}, the port for the websocket
+ - ${chalk.magenta(' Salt')}, the salt for username trip
+ - ${chalk.magenta('Admin Name')}, the initial admin username
+ - ${chalk.magenta('Admin Pass')}, the initial admin password
+ - ${chalk.magenta(' Port')}, the port for the websocket
\u200b
`);
diff --git a/server/src/scripts/setupSchema/Questions.js b/server/src/scripts/setupSchema/Questions.js
index f84d32f..532ba67 100644
--- a/server/src/scripts/setupSchema/Questions.js
+++ b/server/src/scripts/setupSchema/Questions.js
@@ -15,10 +15,10 @@ const Questions = {
type: 'string',
hidden: true,
replace: '*',
- before: value => {
+ before: (value) => {
salt = value;
return value;
- }
+ },
},
adminName: {
@@ -26,7 +26,7 @@ const Questions = {
pattern: /^"?[a-zA-Z0-9_]+"?$/,
type: 'string',
message: 'Nicks can only contain letters, numbers and underscores',
- before: value => value.replace(/"/g, '')
+ before: (value) => value.replace(/"/g, ''),
},
adminTrip: {
@@ -35,21 +35,21 @@ const Questions = {
replace: '*',
description: 'Admin Password',
message: 'You must enter or re-enter a password',
- before: value => {
+ before: (value) => {
const crypto = require('crypto');
- let sha = crypto.createHash('sha256');
+ const sha = crypto.createHash('sha256');
sha.update(value + salt);
return sha.digest('base64').substr(0, 6);
- }
+ },
},
websocketPort: {
type: 'integer',
message: 'The port may only be a number!',
description: 'Websocket Port',
- default: '6060'
- }
- }
-}
+ default: '6060',
+ },
+ },
+};
module.exports = Questions;