Skip to content

Commit

Permalink
moved to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
tblobaum committed Dec 16, 2011
1 parent 332e18b commit d64811c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -28,7 +28,7 @@ Require a different directory:

```javascript
require('directory')(__dirname + '/plugins', function (module, name) {
require('directory')(__dirname + '/plugins/', function (module, name) {
models.plugin(module, options)
})
Expand Down
31 changes: 1 addition & 30 deletions index.js
@@ -1,30 +1 @@

/*!
* node-directory
* Copyright(c) Thomas Blobaum
* MIT Licensed
*/

module.exports = function modulate(dirname, callback) {

if (!callback) {
var callback = dirname
}

if (typeof dirname == 'function') {
var dirname = module.parent.paths[0].split("node_modules")[0]
}


var paths = require('findit').sync(dirname)

paths.forEach(function (path) {
if (!path.match(module.parent.id)) {
var filename = path.split(dirname)[1].split(".js")[0]
callback(require(path), filename)
}
})

delete require.cache[__filename]
}

module.exports = require('./lib/directory')
32 changes: 32 additions & 0 deletions lib/directory.js
@@ -0,0 +1,32 @@

/*!
* node-directory
* Copyright(c) Thomas Blobaum
* MIT Licensed
*/

function modulate (dirname, callback) {

if (!callback) {
var callback = dirname
}

if (typeof dirname == 'function') {
var dirname = module.parent.paths[0].split("node_modules")[0]
}


var paths = require('findit').sync(dirname)

paths.forEach(function (path) {
if (!path.match(module.parent.id)) {
var filename = path.split(dirname)[1].split(".js")[0]
callback(require(path), filename)
}
})

delete require.cache[__filename]
}

module.exports = modulate

0 comments on commit d64811c

Please sign in to comment.