Merge pull request #4380 from strapi/enhancement/initialise-fn

Update initialisation detection when starting a project
This commit is contained in:
Alexandre BODIN 2019-10-28 17:51:15 +01:00 committed by GitHub
commit c0c7f134b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -1,3 +0,0 @@
{
"init": true
}

View File

@ -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);
}

View File

@ -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);
}
},