Expose globals

This commit is contained in:
Aurélien Georget 2016-07-14 11:39:40 +02:00
parent 185542b74f
commit 3cd111bdb2
3 changed files with 9 additions and 11 deletions

View File

@ -50,8 +50,8 @@ module.exports = class Strapi extends EventEmitter {
}
// Private method to expose instance globals
this.exposeGlobals = () => {
require('./private/exposeGlobals').apply(this);
this.exposeGlobals = cb => {
require('./private/exposeGlobals').apply(this, [cb]);
}
// Private method to run instance bootstrap

View File

@ -44,17 +44,16 @@ module.exports = strapi => {
configOverride = configOverride || {};
strapi.config = _.cloneDeep(configOverride);
// Optionally expose globals as soon as the
// config hook is loaded.
strapi.on('hook:_config:loaded', strapi.exposeGlobals);
async.auto({
// Apply core defaults and hook-agnostic configuration,
// esp. overrides including command-line options, environment variables,
// and options that were passed in programmatically.
config: [Configuration.load],
// Optionally expose globals as soon as the
// config hook is loaded.
exposeGlobals: ['config', strapi.exposeGlobals],
// Initiliaze hooks global variable and configurations
hooks: ['config', initializeHooks],
hooks: ['exposeGlobals', initializeHooks],
// Load core's hooks into memory, with their middleware and routes.
dictionary: ['hooks', cb => loader('dictionary', cb)],
// Load core's hooks into memory, with their middleware and routes.

View File

@ -8,11 +8,10 @@
* @api private
*/
module.exports = function exposeGlobals() {
module.exports = cb => {
global.async = require('async');
global._ = require('lodash');
console.log(this);
global.strapi = this;
return cb();
};