mirror of
https://github.com/strapi/strapi.git
synced 2025-08-31 12:23:05 +00:00
Merge pull request #4380 from strapi/enhancement/initialise-fn
Update initialisation detection when starting a project
This commit is contained in:
commit
c0c7f134b3
@ -1,3 +0,0 @@
|
||||
{
|
||||
"init": true
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user