diff --git a/packages/strapi/bin/strapi.js b/packages/strapi/bin/strapi.js index cefc542648..5226900af8 100755 --- a/packages/strapi/bin/strapi.js +++ b/packages/strapi/bin/strapi.js @@ -205,6 +205,11 @@ program .description('Starts the admin dev server') .action(getLocalScript('watchAdmin')); +program + .command('configuration:dump') + .option('-f, --file ', 'file to output to') + .action(getLocalScript('configurationDump')); + /** * Normalize help argument */ diff --git a/packages/strapi/lib/Strapi.js b/packages/strapi/lib/Strapi.js index 0d6a5bf6e4..8b9acb5e95 100644 --- a/packages/strapi/lib/Strapi.js +++ b/packages/strapi/lib/Strapi.js @@ -53,6 +53,7 @@ class Strapi { this.admin = {}; this.plugins = {}; this.config = loadConfiguration(this.dir, opts); + this.isLoaded = false; // internal services. this.fs = createStrapiFs(this); @@ -127,12 +128,9 @@ class Strapi { async start(cb) { try { - await this.load(); - - // Run bootstrap function. - await this.runBootstrapFunctions(); - // Freeze object. - await this.freeze(); + if (!this.isLoaded) { + await this.load(); + } this.app.use(this.router.routes()).use(this.router.allowedMethods()); @@ -236,6 +234,8 @@ class Strapi { } async load() { + this.isLoaded = true; + this.app.use(async (ctx, next) => { if (ctx.request.url === '/_health' && ctx.request.method === 'HEAD') { ctx.set('strapi', 'You are so French!'); @@ -294,6 +294,9 @@ class Strapi { // Initialize hooks and middlewares. await initializeMiddlewares.call(this); await initializeHooks.call(this); + + await this.runBootstrapFunctions(); + await this.freeze(); } async startWebhooks() { diff --git a/packages/strapi/lib/commands/configurationDump.js b/packages/strapi/lib/commands/configurationDump.js new file mode 100644 index 0000000000..c9480b0907 --- /dev/null +++ b/packages/strapi/lib/commands/configurationDump.js @@ -0,0 +1,25 @@ +'use strict'; + +const fs = require('fs'); +const { logger } = require('strapi-utils'); +const loadConfiguration = require('../core/app-configuration'); +const strapi = require('../index'); + +module.exports = async function({ file }) { + const output = file ? fs.createWriteStream(file) : process.stdout; + + output.write('this is a test'); + + const app = strapi(); + + await app.load(); + + const confs = await app.query('core_store').find({ + key_contains: 'plugin', + }); + + console.log(confs); + + output.write('\n'); + output.end(); +};