diff --git a/packages/strapi-generate-new/lib/resources/files/config/.init.json b/packages/strapi-generate-new/lib/resources/files/config/.init.json deleted file mode 100644 index 9697e15cde..0000000000 --- a/packages/strapi-generate-new/lib/resources/files/config/.init.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "init": true -} diff --git a/packages/strapi/lib/Strapi.js b/packages/strapi/lib/Strapi.js index fefd643a7f..f447d269c6 100644 --- a/packages/strapi/lib/Strapi.js +++ b/packages/strapi/lib/Strapi.js @@ -199,8 +199,8 @@ class Strapi extends EventEmitter { await this.runBootstrapFunctions(); // Freeze object. await this.freeze(); - // Init first start - utils.init(this.config); + // Is the project initialised? + const isInitialised = await utils.isInitialised(this); this.app.use(this.router.routes()).use(this.router.allowedMethods()); @@ -208,7 +208,7 @@ class Strapi extends EventEmitter { this.server.listen(this.config.port, async err => { if (err) return this.stopWithError(err); - if (this.config.init) { + if (!isInitialised) { this.logFirstStartupMessage(); } else { this.logStartupMessage(); @@ -228,7 +228,7 @@ class Strapi extends EventEmitter { 'server.admin.autoOpen', true ) !== false) || - this.config.init + !isInitialised ) { await utils.openBrowser.call(this); } diff --git a/packages/strapi/lib/utils/index.js b/packages/strapi/lib/utils/index.js index e5f029c254..c7221e7817 100644 --- a/packages/strapi/lib/utils/index.js +++ b/packages/strapi/lib/utils/index.js @@ -12,6 +12,7 @@ const { get, difference, intersection, + isEmpty, isObject, isFunction, } = require('lodash'); @@ -23,9 +24,22 @@ const exposer = require('./exposer'); const openBrowser = require('./openBrowser'); module.exports = { - init(config) { - if (config.init) { - fs.unlinkSync(path.resolve(config.appPath, 'config', '.init.json')); + /* + * Return false where there is no administrator, otherwise return true. + */ + async isInitialised(strapi) { + try { + if (isEmpty(strapi.admin)) { + return true; + } + + const numberOfAdministrators = await strapi + .query('administrator', 'admin') + .find({ _limit: 1 }); + + return numberOfAdministrators.length > 0; + } catch (err) { + strapi.stopWithError(err); } },