Comparing version 0.1.1 to 0.1.2
13
index.js
@@ -10,3 +10,4 @@ require('coffee-script/register'); | ||
module.exports = function(dir){ | ||
var res = {} | ||
dir = path.resolve(dir); | ||
var res = {}; | ||
var objs = fs.readdirSync(dir) | ||
@@ -20,7 +21,7 @@ // ignore index file | ||
// remove extensions | ||
.map(function(f){ return f.replace(extensions_regex(), '') }) | ||
.map(function(f){ return f.replace(extensions_regex(), '') }); | ||
objs.forEach(function(obj){ | ||
try { | ||
res[obj] = require(path.join(dir, obj)) | ||
res[obj] = require(path.join(dir, obj)); | ||
} catch (err) { | ||
@@ -35,5 +36,5 @@ console.error('could not require '.red.bold + obj.red.bold); | ||
// | ||
// | ||
// @api private | ||
// | ||
// | ||
@@ -44,3 +45,3 @@ function isDir(dir, f){ return fs.statSync(path.join(dir,f)).isDirectory() } | ||
var str = ''; | ||
valid_extensions.forEach(function(ext){ str += '.' + ext + '$' + '|'; }); | ||
valid_extensions.forEach(function(ext){ str += '\\.' + ext + '$' + '|'; }); | ||
return new RegExp(str.slice(0,-1)) | ||
@@ -47,0 +48,0 @@ } |
{ | ||
"name": "indx", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Jeff Escalante <hello@jenius.me>", | ||
@@ -23,4 +23,6 @@ "description": "require_tree for node", | ||
"scripts": { | ||
"test": "mocha", | ||
"coverage": "istanbul cover _mocha --report html -- -R spec && open coverage/index.html", | ||
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage" | ||
} | ||
} |
Indx | ||
---- | ||
[![npm](https://badge.fury.io/js/indx.png)](http://badge.fury.io/js/indx) | ||
[![tests](https://travis-ci.org/jenius/indx.png?branch=master)](https://travis-ci.org/jenius/indx) | ||
[![dependencies](https://david-dm.org/jenius/indx.png?theme=shields.io)](https://david-dm.org/jenius/indx) | ||
[![coverage](https://coveralls.io/repos/jenius/indx/badge.png)](https://coveralls.io/r/jenius/indx) | ||
[![npm](http://img.shields.io/npm/v/indx.svg?style=flat)](https://badge.fury.io/js/indx) [![tests](http://img.shields.io/travis/jenius/indx/master.svg?style=flat)](https://travis-ci.org/jenius/indx) [![coverage](http://img.shields.io/coveralls/jenius/indx.svg?style=flat)](https://coveralls.io/r/jenius/indx) [![dependencies](http://img.shields.io/gemnasium/jenius/indx.svg?style=flat)](https://gemnasium.com/jenius/indx) | ||
@@ -21,3 +18,3 @@ Require a folder of files or other folders, instead of doing them one at a time. | ||
`npm install indx --save` | ||
`npm install indx` | ||
@@ -32,4 +29,10 @@ ### Usage | ||
...that's it. | ||
This you can require that folder and each of the files will be present. Alternately, just pass `indx` the path of a directory you want to require: | ||
```js | ||
var adapters = require('indx')('./adapters') | ||
``` | ||
The path you pass will be passed through [path.resolve](http://nodejs.org/api/path.html#path_path_resolve_from_to), so no need to compute an absolute path if you don't need to. The example above will work fine without having to run any additional `path` methods on it as long as the relative path there is correct. | ||
Indx supports javascript and coffeescript. If you have folders inside your folder, make sure each of those folders has an `index.js` or `index.coffee` file in it, or it won't be required. If you have files in your folder that are not `.js` or `.coffee`, they will not be required. If there are other languages I'm not aware of you'd like to add support for, feel free to submit a pull request - it's easy to extend the supported extensions. | ||
@@ -36,0 +39,0 @@ |
Sorry, the diff of this file is not supported yet
41
4994
4
43