glob-require
v0.0.2
Published
Use glob to find and call `require` on all matching files in a directory tree.
Downloads
29
Maintainers
Readme
glob-require
Use glob to find and call require
on all matching files in a directory tree.
Installation
npm install --save glob-require
Usage
- Install using npm:
npm install glob-require
- Include it in your source:
const globRequire = require('glob-require');
// simple case, pass in a subdirectory to include to
// search for and require all .js files.
globRequire(SUBDIR_TO_INCLUDE, function(err, includes) {
// includes is an array of included files.
// each include contains two fields:
// * path - full path to included file
// * exports - the return value of `require`
processIncludes(includes);
});
const globRequire = require('glob-require');
// advanced case, pass a 'glob' pattern and configuration object.
// See https://github.com/isaacs/node-glob#options for a list of options.
globRequire('**/*.js', {
cwd: SUBDIR_TO_INCLUDE
}, function(err, includes) {
// includes is an array of included files.
// each include contains two fields:
// * path - full path to included file
// * exports - the return value of `require`
processIncludes(includes);
});
Run the tests
npm test
Get involved:
If you find a bugs or see any features you wish to add, file an issue or submit a pull request!
Repo information:
https://github.com/shane-tomlinson/glob-require
Author:
- Shane Tomlinson
- [email protected]
- [email protected]
- [email protected]
- https://shanetomlinson.com
- https://github.com/shane-tomlinson
- @shane_tomlinson
License:
This software is available under version 2.0 of the MPL:
https://www.mozilla.org/MPL/