mirror of
https://github.com/strapi/strapi.git
synced 2025-07-31 04:45:54 +00:00
Merge pull request #2557 from strapi/improve-strapi-new
Improve strapi new
This commit is contained in:
commit
2f8e5bcdb2
@ -10,7 +10,7 @@ Create a new project
|
||||
```bash
|
||||
strapi new <name>
|
||||
|
||||
options: [--dev|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth>]
|
||||
options: [--dev|--debug|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth>]
|
||||
```
|
||||
|
||||
- **strapi new <name>**<br/>
|
||||
@ -19,6 +19,9 @@ options: [--dev|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbna
|
||||
- **strapi new <name> --dev**<br/>
|
||||
Generates a new project called **<name>** and creates symlinks for the `./admin` folder and each plugin inside the `./plugin` folder. It means that the Strapi's development workflow has been set up on the machine earlier.
|
||||
|
||||
- **strapi new <name> --debug**<br/>
|
||||
Will display the full error message if one is fired during the database connection.
|
||||
|
||||
- **strapi new <name> --dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth>**<br/>
|
||||
Generates a new project called **<name>** and skip the interactive database configuration and initilize with these options.
|
||||
- **<dbclient>** can be `mongo`, `postgres`, `mysql`.
|
||||
|
@ -226,6 +226,7 @@ module.exports = (scope, cb) => {
|
||||
}
|
||||
|
||||
let cmd = `${packageCmd} ${scope.client.connector}@${scope.strapiPackageJSON.version}`;
|
||||
let linkNodeModulesCommand = `cd ${scope.tmpPath} && npm link ${scope.client.connector}`;
|
||||
|
||||
if (scope.client.module) {
|
||||
cmd += ` ${scope.client.module}`;
|
||||
@ -233,6 +234,7 @@ module.exports = (scope, cb) => {
|
||||
|
||||
if (scope.client.connector === 'strapi-hook-bookshelf') {
|
||||
cmd += ` strapi-hook-knex@${scope.strapiPackageJSON.version}`;
|
||||
linkNodeModulesCommand += ` && npm link strapi-hook-knex`;
|
||||
|
||||
scope.additionalsDependencies = ['strapi-hook-knex', 'knex'];
|
||||
}
|
||||
@ -248,7 +250,13 @@ module.exports = (scope, cb) => {
|
||||
}
|
||||
}
|
||||
|
||||
resolve();
|
||||
if (scope.developerMode) {
|
||||
exec(linkNodeModulesCommand, () => {
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
})
|
||||
];
|
||||
@ -258,8 +266,8 @@ module.exports = (scope, cb) => {
|
||||
try {
|
||||
require(path.join(`${scope.tmpPath}`, '/node_modules/', `${scope.client.connector}/lib/utils/connectivity.js`))(scope, cb.success, connectionValidation);
|
||||
} catch(err) {
|
||||
shell.rm('-r', scope.tmpPath);
|
||||
console.log(err);
|
||||
shell.rm('-r', scope.tmpPath);
|
||||
cb.error();
|
||||
}
|
||||
});
|
||||
|
@ -1,12 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
// Core
|
||||
const path = require('path');
|
||||
|
||||
// Public node modules
|
||||
const inquirer = require('inquirer');
|
||||
const rimraf = require('rimraf');
|
||||
|
||||
module.exports = (scope, success, error) => {
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
const knex = require('knex')({
|
||||
let knex;
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
knex = require('knex');
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
knex = require(path.resolve(scope.tmpPath, 'node_modules', 'knex'));
|
||||
}
|
||||
|
||||
knex = knex({
|
||||
client: scope.client.module,
|
||||
connection: Object.assign({}, scope.database.settings, {
|
||||
user: scope.database.settings.username
|
||||
@ -48,10 +60,16 @@ module.exports = (scope, success, error) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.sql) {
|
||||
console.log('⚠️ Server connection has failed! Make sure your database server is running.');
|
||||
console.log('⚠️ Server connection has failed! Make sure your database server is running.');
|
||||
} else {
|
||||
console.log(`⚠️ Database connection has failed! Make sure your "${scope.database.settings.database}" database exist.`);
|
||||
console.log(`⚠️ Database connection has failed! Make sure your "${scope.database.settings.database}" database exist.`);
|
||||
}
|
||||
|
||||
if (scope.debug) {
|
||||
console.log('🐛 Full error log:');
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
error();
|
||||
});
|
||||
};
|
||||
|
@ -29,7 +29,13 @@ module.exports = (scope, success, error) => {
|
||||
|
||||
Mongoose.connect(`mongodb${srv ? '+srv' : ''}://${scope.database.settings.host}${!srv ? `:${scope.database.settings.port}` : ''}/`, connectOptions, function (err) {
|
||||
if (err) {
|
||||
console.log('⚠️ Database connection has failed! Make sure your database is running.');
|
||||
console.log('⚠️ Database connection has failed! Make sure your database is running.');
|
||||
|
||||
if (scope.debug) {
|
||||
console.log('🐛 Full error log:');
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
return error();
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,8 @@ module.exports = function (name, cliArguments) {
|
||||
generatorType: 'new',
|
||||
name,
|
||||
strapiPackageJSON: packageJSON,
|
||||
developerMode
|
||||
developerMode,
|
||||
debug: cliArguments.debug !== undefined
|
||||
};
|
||||
|
||||
const dbArguments = ['dbclient', 'dbhost', 'dbport', 'dbname', 'dbusername', 'dbpassword'];
|
||||
|
@ -53,6 +53,7 @@ program
|
||||
program
|
||||
.command('new')
|
||||
.option('-d, --dev', 'Development mode')
|
||||
.option('--debug', 'Display database connection error')
|
||||
.option('--dbclient <dbclient>', 'Database client')
|
||||
.option('--dbhost <dbhost>', 'Database host')
|
||||
.option('--dbport <dbport>', 'Database port')
|
||||
|
Loading…
x
Reference in New Issue
Block a user