install.js minor refactor - moved questions into their own modules; don't need to export installation questions

v1.18.x
psychobunny 11 years ago
parent f3fe79ab60
commit be83157de2

@ -9,82 +9,51 @@ var async = require('async'),
nconf = require('nconf'),
utils = require('../public/src/utils.js'),
ALLOWED_DATABASES = ['redis', 'mongo', 'level'],
ALLOWED_DATABASES = ['redis', 'mongo', 'level'];
install = {
questions: [{
var install = {},
questions = {};
questions.main = [{
name: 'base_url',
description: 'URL of this installation',
'default': nconf.get('base_url') || 'http://localhost',
pattern: /^http(?:s)?:\/\//,
message: 'Base URL must begin with \'http://\' or \'https://\'',
}, {
}, {
name: 'port',
description: 'Port number of your NodeBB',
'default': nconf.get('port') || 4567,
pattern: /[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]/,
message: 'Please enter a value betweeen 1 and 65535'
}, {
}, {
name: 'use_port',
description: 'Use a port number to access NodeBB?',
'default': (nconf.get('use_port') !== undefined ? (nconf.get('use_port') ? 'y' : 'n') : 'y'),
pattern: /y[es]*|n[o]?/,
message: 'Please enter \'yes\' or \'no\''
}, {
}, {
name: 'secret',
description: 'Please enter a NodeBB secret',
'default': nconf.get('secret') || utils.generateUUID()
}, {
}, {
name: 'bind_address',
description: 'IP or Hostname to bind to',
'default': nconf.get('bind_address') || '0.0.0.0'
}, {
}, {
name: 'database',
description: 'Which database to use',
'default': nconf.get('database') || 'redis'
}],
redisQuestions : [{
name: 'redis:host',
description: 'Host IP or address of your Redis instance',
'default': nconf.get('redis:host') || '127.0.0.1'
}, {
name: 'redis:port',
description: 'Host port of your Redis instance',
'default': nconf.get('redis:port') || 6379
}, {
name: 'redis:password',
description: 'Password of your Redis database'
}, {
name: "redis:database",
description: "Which database to use (0..n)",
'default': nconf.get('redis:database') || 0
}],
mongoQuestions : [{
name: 'mongo:host',
description: 'Host IP or address of your MongoDB instance',
'default': nconf.get('mongo:host') || '127.0.0.1'
}, {
name: 'mongo:port',
description: 'Host port of your MongoDB instance',
'default': nconf.get('mongo:port') || 27017
}, {
name: 'mongo:username',
description: 'MongoDB username'
}, {
name: 'mongo:password',
description: 'Password of your MongoDB database'
}, {
name: "mongo:database",
description: "Which database to use",
'default': nconf.get('mongo:database') || 0
}],
levelQuestions : [{
name: "level:database",
description: "Enter the path to your Level database",
'default': nconf.get('level:database') || '/var/level/nodebb'
}],
}];
setup: function (callback) {
ALLOWED_DATABASES.forEach(function(db) {
questions[db] = require('./database/' + db).questions;
});
install.setup = function (callback) {
async.series([
function (next) {
// Check if the `--setup` flag contained values we can work with
@ -192,7 +161,7 @@ var async = require('async'),
return next(new Error('unknown database : ' + database));
}
var allQuestions = install.redisQuestions.concat(install.mongoQuestions.concat(install.levelQuestions));
var allQuestions = questions.redis.concat(questions.mongo.concat(questions.level));
for(var x=0;x<allQuestions.length;x++) {
delete config[allQuestions[x].name];
}
@ -214,19 +183,19 @@ var async = require('async'),
if (config['redis:host'] && config['redis:port']) {
dbQuestionsSuccess(null, config);
} else {
prompt.get(install.redisQuestions, dbQuestionsSuccess);
prompt.get(questions.redis, dbQuestionsSuccess);
}
} else if(database === 'mongo') {
if (config['mongo:host'] && config['mongo:port']) {
dbQuestionsSuccess(null, config);
} else {
prompt.get(install.mongoQuestions, dbQuestionsSuccess);
prompt.get(questions.mongo, dbQuestionsSuccess);
}
} else if(database === 'level') {
if (config['level:database']) {
dbQuestionsSuccess(null, config);
} else {
prompt.get(install.levelQuestions, dbQuestionsSuccess);
prompt.get(questions.level, dbQuestionsSuccess);
}
} else {
return next(new Error('unknown database : ' + database));
@ -239,7 +208,7 @@ var async = require('async'),
prompt.delimiter = '';
if (!install.values) {
prompt.get(install.questions, function(err, config) {
prompt.get(questions.main, function(err, config) {
if (nconf.get('advanced')) {
prompt.get({
name: 'secondary_database',
@ -256,7 +225,7 @@ var async = require('async'),
} else {
// Use provided values, fall back to defaults
var config = {},
question, x, numQ, allQuestions = install.questions.concat(install.redisQuestions).concat(install.mongoQuestions.concat(install.levelQuestions));
question, x, numQ, allQuestions = questions.main.concat(questions.redis).concat(questions.mongo.concat(questions.level));
for(x=0,numQ=allQuestions.length;x<numQ;x++) {
question = allQuestions[x];
config[question.name] = install.values[question.name] || question['default'] || '';
@ -434,12 +403,14 @@ var async = require('async'),
callback();
}
});
},
createAdmin: function (callback) {
};
install.createAdmin = function(callback) {
var User = require('./user'),
Groups = require('./groups');
winston.warn('No administrators have been detected, running initial user setup');
var questions = [{
name: 'username',
description: 'Administrator username',
@ -515,9 +486,11 @@ var async = require('async'),
success(null, results);
}
},
save: function (server_conf, callback) {
};
install.save = function (server_conf, callback) {
var serverConfigPath = path.join(__dirname, '../config.json');
if (nconf.get('config')) {
serverConfigPath = path.resolve(__dirname, '../', nconf.get('config'));
}
@ -536,7 +509,6 @@ var async = require('async'),
callback();
});
}
};
};
module.exports = install;
Loading…
Cancel
Save