From bf7daaf99a8bf02b9d9a8c02cf9734ecc7dd5287 Mon Sep 17 00:00:00 2001 From: Jim Laurie Date: Wed, 10 Jan 2018 14:45:32 +0100 Subject: [PATCH] Reorder promises --- packages/strapi-generate-new/lib/before.js | 132 ++++++++++----------- 1 file changed, 64 insertions(+), 68 deletions(-) diff --git a/packages/strapi-generate-new/lib/before.js b/packages/strapi-generate-new/lib/before.js index db03f12b57..f3daf4d303 100755 --- a/packages/strapi-generate-new/lib/before.js +++ b/packages/strapi-generate-new/lib/before.js @@ -53,78 +53,72 @@ module.exports = (scope, cb) => { scope.database = {}; const connectionValidation = () => { - let formSteps = new Promise(resolve => { - const databaseChoises = [ - { - name: 'MongoDB (highly recommended)', - value: { - database: 'mongo', - connector: 'strapi-mongoose' - } - }, - { - name: 'Postgres', - value: { - database: 'postgres', - connector: 'strapi-bookshelf', - module: 'pg' - } - }, - { - name: 'MySQL', - value: { - database: 'mysql', - connector: 'strapi-bookshelf', - module: 'mysql' - } - }, - { - name: 'Sqlite3', - value: { - database: 'sqlite3', - connector: 'strapi-bookshelf', - module: 'sqlite3' - } - }, - { - name: 'Redis', - value: { - database: 'redis', - connector: 'strapi-redis' + const databaseChoises = [ + { + name: 'MongoDB (highly recommended)', + value: { + database: 'mongo', + connector: 'strapi-mongoose' + } + }, + { + name: 'Postgres', + value: { + database: 'postgres', + connector: 'strapi-bookshelf', + module: 'pg' + } + }, + { + name: 'MySQL', + value: { + database: 'mysql', + connector: 'strapi-bookshelf', + module: 'mysql' + } + }, + { + name: 'Sqlite3', + value: { + database: 'sqlite3', + connector: 'strapi-bookshelf', + module: 'sqlite3' + } + }, + { + name: 'Redis', + value: { + database: 'redis', + connector: 'strapi-redis' + } + } + ]; + + inquirer + .prompt([ + { + type: 'list', + prefix: '', + name: 'client', + message: 'Choose your database:', + choices: databaseChoises, + default: () => { + if (scope.client) { + return _.findIndex(databaseChoises, { value: _.omit(scope.client, ['version'])}); } } - ]; - - inquirer - .prompt([ - { - type: 'list', - prefix: '', - name: 'client', - message: 'Choose your database:', - choices: databaseChoises, - default: () => { - if (scope.client) { - return _.findIndex(databaseChoises, { value: _.omit(scope.client, ['version'])}); - } - } - } - ]) - .then(answers => { - scope.client = answers.client; - _.assign(scope.database, { - connector: answers.client.connector, - settings: { - client: answers.client.database - }, - options: {} - }); - - resolve(); + } + ]) + .then(answers => { + scope.client = answers.client; + _.assign(scope.database, { + connector: answers.client.connector, + settings: { + client: answers.client.database + }, + options: {} }); - }); - formSteps = formSteps.then(() => { const asyncFn = [ new Promise(resolve => { inquirer @@ -186,6 +180,8 @@ module.exports = (scope, cb) => { scope.database.username = answers.username; scope.database.password = answers.password; + logger.info('Testing database connection...'); + resolve(); }); }),