Merge pull request #2732 from strapi/quickstart

Add quickstart mode
This commit is contained in:
Jim LAURIE 2019-02-01 17:26:16 +01:00 committed by GitHub
commit 5ed07cb27a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 232 additions and 192 deletions

View File

@ -10,7 +10,7 @@ Create a new project
```bash ```bash
strapi new <name> 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 &#60;name&#62;**<br/> - **strapi new &#60;name&#62;**<br/>
@ -22,6 +22,9 @@ options: [--dev|--debug|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport
- **strapi new &#60;name&#62; --debug**<br/> - **strapi new &#60;name&#62; --debug**<br/>
Will display the full error message if one is fired during the database connection. Will display the full error message if one is fired during the database connection.
- **strapi new &#60;name&#62; --quickstart**<br/>
Use the quickstart system to create your app.
- **strapi new &#60;name&#62; --dbclient=&#60;dbclient&#62; --dbhost=&#60;dbhost&#62; --dbport=&#60;dbport&#62; --dbname=&#60;dbname&#62; --dbusername=&#60;dbusername&#62; --dbpassword=&#60;dbpassword&#62; --dbssl=&#60;dbssl&#62; --dbauth=&#60;dbauth&#62; --dbforce**<br/> - **strapi new &#60;name&#62; --dbclient=&#60;dbclient&#62; --dbhost=&#60;dbhost&#62; --dbport=&#60;dbport&#62; --dbname=&#60;dbname&#62; --dbusername=&#60;dbusername&#62; --dbpassword=&#60;dbpassword&#62; --dbssl=&#60;dbssl&#62; --dbauth=&#60;dbauth&#62; --dbforce**<br/>
Generates a new project called **&#60;name&#62;** and skip the interactive database configuration and initilize with these options. Generates a new project called **&#60;name&#62;** and skip the interactive database configuration and initilize with these options.

View File

@ -62,13 +62,11 @@ module.exports = (scope, cb) => {
// ... // ...
} }
console.log('Let\s configurate the connection to your database:');
if (hasDatabaseConfig) { if (hasDatabaseConfig) {
console.log(`Database determined by CLI args: ${scope.database.settings.client}`); console.log(`Database determined by CLI args: ${scope.database.settings.client}`);
} }
const connectionValidation = () => { const connectionValidation = async () => {
const databaseChoices = [ const databaseChoices = [
{ {
name: 'SQLite', name: 'SQLite',
@ -103,10 +101,25 @@ module.exports = (scope, cb) => {
} }
]; ];
inquirer const answers = await inquirer
.prompt([ .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', type: 'list',
name: 'client', name: 'client',
message: 'Choose your main database:', 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) { if (hasDatabaseConfig) {
const databaseChoice = _.find(databaseChoices, ['value.database', scope.database.settings.client]); const databaseChoice = _.find(databaseChoices, ['value.database', scope.database.settings.client]);
scope.database.connector = databaseChoice.value.connector; scope.database.connector = databaseChoice.value.connector;
@ -134,14 +154,15 @@ module.exports = (scope, cb) => {
options: {} options: {}
}); });
} }
scope.client = answers.client; scope.client = answers.client;
const asyncFn = [ const asyncFn = [
new Promise(resolve => { new Promise(async resolve => {
const isMongo = scope.client.database === 'mongo'; const isMongo = scope.client.database === 'mongo';
const isSQLite = scope.database.settings.client === 'sqlite'; const isSQLite = scope.database.settings.client === 'sqlite';
inquirer let answers = await inquirer
.prompt([ .prompt([
{ {
when: !hasDatabaseConfig && !isSQLite, when: !hasDatabaseConfig && !isSQLite,
@ -213,14 +234,18 @@ module.exports = (scope, cb) => {
default: _.get(scope.database, 'ssl', false) default: _.get(scope.database, 'ssl', false)
}, },
{ {
when: !hasDatabaseConfig && isSQLite, when: !hasDatabaseConfig && isSQLite && !isQuick,
type: 'input', type: 'input',
name: 'filename', name: 'filename',
message: 'Filename:', message: 'Filename:',
default: () => '.tmp/data.db' default: () => '.tmp/data.db'
} }
]) ]);
.then(answers => {
if (isQuick) {
answers.filename = '.tmp/data.db';
}
if (hasDatabaseConfig) { if (hasDatabaseConfig) {
answers = _.merge((_.omit(scope.database.settings, ['client'])), scope.database.options); 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.database = answers.database;
scope.database.settings.username = answers.username; scope.database.settings.username = answers.username;
scope.database.settings.password = answers.password; scope.database.settings.password = answers.password;
if (answers.filename) { if (answers.filename) {
scope.database.settings.filename = answers.filename; scope.database.settings.filename = answers.filename;
} }
@ -258,7 +284,6 @@ module.exports = (scope, cb) => {
console.log('⏳ Testing database connection...'); console.log('⏳ Testing database connection...');
resolve(); resolve();
});
}), }),
new Promise(resolve => { new Promise(resolve => {
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM(); const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM();
@ -314,7 +339,6 @@ module.exports = (scope, cb) => {
cb.error(); cb.error();
} }
}); });
});
}; };
connectionValidation(); connectionValidation();

View File

@ -11,6 +11,7 @@ const path = require('path');
// Public node modules. // Public node modules.
const _ = require('lodash'); const _ = require('lodash');
const shell = require('shelljs');
// Master of ceremonies for generators. // Master of ceremonies for generators.
const generate = require('strapi-generate'); const generate = require('strapi-generate');
@ -43,7 +44,8 @@ module.exports = function (name, cliArguments) {
name, name,
strapiPackageJSON: packageJSON, strapiPackageJSON: packageJSON,
developerMode, developerMode,
debug: cliArguments.debug !== undefined debug: cliArguments.debug !== undefined,
quick: cliArguments.quickstart !== undefined
}; };
const dbArguments = ['dbclient', 'dbhost', 'dbport', 'dbname', 'dbusername', 'dbpassword']; const dbArguments = ['dbclient', 'dbhost', 'dbport', 'dbname', 'dbusername', 'dbpassword'];
@ -83,6 +85,15 @@ module.exports = function (name, cliArguments) {
error: function returnError(err) { error: function returnError(err) {
console.log(err); console.log(err);
process.exit(1); process.exit(1);
},
success: () => {
if (scope.quick) {
shell.cd(scope.rootPath);
shell.exec('strapi start', {
stdio: 'inherit'
});
}
} }
}); });
}; };

View File

@ -54,6 +54,7 @@ program
.command('new') .command('new')
.option('-d, --dev', 'Development mode') .option('-d, --dev', 'Development mode')
.option('--debug', 'Display database connection error') .option('--debug', 'Display database connection error')
.option('--quickstart', 'Quickstart app creation')
.option('--dbclient <dbclient>', 'Database client') .option('--dbclient <dbclient>', 'Database client')
.option('--dbhost <dbhost>', 'Database host') .option('--dbhost <dbhost>', 'Database host')
.option('--dbsrv <dbsrv>', 'Database srv') .option('--dbsrv <dbsrv>', 'Database srv')

View File

@ -59,6 +59,7 @@
"ora": "^3.0.0", "ora": "^3.0.0",
"rimraf": "^2.6.2", "rimraf": "^2.6.2",
"semver": "^5.4.1", "semver": "^5.4.1",
"shelljs": "^0.8.3",
"stack-trace": "0.0.10", "stack-trace": "0.0.10",
"strapi-generate": "3.0.0-alpha.21", "strapi-generate": "3.0.0-alpha.21",
"strapi-generate-admin": "3.0.0-alpha.21", "strapi-generate-admin": "3.0.0-alpha.21",