From 080fd1721bd928d605e076aecfdb1fe14ac8c469 Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Fri, 28 Dec 2018 14:59:45 +0100 Subject: [PATCH 1/3] In dev mode use local connectivity script --- packages/strapi-generate-new/lib/before.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/strapi-generate-new/lib/before.js b/packages/strapi-generate-new/lib/before.js index bc69e93e2e..fff1a83e98 100644 --- a/packages/strapi-generate-new/lib/before.js +++ b/packages/strapi-generate-new/lib/before.js @@ -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(); + } }); }) ]; From 6de05cbdad99a72c5922c6e68ce698519863cb68 Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Fri, 28 Dec 2018 16:51:02 +0100 Subject: [PATCH 2/3] Add debug option on strapi new --- packages/strapi-generate-new/lib/before.js | 2 +- .../lib/utils/connectivity.js | 26 ++++++++++++++++--- .../lib/utils/connectivity.js | 8 +++++- packages/strapi/bin/strapi-new.js | 3 ++- packages/strapi/bin/strapi.js | 1 + 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/packages/strapi-generate-new/lib/before.js b/packages/strapi-generate-new/lib/before.js index fff1a83e98..3bdce44d98 100644 --- a/packages/strapi-generate-new/lib/before.js +++ b/packages/strapi-generate-new/lib/before.js @@ -266,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(); } }); diff --git a/packages/strapi-hook-bookshelf/lib/utils/connectivity.js b/packages/strapi-hook-bookshelf/lib/utils/connectivity.js index 34671904b7..187492aa61 100644 --- a/packages/strapi-hook-bookshelf/lib/utils/connectivity.js +++ b/packages/strapi-hook-bookshelf/lib/utils/connectivity.js @@ -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(); }); }; diff --git a/packages/strapi-hook-mongoose/lib/utils/connectivity.js b/packages/strapi-hook-mongoose/lib/utils/connectivity.js index 214ab4196b..f2addd4b0c 100644 --- a/packages/strapi-hook-mongoose/lib/utils/connectivity.js +++ b/packages/strapi-hook-mongoose/lib/utils/connectivity.js @@ -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(); } diff --git a/packages/strapi/bin/strapi-new.js b/packages/strapi/bin/strapi-new.js index 6c475c28f7..718bf93e79 100644 --- a/packages/strapi/bin/strapi-new.js +++ b/packages/strapi/bin/strapi-new.js @@ -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']; diff --git a/packages/strapi/bin/strapi.js b/packages/strapi/bin/strapi.js index 453a7705eb..1740314572 100755 --- a/packages/strapi/bin/strapi.js +++ b/packages/strapi/bin/strapi.js @@ -53,6 +53,7 @@ program program .command('new') .option('-d, --dev', 'Development mode') + .option('--debug', 'Display database connection error') .option('--dbclient ', 'Database client') .option('--dbhost ', 'Database host') .option('--dbport ', 'Database port') From 31626ae14e0d853383c3e2a6f2e1de98e69fe78f Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Fri, 28 Dec 2018 17:05:16 +0100 Subject: [PATCH 3/3] Add documentation --- docs/3.x.x/cli/CLI.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/3.x.x/cli/CLI.md b/docs/3.x.x/cli/CLI.md index 5ed7c01e84..e56430d188 100644 --- a/docs/3.x.x/cli/CLI.md +++ b/docs/3.x.x/cli/CLI.md @@ -10,7 +10,7 @@ Create a new project ```bash strapi new -options: [--dev|--dbclient= --dbhost= --dbport= --dbname= --dbusername= --dbpassword= --dbssl= --dbauth=] +options: [--dev|--debug|--dbclient= --dbhost= --dbport= --dbname= --dbusername= --dbpassword= --dbssl= --dbauth=] ``` - **strapi new <name>**
@@ -19,6 +19,9 @@ options: [--dev|--dbclient= --dbhost= --dbport= --dbna - **strapi new <name> --dev**
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**
+ 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>**
Generates a new project called **<name>** and skip the interactive database configuration and initilize with these options. - **<dbclient>** can be `mongo`, `postgres`, `mysql`.