troygoode / node-require-directory

Recursively iterates over specified directory, requiring each file, and returning a nested hash structure containing those libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rename customization not working, returning empty object

megancooper opened this issue · comments

commented

I am using the rename feature to convert kebab-case to camelCase. For some reason, when my index.js is the following (without any name changes) I can require the directly and get the contents in kebab case:

var requireDirectory = require('require-directory');
module.exports = requireDirectory(module);

Terminal Log

Handlers ::: { 'start-session': [Function] }

When I attempt to use rename, an empty object is returning:

var requireDirectory = require('require-directory'),
    renamer = function (name) {
        // convert names to camel case
        return name.replace(/[-_]([a-z])/g, function (g) { return g[1].toUpperCase(); })
    },
    hash = requireDirectory(module, {
        rename: renamer,
        recurse: false
    });

Terminal Log

Handlers ::: {}

Why does it stop working when I try to use some of the customization features?

My Folder Structure:

core/

  • index.js (with default requireDir, no customizations)
  • session/
    • routes.js (file trying to import/require handlers folder)
    • handlers/
      • index.js (file with custom camel case renaming not working)
      • start-session.js
commented

Fixed, I needed to add module.exports = requireDirectory(module);:

var requireDirectory = require('require-directory'),
    renamer = function (name) {
        // convert names to camel case
        return name.replace(/[-_]([a-z])/g, function (g) { return g[1].toUpperCase(); })
    },
    hash = requireDirectory(module, {
        rename: renamer,
        recurse: false
    });
module.exports = requireDirectory(module);