Skip to content

Recursively find and call `require` on all matching files in a subdirectory.

License

Notifications You must be signed in to change notification settings

shane-tomlinson/glob-require

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

glob-require

Use glob to find and call require on all matching files in a directory tree.

Installation

npm install --save glob-require

Usage

  1. Install using npm: npm install glob-require
  2. 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:

License:

This software is available under version 2.0 of the MPL:

https://www.mozilla.org/MPL/

About

Recursively find and call `require` on all matching files in a subdirectory.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages