Skip to content

Commit

Permalink
add "hookName" option to installable hook config
Browse files Browse the repository at this point in the history
- set "hookName" in order to specify installable hook name.
e.g. {
  "sails": {
    "isHook": true,
    "hookName": "myHook"
  }
}
  • Loading branch information
tjwebb committed Aug 20, 2015
1 parent 867c162 commit 66040dc
Showing 1 changed file with 5 additions and 46 deletions.
51 changes: 5 additions & 46 deletions lib/hooks/moduleloader/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
module.exports = function(sails) {


/**
* Module dependencies
*/

var path = require('path');
var async = require('async');
var _ = require('lodash');
var buildDictionary = require('sails-build-dictionary');
var walk = require('walk');


// TODO:
// Look at improving `includeAll` to work asynchronously
// CommonJS `require` is a blocking operation, and makes apps
// start slower.



/**
* Module loader
*
* Load a module into memory
*/
return {


// Default configuration
defaults: function (config) {

var localConfig = {
Expand Down Expand Up @@ -158,7 +142,6 @@ module.exports = function(sails) {
return localConfig;
},


initialize: function(cb) {
// Expose self as `sails.modules` (for backwards compatibility)
sails.modules = sails.hooks.moduleloader;
Expand All @@ -174,8 +157,6 @@ module.exports = function(sails) {
this.configure();
}
}
// console.log('Trying to use appPath:',sails.config.appPath);
// console.log('Trying to use config dir at:',path.resolve(sails.config.appPath, 'config'));
sails.config.appPath = sails.config.appPath ? path.resolve(sails.config.appPath) : process.cwd();

_.extend(sails.config.paths, {
Expand Down Expand Up @@ -220,7 +201,6 @@ module.exports = function(sails) {
loadUserConfig: function (cb) {

async.auto({

'config/*': function loadOtherConfigFiles (cb) {
buildDictionary.aggregate({
dirname : sails.config.paths.config || sails.config.appPath + '/config',
Expand All @@ -232,7 +212,6 @@ module.exports = function(sails) {
}, cb);
},


'config/local' : function loadLocalOverrideFile (cb) {
buildDictionary.aggregate({
dirname : sails.config.paths.config || sails.config.appPath + '/config',
Expand Down Expand Up @@ -290,8 +269,6 @@ module.exports = function(sails) {
});
},



/**
* Load app controllers
*
Expand All @@ -308,9 +285,6 @@ module.exports = function(sails) {
}, bindToSails(cb));
},




/**
* Load adapters
*
Expand All @@ -326,9 +300,6 @@ module.exports = function(sails) {
}, bindToSails(cb));
},




/**
* Load app's model definitions
*
Expand Down Expand Up @@ -357,10 +328,6 @@ module.exports = function(sails) {
});
},





/**
* Load app services
*
Expand All @@ -376,8 +343,6 @@ module.exports = function(sails) {
}, bindToSails(cb));
},



/**
* Check for the existence of views in the app
*
Expand All @@ -393,8 +358,6 @@ module.exports = function(sails) {
}, cb);
},



/**
* Load app policies
*
Expand All @@ -411,8 +374,6 @@ module.exports = function(sails) {
}, bindToSails(cb));
},



/**
* Load app hooks
*
Expand Down Expand Up @@ -452,20 +413,23 @@ module.exports = function(sails) {
var hooks = results.hooksFolder;

try {

var modules = flattenNamespacedModules(results.nodeModulesFolder);

_.extend(hooks, _.reduce(modules, function(memo, module, identity) {

// Hooks loaded from "node_modules" need to have "sails.isHook: true" in order for us
// to know that they are a sails hook
if (module['package.json'] && module['package.json'].sails && module['package.json'].sails.isHook) {
var hookConfig = module['package.json'].sails;

// Determine the name the hook should be added as
var hookName;

if (!_.isEmpty(hookConfig.hookName)) {
hookName = hookConfig.hookName;
}
// If an identity was specified in sails.config.installedHooks, use that
if (sails.config.installedHooks && sails.config.installedHooks[identity] && sails.config.installedHooks[identity].name) {
else if (sails.config.installedHooks && sails.config.installedHooks[identity] && sails.config.installedHooks[identity].name) {
hookName = sails.config.installedHooks[identity].name;
}
// Otherwise use the module name, with initial "sails-hook" stripped off if it exists
Expand Down Expand Up @@ -512,8 +476,6 @@ module.exports = function(sails) {
});
},



/**
* Load app blueprint middleware.
*
Expand All @@ -528,8 +490,6 @@ module.exports = function(sails) {
}, cb);
},



/**
* Load custom API responses.
*
Expand All @@ -548,7 +508,6 @@ module.exports = function(sails) {
required: buildDictionary.required,
aggregate: buildDictionary.aggregate,
exits: buildDictionary.exists

};

function bindToSails(cb) {
Expand Down

0 comments on commit 66040dc

Please sign in to comment.