-
Notifications
You must be signed in to change notification settings - Fork 1
/
hook.js
27 lines (26 loc) · 829 Bytes
/
hook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const fs = require("fs");
const _ = require("lodash");
const path = require("path");
module.exports = function(sails) {
const loader = require("./index")(sails);
const directoryPath = path.join(sails.config.appPath, "modules");
return {
getDirectories: function(path) {
return fs.readdirSync(path).filter(function(file) {
return fs.statSync(path + "/" + file).isDirectory();
});
},
initialize: function(next) {
const modules = this.getDirectories(directoryPath);
sails.after(["hook:i18n:loaded"], function() {
_.map(modules, mod => {
const modulePath = path.join(sails.config.appPath, "modules", mod);
loader.inject(modulePath, err => {
if (err) sails.log.warn(err);
});
});
});
return next();
}
};
};