Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Adds global hooks. #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ module.exports = generators.Base.extend({

if (this.props.authentication.length) {
this.dependencies.push('feathers-authentication');

this.fs.copy(
this.templatePath('hooks.auth.js'),
this.destinationPath('server/hooks', 'auth.js')
);
}
},

Expand Down
3 changes: 3 additions & 0 deletions app/templates/hooks.auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {hooks} from 'feathers-authentication';

export default hooks;
3 changes: 3 additions & 0 deletions app/templates/static/server/hooks/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import hooks from 'feathers-hooks/hooks';

export default hooks;
22 changes: 18 additions & 4 deletions app/templates/static/server/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// jshint unused:false
export default function() {
const app = this;
}
// Read all hooks from the file system and arrange them into a single object.
import fs from 'fs';

let hooks = {};

fs.readdir(__dirname, (err, files) => {
files.forEach(fileName => {
if (fileName.indexOf('.js') >= 0 && fileName !== 'index.js') {
fileName = fileName.replace('.js', '');
let camelCased = fileName.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
let module = require('./' + fileName);
module = module.default ? module.default : module;
hooks[camelCased] = module;
}
});
});

export default hooks;