Reorder promises

This commit is contained in:
Jim Laurie 2018-01-10 14:45:32 +01:00
parent fbd17f4205
commit bf7daaf99a

View File

@ -53,78 +53,72 @@ module.exports = (scope, cb) => {
scope.database = {}; scope.database = {};
const connectionValidation = () => { const connectionValidation = () => {
let formSteps = new Promise(resolve => { const databaseChoises = [
const databaseChoises = [ {
{ name: 'MongoDB (highly recommended)',
name: 'MongoDB (highly recommended)', value: {
value: { database: 'mongo',
database: 'mongo', connector: 'strapi-mongoose'
connector: 'strapi-mongoose' }
} },
}, {
{ name: 'Postgres',
name: 'Postgres', value: {
value: { database: 'postgres',
database: 'postgres', connector: 'strapi-bookshelf',
connector: 'strapi-bookshelf', module: 'pg'
module: 'pg' }
} },
}, {
{ name: 'MySQL',
name: 'MySQL', value: {
value: { database: 'mysql',
database: 'mysql', connector: 'strapi-bookshelf',
connector: 'strapi-bookshelf', module: 'mysql'
module: 'mysql' }
} },
}, {
{ name: 'Sqlite3',
name: 'Sqlite3', value: {
value: { database: 'sqlite3',
database: 'sqlite3', connector: 'strapi-bookshelf',
connector: 'strapi-bookshelf', module: 'sqlite3'
module: 'sqlite3' }
} },
}, {
{ name: 'Redis',
name: 'Redis', value: {
value: { database: 'redis',
database: 'redis', connector: 'strapi-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 .then(answers => {
.prompt([ scope.client = answers.client;
{ _.assign(scope.database, {
type: 'list', connector: answers.client.connector,
prefix: '', settings: {
name: 'client', client: answers.client.database
message: 'Choose your database:', },
choices: databaseChoises, options: {}
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();
}); });
});
formSteps = formSteps.then(() => {
const asyncFn = [ const asyncFn = [
new Promise(resolve => { new Promise(resolve => {
inquirer inquirer
@ -186,6 +180,8 @@ module.exports = (scope, cb) => {
scope.database.username = answers.username; scope.database.username = answers.username;
scope.database.password = answers.password; scope.database.password = answers.password;
logger.info('Testing database connection...');
resolve(); resolve();
}); });
}), }),