mirror of
https://github.com/strapi/strapi.git
synced 2025-08-19 14:19:03 +00:00
commit
5ed07cb27a
@ -10,7 +10,7 @@ Create a new project
|
||||
```bash
|
||||
strapi new <name>
|
||||
|
||||
options: [--dev|--debug|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth> --dbforce]
|
||||
options: [--dev|--debug|--quickstart|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth> --dbforce]
|
||||
```
|
||||
|
||||
- **strapi new <name>**<br/>
|
||||
@ -22,6 +22,9 @@ options: [--dev|--debug|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport
|
||||
- **strapi new <name> --debug**<br/>
|
||||
Will display the full error message if one is fired during the database connection.
|
||||
|
||||
- **strapi new <name> --quickstart**<br/>
|
||||
Use the quickstart system to create your app.
|
||||
|
||||
- **strapi new <name> --dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth> --dbforce**<br/>
|
||||
|
||||
Generates a new project called **<name>** and skip the interactive database configuration and initilize with these options.
|
||||
|
@ -62,13 +62,11 @@ module.exports = (scope, cb) => {
|
||||
// ...
|
||||
}
|
||||
|
||||
console.log('Let\s configurate the connection to your database:');
|
||||
|
||||
if (hasDatabaseConfig) {
|
||||
console.log(`Database determined by CLI args: ${scope.database.settings.client}`);
|
||||
}
|
||||
|
||||
const connectionValidation = () => {
|
||||
const connectionValidation = async () => {
|
||||
const databaseChoices = [
|
||||
{
|
||||
name: 'SQLite',
|
||||
@ -103,10 +101,25 @@ module.exports = (scope, cb) => {
|
||||
}
|
||||
];
|
||||
|
||||
inquirer
|
||||
const answers = await inquirer
|
||||
.prompt([
|
||||
{
|
||||
when: !hasDatabaseConfig,
|
||||
when: !scope.quick,
|
||||
type: 'list',
|
||||
name: 'type',
|
||||
message: 'Choose your installation type',
|
||||
choices: [{
|
||||
name: 'Quickstart (recommended)',
|
||||
value: 'quick'
|
||||
}, {
|
||||
name: 'Custom (manual settings)',
|
||||
value: 'custom'
|
||||
}]
|
||||
},
|
||||
{
|
||||
when: (answers) => {
|
||||
return !hasDatabaseConfig && answers.type === 'custom';
|
||||
},
|
||||
type: 'list',
|
||||
name: 'client',
|
||||
message: 'Choose your main database:',
|
||||
@ -117,8 +130,15 @@ module.exports = (scope, cb) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
])
|
||||
.then(answers => {
|
||||
]);
|
||||
|
||||
scope.quick = answers.type === 'quick' || scope.quick;
|
||||
const isQuick = scope.quick;
|
||||
|
||||
if (isQuick) {
|
||||
answers.client = databaseChoices[0].value;
|
||||
}
|
||||
|
||||
if (hasDatabaseConfig) {
|
||||
const databaseChoice = _.find(databaseChoices, ['value.database', scope.database.settings.client]);
|
||||
scope.database.connector = databaseChoice.value.connector;
|
||||
@ -134,14 +154,15 @@ module.exports = (scope, cb) => {
|
||||
options: {}
|
||||
});
|
||||
}
|
||||
|
||||
scope.client = answers.client;
|
||||
|
||||
const asyncFn = [
|
||||
new Promise(resolve => {
|
||||
new Promise(async resolve => {
|
||||
const isMongo = scope.client.database === 'mongo';
|
||||
const isSQLite = scope.database.settings.client === 'sqlite';
|
||||
|
||||
inquirer
|
||||
let answers = await inquirer
|
||||
.prompt([
|
||||
{
|
||||
when: !hasDatabaseConfig && !isSQLite,
|
||||
@ -213,14 +234,18 @@ module.exports = (scope, cb) => {
|
||||
default: _.get(scope.database, 'ssl', false)
|
||||
},
|
||||
{
|
||||
when: !hasDatabaseConfig && isSQLite,
|
||||
when: !hasDatabaseConfig && isSQLite && !isQuick,
|
||||
type: 'input',
|
||||
name: 'filename',
|
||||
message: 'Filename:',
|
||||
default: () => '.tmp/data.db'
|
||||
}
|
||||
])
|
||||
.then(answers => {
|
||||
]);
|
||||
|
||||
if (isQuick) {
|
||||
answers.filename = '.tmp/data.db';
|
||||
}
|
||||
|
||||
if (hasDatabaseConfig) {
|
||||
answers = _.merge((_.omit(scope.database.settings, ['client'])), scope.database.options);
|
||||
}
|
||||
@ -230,6 +255,7 @@ module.exports = (scope, cb) => {
|
||||
scope.database.settings.database = answers.database;
|
||||
scope.database.settings.username = answers.username;
|
||||
scope.database.settings.password = answers.password;
|
||||
|
||||
if (answers.filename) {
|
||||
scope.database.settings.filename = answers.filename;
|
||||
}
|
||||
@ -258,7 +284,6 @@ module.exports = (scope, cb) => {
|
||||
console.log('⏳ Testing database connection...');
|
||||
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
new Promise(resolve => {
|
||||
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM();
|
||||
@ -314,7 +339,6 @@ module.exports = (scope, cb) => {
|
||||
cb.error();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
connectionValidation();
|
||||
|
@ -11,6 +11,7 @@ const path = require('path');
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
const shell = require('shelljs');
|
||||
|
||||
// Master of ceremonies for generators.
|
||||
const generate = require('strapi-generate');
|
||||
@ -43,7 +44,8 @@ module.exports = function (name, cliArguments) {
|
||||
name,
|
||||
strapiPackageJSON: packageJSON,
|
||||
developerMode,
|
||||
debug: cliArguments.debug !== undefined
|
||||
debug: cliArguments.debug !== undefined,
|
||||
quick: cliArguments.quickstart !== undefined
|
||||
};
|
||||
|
||||
const dbArguments = ['dbclient', 'dbhost', 'dbport', 'dbname', 'dbusername', 'dbpassword'];
|
||||
@ -83,6 +85,15 @@ module.exports = function (name, cliArguments) {
|
||||
error: function returnError(err) {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
},
|
||||
|
||||
success: () => {
|
||||
if (scope.quick) {
|
||||
shell.cd(scope.rootPath);
|
||||
shell.exec('strapi start', {
|
||||
stdio: 'inherit'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -54,6 +54,7 @@ program
|
||||
.command('new')
|
||||
.option('-d, --dev', 'Development mode')
|
||||
.option('--debug', 'Display database connection error')
|
||||
.option('--quickstart', 'Quickstart app creation')
|
||||
.option('--dbclient <dbclient>', 'Database client')
|
||||
.option('--dbhost <dbhost>', 'Database host')
|
||||
.option('--dbsrv <dbsrv>', 'Database srv')
|
||||
|
@ -59,6 +59,7 @@
|
||||
"ora": "^3.0.0",
|
||||
"rimraf": "^2.6.2",
|
||||
"semver": "^5.4.1",
|
||||
"shelljs": "^0.8.3",
|
||||
"stack-trace": "0.0.10",
|
||||
"strapi-generate": "3.0.0-alpha.21",
|
||||
"strapi-generate-admin": "3.0.0-alpha.21",
|
||||
|
Loading…
x
Reference in New Issue
Block a user