refactor: *.hooks.js
This commit is contained in:
parent
5eb21e5e26
commit
7deaa58fdb
|
@ -29,24 +29,25 @@ module.exports = function(source) {
|
|||
// Extract options.
|
||||
const {paths, root} = options;
|
||||
// Build registers.
|
||||
const sourcePaths = lookupSourcePaths(paths, 'hooks.js');
|
||||
const sourcePaths = lookupSourcePaths(paths, '*.hooks.js');
|
||||
const registers = sourcePaths.map((sourcePath) => {
|
||||
const relativePath = path.relative(root, sourcePath);
|
||||
const parts = relativePath.split('/');
|
||||
// Chop off basename.
|
||||
parts.pop();
|
||||
const basename = parts.pop();
|
||||
// Module or local?
|
||||
let importDirectory;
|
||||
if ('node_modules' === parts[0]) {
|
||||
importDirectory = parts.slice(1).join('/');
|
||||
}
|
||||
else {
|
||||
importDirectory = `./${parts.join('/')}`;
|
||||
importDirectory = `${root}/${parts.join('/')}`;
|
||||
}
|
||||
const moduleName = path.basename(basename, '.js');
|
||||
// Register hooks.
|
||||
const importPath = `${importDirectory}/hooks`;
|
||||
const importPath = `${importDirectory}/${moduleName}`;
|
||||
return [
|
||||
`registerHooks('${importDirectory}', require('${importPath}'));`,
|
||||
`registerHooks('${importPath}', require('${importPath}'));`,
|
||||
].join('\n');
|
||||
});
|
||||
// Import trait registry first.
|
||||
|
|
Loading…
Reference in New Issue
Block a user