mirror of
https://github.com/strapi/strapi.git
synced 2025-08-21 23:28:58 +00:00
Install db dependencies on app creation
This commit is contained in:
parent
a892a6943d
commit
23ee0b25bf
@ -40,7 +40,8 @@ module.exports = scope => {
|
|||||||
'dependencies': {
|
'dependencies': {
|
||||||
'lodash': '4.x.x',
|
'lodash': '4.x.x',
|
||||||
'strapi': getDependencyVersion(cliPkg, 'strapi'),
|
'strapi': getDependencyVersion(cliPkg, 'strapi'),
|
||||||
'strapi-mongoose': getDependencyVersion(cliPkg, 'strapi')
|
[scope.client.connector]: getDependencyVersion(cliPkg, 'strapi'),
|
||||||
|
[scope.client.module]: scope.client.version
|
||||||
},
|
},
|
||||||
'author': {
|
'author': {
|
||||||
'name': scope.author || 'A Strapi developer',
|
'name': scope.author || 'A Strapi developer',
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
// Node.js core.
|
// Node.js core.
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const exec = require('child_process').exec;
|
||||||
|
const execSync = require('child_process').execSync;
|
||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
@ -47,112 +49,154 @@ module.exports = (scope, cb) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.info('Let\s configurate the connection to your database:');
|
logger.info('Let\s configurate the connection to your database:');
|
||||||
inquirer
|
let formSteps = new Promise(resolve => {
|
||||||
.prompt([
|
inquirer
|
||||||
{
|
.prompt([
|
||||||
type: 'list',
|
{
|
||||||
prefix: '',
|
type: 'list',
|
||||||
name: 'client',
|
prefix: '',
|
||||||
message: 'Choose your database:',
|
name: 'client',
|
||||||
choices: [
|
message: 'Choose your database:',
|
||||||
{
|
choices: [
|
||||||
name: 'MongoDB (highly recommended)',
|
{
|
||||||
value: {
|
name: 'MongoDB (highly recommended)',
|
||||||
database: 'mongo',
|
value: {
|
||||||
connector: 'strapi-mongoose'
|
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'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
]
|
||||||
{
|
|
||||||
name: 'Postgres',
|
|
||||||
value: {
|
|
||||||
database: 'postgres',
|
|
||||||
connector: 'strapi-bookshelf'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'MySQL',
|
|
||||||
value: {
|
|
||||||
database: 'mysql',
|
|
||||||
connector: 'strapi-bookshelf'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Sqlite3',
|
|
||||||
value: {
|
|
||||||
database: 'sqlite3',
|
|
||||||
connector: 'strapi-bookshelf'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Redis',
|
|
||||||
value: {
|
|
||||||
database: 'redis',
|
|
||||||
connector: 'strapi-bookshelf'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'input',
|
|
||||||
prefix: '',
|
|
||||||
name: 'name',
|
|
||||||
message: 'Database name:',
|
|
||||||
default: 'strapi'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'input',
|
|
||||||
prefix: '',
|
|
||||||
name: 'host',
|
|
||||||
message: 'Host:',
|
|
||||||
default: 'localhost'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'input',
|
|
||||||
prefix: '',
|
|
||||||
name: 'port',
|
|
||||||
message: 'Port:',
|
|
||||||
default: (answers) => {
|
|
||||||
const ports = {
|
|
||||||
mongo: 27017,
|
|
||||||
postgres: 5432,
|
|
||||||
mysql: 3306,
|
|
||||||
sqlite3: 1433,
|
|
||||||
redis: 6379
|
|
||||||
};
|
|
||||||
|
|
||||||
return ports[answers.client.database];
|
|
||||||
}
|
}
|
||||||
},
|
])
|
||||||
{
|
.then(answers => {
|
||||||
type: 'input',
|
scope.client = answers.client;
|
||||||
prefix: '',
|
scope.database = {
|
||||||
name: 'username',
|
connector: answers.client.connector,
|
||||||
message: 'Username:'
|
settings: {
|
||||||
},
|
client: answers.client.database
|
||||||
{
|
},
|
||||||
type: 'input',
|
options: {}
|
||||||
prefix: '',
|
};
|
||||||
name: 'password',
|
|
||||||
message: 'Password:'
|
|
||||||
}
|
|
||||||
])
|
|
||||||
.then(answers => {
|
|
||||||
scope.database = {
|
|
||||||
connector: answers.client.connector,
|
|
||||||
settings: {
|
|
||||||
client: answers.client.database,
|
|
||||||
host: answers.host,
|
|
||||||
port: answers.port,
|
|
||||||
database: answers.name,
|
|
||||||
username: answers.username,
|
|
||||||
password: answers.password
|
|
||||||
},
|
|
||||||
options: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
logger.info('Copying the dashboard...');
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Trigger callback with no error to proceed.
|
formSteps = formSteps.then(() => {
|
||||||
return cb.success();
|
const asyncFn = [
|
||||||
|
new Promise(resolve => {
|
||||||
|
inquirer
|
||||||
|
.prompt([
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
prefix: '',
|
||||||
|
name: 'name',
|
||||||
|
message: 'Database name:',
|
||||||
|
default: 'strapi'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
prefix: '',
|
||||||
|
name: 'host',
|
||||||
|
message: 'Host:',
|
||||||
|
default: 'localhost'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
prefix: '',
|
||||||
|
name: 'port',
|
||||||
|
message: 'Port:',
|
||||||
|
default: (answers) => {
|
||||||
|
const ports = {
|
||||||
|
mongo: 27017,
|
||||||
|
postgres: 5432,
|
||||||
|
mysql: 3306,
|
||||||
|
sqlite3: 1433,
|
||||||
|
redis: 6379
|
||||||
|
};
|
||||||
|
|
||||||
|
return ports[scope.client.database];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
prefix: '',
|
||||||
|
name: 'username',
|
||||||
|
message: 'Username:'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
prefix: '',
|
||||||
|
name: 'password',
|
||||||
|
message: 'Password:'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
.then(answers => {
|
||||||
|
scope.database.host = answers.host;
|
||||||
|
scope.database.port = answers.port;
|
||||||
|
scope.database.database = answers.name;
|
||||||
|
scope.database.username = answers.username;
|
||||||
|
scope.database.password = answers.password;
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
new Promise(resolve => {
|
||||||
|
let cmd = `npm install --prefix ${scope.rootPath}_ ${scope.client.connector}@alpha`;
|
||||||
|
if (scope.client.module) {
|
||||||
|
cmd += ` ${scope.client.module}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
exec(cmd, () => {
|
||||||
|
if (scope.client.module) {
|
||||||
|
const lock = require(`${scope.rootPath}_/package-lock.json`);
|
||||||
|
scope.client.version = lock.dependencies[scope.client.module].version;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
Promise.all(asyncFn)
|
||||||
|
.then(() => {
|
||||||
|
execSync(`rm -r ${scope.rootPath}_`);
|
||||||
|
|
||||||
|
logger.info('Copying the dashboard...');
|
||||||
|
|
||||||
|
// Trigger callback with no error to proceed.
|
||||||
|
cb.success();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user