From 27c05448e1532ce466658513af0e2ff65576b410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 16 Nov 2021 17:11:26 -0500 Subject: [PATCH] refactor: remove another async.series --- src/cli/setup.js | 91 +++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 55 deletions(-) diff --git a/src/cli/setup.js b/src/cli/setup.js index d4f530f728..ed66cc8bbf 100644 --- a/src/cli/setup.js +++ b/src/cli/setup.js @@ -1,13 +1,12 @@ 'use strict'; const winston = require('winston'); -const async = require('async'); const path = require('path'); const nconf = require('nconf'); -const { install } = require('../../install/web'); +const { webInstall } = require('../../install/web'); -function setup(initConfig) { +async function setup(initConfig) { const { paths } = require('../constants'); const install = require('../install'); const build = require('../meta/build'); @@ -21,59 +20,41 @@ function setup(initConfig) { 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) { - let configFile = paths.config; - if (nconf.get('config')) { - configFile = path.resolve(paths.baseDir, nconf.get('config')); - } - - prestart.loadConfig(configFile); - - if (!nconf.get('skip-build')) { - build.buildAll(next); - } else { - setImmediate(next); - } - }, - ], (err, data) => { - // Disregard build step data - data = data[0]; - - let separator = ' '; - if (process.stdout.columns > 10) { - for (let x = 0, cols = process.stdout.columns - 10; x < cols; x += 1) { - separator += '='; - } + const data = await install.setup(); + let configFile = paths.config; + if (nconf.get('config')) { + configFile = path.resolve(paths.baseDir, nconf.get('config')); + } + + prestart.loadConfig(configFile); + + if (!nconf.get('skip-build')) { + await build.buildAll(); + } + + let separator = ' '; + if (process.stdout.columns > 10) { + for (let x = 0, cols = process.stdout.columns - 10; x < cols; x += 1) { + separator += '='; } - console.log(`\n${separator}\n`); - - if (err) { - 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:'); - 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(); - }); + } + console.log(`\n${separator}\n`); + + if (data.hasOwnProperty('password')) { + console.log('An administrative user was automatically created for you:'); + 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; +exports.webInstall = webInstall;