Files
NodeBB/src/cli/setup.js

80 lines
2.2 KiB
JavaScript
Raw Normal View History

'use strict';
const winston = require('winston');
const async = require('async');
const path = require('path');
const nconf = require('nconf');
const { install } = require('../../install/web');
function setup(initConfig) {
const { paths } = require('../constants');
const install = require('../install');
const build = require('../meta/build');
const prestart = require('../prestart');
const pkg = require('../../package.json');
winston.info('NodeBB Setup Triggered via Command Line');
2021-02-03 23:59:08 -07:00
console.log(`\nWelcome to NodeBB v${pkg.version}!`);
console.log('\nThis looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.');
console.log('Press enter to accept the default setting (shown in brackets).');
install.values = initConfig;
async.series([
async function () {
return await install.setup();
},
function (next) {
2021-02-04 00:06:15 -07:00
let configFile = paths.config;
if (nconf.get('config')) {
configFile = path.resolve(paths.baseDir, nconf.get('config'));
}
prestart.loadConfig(configFile);
2020-02-28 21:24:51 -05:00
2020-02-28 22:02:46 -05:00
if (!nconf.get('skip-build')) {
2020-02-28 15:53:16 -05:00
build.buildAll(next);
2020-02-28 21:24:51 -05:00
} else {
setImmediate(next);
2020-02-28 15:53:16 -05:00
}
2020-02-28 21:24:51 -05:00
},
2021-02-04 00:01:39 -07:00
], (err, data) => {
// Disregard build step data
data = data[0];
2021-02-04 00:06:15 -07:00
let separator = ' ';
if (process.stdout.columns > 10) {
2021-02-04 00:06:15 -07:00
for (let x = 0, cols = process.stdout.columns - 10; x < cols; x += 1) {
separator += '=';
}
}
2021-02-03 23:59:08 -07:00
console.log(`\n${separator}\n`);
if (err) {
2021-02-03 23:59:08 -07:00
winston.error(`There was a problem completing NodeBB setup\n${err.stack}`);
throw err;
} else {
if (data.hasOwnProperty('password')) {
console.log('An administrative user was automatically created for you:');
2021-02-03 23:59:08 -07:00
console.log(` Username: ${data.username}`);
console.log(` Password: ${data.password}`);
console.log('');
}
console.log('NodeBB Setup Completed. Run "./nodebb start" to manually start your NodeBB server.');
// If I am a child process, notify the parent of the returned data before exiting (useful for notifying
// hosts of auto-generated username/password during headless setups)
if (process.send) {
process.send(data);
}
}
process.exit();
});
}
exports.setup = setup;
exports.webInstall = install;