include-all
Advanced tools
Comparing version 0.1.0 to 0.1.1
43
index.js
@@ -10,4 +10,21 @@ var fs = require('fs'); | ||
// Sane default for `filter` option | ||
if (!options.filter) { | ||
options.filter = /(.*)/; | ||
} | ||
// Reset our depth counter the first time | ||
if (typeof options._depth === 'undefined') { | ||
options._depth = 0; | ||
} | ||
// Bail out if our counter has reached the desired depth | ||
// indicated by the user in options.depth | ||
if (typeof options.depth !== 'undefined' && | ||
options._depth >= options.depth) { | ||
return; | ||
} | ||
// Remember the starting directory | ||
if(!options.startDirname) { | ||
if (!options.startDirname) { | ||
options.startDirname = options.dirname; | ||
@@ -18,4 +35,4 @@ } | ||
files = fs.readdirSync(options.dirname); | ||
} catch(e) { | ||
if(options.optional) return {}; | ||
} catch (e) { | ||
if (options.optional) return {}; | ||
else throw new Error('Directory not found: ' + options.dirname); | ||
@@ -29,6 +46,6 @@ } | ||
// For directories, continue to recursively include modules | ||
if(fs.statSync(filepath).isDirectory()) { | ||
if (fs.statSync(filepath).isDirectory()) { | ||
// Ignore explicitly excluded directories | ||
if(excludeDirectory(file)) return; | ||
if (excludeDirectory(file)) return; | ||
@@ -42,3 +59,7 @@ // Recursively call requireAll on each child directory | ||
startDirname: options.startDirname, | ||
dontLoad: options.dontLoad | ||
dontLoad: options.dontLoad, | ||
// Keep track of depth | ||
_depth: options._depth+1, | ||
depth: options.depth | ||
}); | ||
@@ -56,3 +77,3 @@ | ||
var match = file.match(options.filter); | ||
if(!match) return; | ||
if (!match) return; | ||
identity = match[1]; | ||
@@ -64,6 +85,6 @@ } | ||
// Peel off relative path | ||
var path = filepath.replace(options.startDirname,''); | ||
var path = filepath.replace(options.startDirname, ''); | ||
// make sure a slash exists on the left side of path | ||
path = '/' + ltrim(path,'/'); | ||
path = '/' + ltrim(path, '/'); | ||
@@ -86,2 +107,2 @@ var pathMatch = path.match(options.pathFilter); | ||
} | ||
}; | ||
}; |
{ | ||
"name": "include-all", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "An easy way to include all node.js modules within a directory. This is a fork of felixge's awesome module, require-all (https://github.com/felixge/node-require-all) which adds the ability to mark an include as **optional**.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6688
151