diff --git a/lib/Strapi.js b/lib/Strapi.js index d25f75b2eb..ffef8233d9 100755 --- a/lib/Strapi.js +++ b/lib/Strapi.js @@ -10,7 +10,6 @@ const events = require('events'); const util = require('util'); // Public node modules. -const _ = require('lodash'); const winston = require('winston'); // Local dependencies. @@ -37,17 +36,6 @@ function Strapi() { // Mixin support for `Strapi.prototype.after()`. mixinAfter(this); - // Bind `this` context for all `Strapi.prototype.*` methods. - this.load = _.bind(this.load, this); - this.start = _.bind(this.start, this); - this.stop = _.bind(this.stop, this); - this.restart = _.bind(this.restart, this); - this.initialize = _.bind(this.initialize, this); - this.exposeGlobals = _.bind(this.exposeGlobals, this); - this.runBootstrap = _.bind(this.runBootstrap, this); - this.isLocalStrapiValid = _.bind(this.isLocalStrapiValid, this); - this.isStrapiAppSync = _.bind(this.isStrapiAppSync, this); - // Expose `koa`. this.server = require('koa'); this.app = require('koa')(); diff --git a/lib/load.js b/lib/load.js index 271bb2e887..09dd29f0e6 100755 --- a/lib/load.js +++ b/lib/load.js @@ -17,7 +17,7 @@ const __initializeHooks = require('./private/loadHooks'); * Load the Strapi instance */ -module.exports = function (strapi) { +module.exports = strapi => { const Configuration = __Configuration(strapi); const initializeHooks = __initializeHooks(strapi); @@ -80,13 +80,9 @@ module.exports = function (strapi) { } async.series([ - function (cb) { - loadHookDefinitions(strapi.hooks, cb); - }, - function (cb) { - initializeHooks(strapi.hooks, cb); - } - ], function (err) { + cb => loadHookDefinitions(strapi.hooks, cb), + cb => initializeHooks(strapi.hooks, cb) + ], err => { if (err) { return cb(err); } diff --git a/lib/restart.js b/lib/restart.js index fd195c95a7..ce912fa558 100644 --- a/lib/restart.js +++ b/lib/restart.js @@ -16,81 +16,73 @@ const async = require('async'); * (useful for the Studio) */ -module.exports = function (cb) { - const self = this; +module.exports = cb => { console.log(); // Update the Strapi status (might be used // by the core or some hooks). - self.reloading = true; + this.reloading = true; // Async module loader to rebuild a // dictionary of the application. async.auto({ // Rebuild the dictionaries. - dictionaries: function (cb) { - self.on('hook:_config:reloaded', function () { - self.on('hook:_api:reloaded', function () { - cb(); - }); - - self.hooks._api.reload(); + dictionaries: cb => { + this.on('hook:_config:reloaded', () => { + this.on('hook:_api:reloaded', () => cb()); + this.hooks._api.reload(); }); - self.hooks._config.reload(); + this.hooks._config.reload(); } }, // Callback. - function (err) { + err => { // Just in case there is an error. if (err) { - self.log.error('Impossible to reload the server'); - self.log.error('Please restart the server manually'); - self.stop(); + this.log.error('Impossible to reload the server'); + this.log.error('Please restart the server manually'); + this.stop(); } // Tell the application the framework is reloading // (might be used by some hooks). - self.reloading = true; + this.reloading = true; // Teardown Waterline adapters and // reload the Waterline ORM. - self.after('hook:waterline:reloaded', function () { - self.after('hook:router:reloaded', function () { - process.nextTick(function () { - cb(); - }); + this.after('hook:waterline:reloaded', () => { + this.after('hook:router:reloaded', () => { + process.nextTick(() => cb()); // Update `strapi` status. - self.reloaded = true; - self.reloading = false; + this.reloaded = true; + this.reloading = false; // Finally inform the developer everything seems ok. if (cluster.isMaster && _.isPlainObject(strapi.config.reload) && !_.isEmpty(strapi.config.reload) && strapi.config.reload.workers < 1) { - self.log.info('Application\'s dictionnary updated'); - self.log.warn('You still need to restart your server to fully enjoy changes...'); + this.log.info('Application\'s dictionnary updated'); + this.log.warn('You still need to restart your server to fully enjoy changes...'); } // Kill every worker processes. - _.forEach(cluster.workers, function () { - process.kill(process.pid, 'SIGHUP'); - }); + _.forEach(cluster.workers, () => process.kill(process.pid, 'SIGHUP')); if (cluster.isMaster && _.isPlainObject(strapi.config.reload) && !_.isEmpty(strapi.config.reload) && strapi.config.reload.workers > 0) { - self.log.info('Application restarted'); + this.log.info('Application restarted'); console.log(); } }); // Reloading the router. - self.hooks.router.reload(); + this.hooks.router.reload(); }); // Reloading the ORM. - self.hooks.waterline.reload(); + this.hooks.waterline.reload(); }); }; diff --git a/lib/server.js b/lib/server.js index 25d075ce5e..258136d2be 100755 --- a/lib/server.js +++ b/lib/server.js @@ -4,9 +4,6 @@ * Module dependencies */ -// Public node modules. -const _ = require('lodash'); - // Local dependencies. const Strapi = require('./Strapi'); @@ -15,13 +12,6 @@ const Strapi = require('./Strapi'); * (maintains backwards compatibility with constructor usage). */ -module.exports = strapiFactory; - -function strapiFactory() { +module.exports = function () { return new Strapi(); -} - -// Backwards compatibility for Strapi singleton usage. -const singleton = strapiFactory(); -strapiFactory.isLocalStrapiValid = _.bind(singleton.isLocalStrapiValid, singleton); -strapiFactory.isStrapiAppSync = _.bind(singleton.isStrapiAppSync, singleton); +}; diff --git a/lib/start.js b/lib/start.js index efed9456f2..2561870f8d 100755 --- a/lib/start.js +++ b/lib/start.js @@ -29,10 +29,8 @@ module.exports = function start(configOverride, cb) { }; async.series([ - function (cb) { - self.load(configOverride, cb); - }, - self.initialize + cb => self.load(configOverride, cb), + this.initialize ], function strapiReady(err) { diff --git a/lib/stop.js b/lib/stop.js index 433e596c6f..fdd73711cc 100755 --- a/lib/stop.js +++ b/lib/stop.js @@ -12,15 +12,14 @@ */ module.exports = function stop() { - const self = this; - // Flag `self._exiting` as soon as the application has begun to shutdown. + // Flag `this._exiting` as soon as the application has begun to shutdown. // This may be used by hooks and other parts of core. - self._exiting = true; + this._exiting = true; // Exit the REPL. process.exit(0); // Emit a `stop` event. - self.emit('stop'); + this.emit('stop'); };