mirror of
https://github.com/strapi/strapi.git
synced 2025-08-01 21:36:25 +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
|
```bash
|
||||||
strapi new <name>
|
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/>
|
- **strapi new <name>**<br/>
|
||||||
@ -19,6 +19,9 @@ options: [--dev|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbna
|
|||||||
- **strapi new <name> --dev**<br/>
|
- **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.
|
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/>
|
- **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.
|
Generates a new project called **<name>** and skip the interactive database configuration and initilize with these options.
|
||||||
- **<dbclient>** can be `mongo`, `postgres`, `mysql`.
|
- **<dbclient>** can be `mongo`, `postgres`, `mysql`.
|
||||||
|
@ -226,6 +226,7 @@ module.exports = (scope, cb) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let cmd = `${packageCmd} ${scope.client.connector}@${scope.strapiPackageJSON.version}`;
|
let cmd = `${packageCmd} ${scope.client.connector}@${scope.strapiPackageJSON.version}`;
|
||||||
|
let linkNodeModulesCommand = `cd ${scope.tmpPath} && npm link ${scope.client.connector}`;
|
||||||
|
|
||||||
if (scope.client.module) {
|
if (scope.client.module) {
|
||||||
cmd += ` ${scope.client.module}`;
|
cmd += ` ${scope.client.module}`;
|
||||||
@ -233,6 +234,7 @@ module.exports = (scope, cb) => {
|
|||||||
|
|
||||||
if (scope.client.connector === 'strapi-hook-bookshelf') {
|
if (scope.client.connector === 'strapi-hook-bookshelf') {
|
||||||
cmd += ` strapi-hook-knex@${scope.strapiPackageJSON.version}`;
|
cmd += ` strapi-hook-knex@${scope.strapiPackageJSON.version}`;
|
||||||
|
linkNodeModulesCommand += ` && npm link strapi-hook-knex`;
|
||||||
|
|
||||||
scope.additionalsDependencies = ['strapi-hook-knex', 'knex'];
|
scope.additionalsDependencies = ['strapi-hook-knex', 'knex'];
|
||||||
}
|
}
|
||||||
@ -248,8 +250,14 @@ module.exports = (scope, cb) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scope.developerMode) {
|
||||||
|
exec(linkNodeModulesCommand, () => {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -258,8 +266,8 @@ module.exports = (scope, cb) => {
|
|||||||
try {
|
try {
|
||||||
require(path.join(`${scope.tmpPath}`, '/node_modules/', `${scope.client.connector}/lib/utils/connectivity.js`))(scope, cb.success, connectionValidation);
|
require(path.join(`${scope.tmpPath}`, '/node_modules/', `${scope.client.connector}/lib/utils/connectivity.js`))(scope, cb.success, connectionValidation);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
shell.rm('-r', scope.tmpPath);
|
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
shell.rm('-r', scope.tmpPath);
|
||||||
cb.error();
|
cb.error();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,24 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// Core
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
// Public node modules
|
// Public node modules
|
||||||
const inquirer = require('inquirer');
|
const inquirer = require('inquirer');
|
||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
|
|
||||||
module.exports = (scope, success, error) => {
|
module.exports = (scope, success, error) => {
|
||||||
|
let knex;
|
||||||
|
|
||||||
|
try {
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
const knex = require('knex')({
|
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,
|
client: scope.client.module,
|
||||||
connection: Object.assign({}, scope.database.settings, {
|
connection: Object.assign({}, scope.database.settings, {
|
||||||
user: scope.database.settings.username
|
user: scope.database.settings.username
|
||||||
@ -52,6 +64,12 @@ module.exports = (scope, success, error) => {
|
|||||||
} else {
|
} 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();
|
error();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -30,6 +30,12 @@ module.exports = (scope, success, error) => {
|
|||||||
Mongoose.connect(`mongodb${srv ? '+srv' : ''}://${scope.database.settings.host}${!srv ? `:${scope.database.settings.port}` : ''}/`, connectOptions, function (err) {
|
Mongoose.connect(`mongodb${srv ? '+srv' : ''}://${scope.database.settings.host}${!srv ? `:${scope.database.settings.port}` : ''}/`, connectOptions, function (err) {
|
||||||
if (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();
|
return error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,8 @@ module.exports = function (name, cliArguments) {
|
|||||||
generatorType: 'new',
|
generatorType: 'new',
|
||||||
name,
|
name,
|
||||||
strapiPackageJSON: packageJSON,
|
strapiPackageJSON: packageJSON,
|
||||||
developerMode
|
developerMode,
|
||||||
|
debug: cliArguments.debug !== undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
const dbArguments = ['dbclient', 'dbhost', 'dbport', 'dbname', 'dbusername', 'dbpassword'];
|
const dbArguments = ['dbclient', 'dbhost', 'dbport', 'dbname', 'dbusername', 'dbpassword'];
|
||||||
|
@ -53,6 +53,7 @@ program
|
|||||||
program
|
program
|
||||||
.command('new')
|
.command('new')
|
||||||
.option('-d, --dev', 'Development mode')
|
.option('-d, --dev', 'Development mode')
|
||||||
|
.option('--debug', 'Display database connection error')
|
||||||
.option('--dbclient <dbclient>', 'Database client')
|
.option('--dbclient <dbclient>', 'Database client')
|
||||||
.option('--dbhost <dbhost>', 'Database host')
|
.option('--dbhost <dbhost>', 'Database host')
|
||||||
.option('--dbport <dbport>', 'Database port')
|
.option('--dbport <dbport>', 'Database port')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user