diff --git a/core/boot.js b/core/boot.js index c8881f95a5..55fe75eb5f 100644 --- a/core/boot.js +++ b/core/boot.js @@ -93,11 +93,6 @@ async function initFrontend() { async function initExpressApps() { debug('Begin: initExpressApps'); const parentApp = require('./server/web/parent/app')(); - - // @TODO: fix this - const {events} = require('./server/lib/common'); - events.emit('themes.ready'); - debug('End: initExpressApps'); return parentApp; } @@ -157,22 +152,29 @@ async function initServices({config}) { } /** - * Kick off recurring and background jobs + * Kick off recurring jobs and background services * These are things that happen on boot, but we don't need to wait for them to finish + * Later, this might be a service hook */ -async function initRecurringJobs({config}) { - debug('Begin: initRecurringJobs'); - // we don't want to kick off scheduled/recurring jobs that will interfere with tests +async function initBackgroundServices({config}) { + debug('Begin: initBackgroundServices'); + + // we don't want to kick off background services that will interfere with tests if (process.env.NODE_ENV.match(/^testing/)) { return; } + // Load email analytics recurring jobs if (config.get('backgroundJobs:emailAnalytics')) { const emailAnalyticsJobs = require('./server/services/email-analytics/jobs'); await emailAnalyticsJobs.scheduleRecurringJobs(); } - debug('End: initRecurringJobs'); + // Load all inactive themes + const themeService = require('./frontend/services/themes'); + themeService.loadInactiveThemes(); + + debug('End: initBackgroundServices'); } /** @@ -270,8 +272,8 @@ async function bootGhost() { notifyServerReady(); - // Init our background jobs, we don't wait for this to finish - initRecurringJobs({config}); + // Init our background services, we don't wait for this to finish + initBackgroundServices({config}); // We return the server for testing purposes debug('End Boot: Returning Ghost Server'); diff --git a/core/frontend/services/themes/index.js b/core/frontend/services/themes/index.js index 905b3d7981..4dd0b0559c 100644 --- a/core/frontend/services/themes/index.js +++ b/core/frontend/services/themes/index.js @@ -22,12 +22,6 @@ module.exports = { i18n.init(activeThemeName); debug('init themes', activeThemeName); - - // Register a listener for when the server says we can start to load all themes - events.on('themes.ready', function readAllThemesOnReady() { - themeLoader.loadAllThemes(); - }); - // Just read the active theme for now return themeLoader .loadOneTheme(activeThemeName) @@ -109,5 +103,11 @@ module.exports = { }, storage: require('./storage'), middleware: require('./middleware'), - loadCoreHelpers: require('./handlebars/helpers').loadCoreHelpers + loadCoreHelpers: require('./handlebars/helpers').loadCoreHelpers, + /** + * Load all inactive themes + */ + loadInactiveThemes: async () => { + return await themeLoader.loadAllThemes(); + } }; diff --git a/test/utils/index.js b/test/utils/index.js index b7f63aa9cb..8642874fcb 100644 --- a/test/utils/index.js +++ b/test/utils/index.js @@ -203,7 +203,7 @@ const restartModeGhostStart = async () => { web.shared.middlewares.customRedirects.reload(); // Trigger themes to load again - events.emit('themes.ready'); + themes.loadInactiveThemes(); }; const bootGhost = async () => {