mirror of
https://github.com/strapi/strapi.git
synced 2025-08-31 20:33:03 +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();
|
await this.runBootstrapFunctions();
|
||||||
// Freeze object.
|
// Freeze object.
|
||||||
await this.freeze();
|
await this.freeze();
|
||||||
// Init first start
|
// Is the project initialised?
|
||||||
utils.init(this.config);
|
const isInitialised = await utils.isInitialised(this);
|
||||||
|
|
||||||
this.app.use(this.router.routes()).use(this.router.allowedMethods());
|
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 => {
|
this.server.listen(this.config.port, async err => {
|
||||||
if (err) return this.stopWithError(err);
|
if (err) return this.stopWithError(err);
|
||||||
|
|
||||||
if (this.config.init) {
|
if (!isInitialised) {
|
||||||
this.logFirstStartupMessage();
|
this.logFirstStartupMessage();
|
||||||
} else {
|
} else {
|
||||||
this.logStartupMessage();
|
this.logStartupMessage();
|
||||||
@ -228,7 +228,7 @@ class Strapi extends EventEmitter {
|
|||||||
'server.admin.autoOpen',
|
'server.admin.autoOpen',
|
||||||
true
|
true
|
||||||
) !== false) ||
|
) !== false) ||
|
||||||
this.config.init
|
!isInitialised
|
||||||
) {
|
) {
|
||||||
await utils.openBrowser.call(this);
|
await utils.openBrowser.call(this);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ const {
|
|||||||
get,
|
get,
|
||||||
difference,
|
difference,
|
||||||
intersection,
|
intersection,
|
||||||
|
isEmpty,
|
||||||
isObject,
|
isObject,
|
||||||
isFunction,
|
isFunction,
|
||||||
} = require('lodash');
|
} = require('lodash');
|
||||||
@ -23,9 +24,22 @@ const exposer = require('./exposer');
|
|||||||
const openBrowser = require('./openBrowser');
|
const openBrowser = require('./openBrowser');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init(config) {
|
/*
|
||||||
if (config.init) {
|
* Return false where there is no administrator, otherwise return true.
|
||||||
fs.unlinkSync(path.resolve(config.appPath, 'config', '.init.json'));
|
*/
|
||||||
|
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