Files
talk/bin/cli-setup
T
2017-01-30 17:46:09 -07:00

83 lines
2.2 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Module dependencies.
*/
const program = require('./commander');
const inquirer = require('inquirer');
const mongoose = require('../services/mongoose');
const SettingModel = require('../models/setting');
const SettingsService = require('../services/settings');
const util = require('../util');
// Register the shutdown criteria.
util.onshutdown([
() => mongoose.disconnect()
]);
//==============================================================================
// Setting up the program command line arguments.
//==============================================================================
program
.description('runs the setup wizard to setup the application')
.parse(process.argv);
//==============================================================================
// Setup the application
//==============================================================================
console.log('We\'ll ask you some questions in order to setup your installation of Talk.\n');
SettingsService
.retrieve()
.catch(() => new SettingModel())
.then((settings) => {
if (settings && settings.id) {
console.log('We found preexisting settings in the database, we\'ll use it\'s values as defaults.\n');
}
return inquirer.prompt([
{
type: 'input',
name: 'organizationName',
message: 'Organization Name',
default: settings.organizationName
},
{
type: 'list',
choices: SettingModel.MODERATION_OPTIONS,
name: 'moderation',
default: settings.moderation,
message: 'Select a moderation mode'
},
{
type: 'confirm',
name: 'requireEmailConfirmation',
default: settings.requireEmailConfirmation,
message: 'Should emails always be confirmed'
}
])
.then((answers) => {
// Update the settings that were changed.
Object.keys(answers).forEach((key) => {
if (answers[key] !== undefined) {
settings[key] = answers[key];
}
});
return SettingsService.update(settings);
});
})
.then(() => {
console.log('\nTalk is now installed!');
util.shutdown();
})
.catch((err) => {
console.error(err);
util.shutdown(1);
});