require-plus
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -7,2 +7,3 @@ 'use strict'; | ||
const Path = require('path'); | ||
const Utils = require('basic-utils'); | ||
@@ -16,2 +17,3 @@ const internals = { | ||
const parentDir = Path.dirname(module.parent.filename); | ||
@@ -27,3 +29,3 @@ delete require.cache[__filename]; | ||
this.moduleSet = {}; | ||
if (Array.isArray(this._settings.directory)) { | ||
if (Utils.isArray(this._settings.directory)) { | ||
const length = this._settings.directory.length; | ||
@@ -45,6 +47,7 @@ for (let i = 0; i < length; ++i) { | ||
let mod; | ||
Fs.readdirSync(directory).forEach((path) => { | ||
const files = internals.readDir(directory); | ||
files.forEach((path) => { | ||
const joined = Path.resolve(directory, path); | ||
if (Fs.statSync(joined).isDirectory()) { | ||
if (Utils.isDir(joined)) { | ||
const blacklist = new RegExp(this._settings.blacklist.join('|'), 'i').test(path); | ||
@@ -94,31 +97,28 @@ if (!blacklist) { | ||
internals.resolve = function (path) { | ||
internals.readDir = (path) => { | ||
if (!Path.isAbsolute(path)) { | ||
path = Path.resolve(parentDir, path); | ||
try { | ||
return Fs.readdirSync(path); | ||
} | ||
if (!internals.isDir(path)) { | ||
throw new Error('Directory ' + path + ' does not exist'); | ||
catch (e) { | ||
throw e; | ||
} | ||
return path; | ||
}; | ||
internals.isDir = function (path) { | ||
internals.resolve = (path) => { | ||
try { | ||
path = Fs.lstatSync(path); | ||
return path.isDirectory() ? true : false; | ||
if (!Path.isAbsolute(path)) { | ||
path = Path.resolve(parentDir, path); | ||
} | ||
catch (e){ | ||
return false; | ||
} | ||
return path; | ||
}; | ||
module.exports = (options) => { | ||
const plus = new RequirePlus(options); | ||
return plus.moduleSet; | ||
return new RequirePlus(options).moduleSet; | ||
}; |
{ | ||
"name": "require-plus", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "better require for directories", | ||
@@ -28,10 +28,11 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"code": "^3.0.1", | ||
"coveralls": "^2.11.11", | ||
"lab": "^10.9.0" | ||
"code": "^4.0.0", | ||
"coveralls": "^2.11.14", | ||
"lab": "^11.1.0" | ||
}, | ||
"dependencies": { | ||
"deepmerge": "^0.2.10", | ||
"hoek": "^4.0.1" | ||
"basic-utils": "^1.7.0", | ||
"deepmerge": "^1.2.0", | ||
"hoek": "^4.1.0" | ||
} | ||
} |
# require-plus | ||
[](https://travis-ci.org/simon-p-r/require-plus) | ||
[](https://www.npmjs.org/package/require-plus) | ||
[](https://coveralls.io/github/simon-p-r/require-plus?branch=master) | ||
[](https://travis-ci.org/simon-p-r/require-plus) | ||
[](https://www.npmjs.org/package/require-plus) | ||
[](https://david-dm.org/simon-p-r/require-plus) | ||
[](https://david-dm.org/simon-p-r/require-plus?type=dev) | ||
[](https://coveralls.io/github/simon-p-r/require-plus) | ||
Node module for requiring a directory tree, it will throw if not a valid directory and it will also throw if the object is not exported properly or cannot be required by require. | ||
@@ -18,3 +19,3 @@ | ||
var options = { | ||
const options = { | ||
blacklist: ['node_modules', '.git', '.idea'], | ||
@@ -24,5 +25,6 @@ extensions: ['.js','.json'], | ||
}; | ||
var plus = require('require-plus')(options); | ||
const plus = require('require-plus')(options); | ||
console.log(plus); | ||
//plus is an object | ||
//plus is an object containing modules exported from above directories | ||
@@ -29,0 +31,0 @@ ##Todo |
11512
34
3
225
+ Addedbasic-utils@^1.7.0
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbasic-utils@1.7.4(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddeep-freeze@0.0.1(transitive)
+ Addeddeepmerge@1.5.2(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removeddeepmerge@0.2.10(transitive)
Updateddeepmerge@^1.2.0
Updatedhoek@^4.1.0