When creating great applications it is important to provide systems that allow features to be implemented and maintained as discrete units of code.
It is also important to avoid magic runtime binding where functionality is implied by folder structure or some other magic variables or constants.
However they lack the ability to autoload modules on the fly based on a dynamic folder structure such as the kind you would see in a modular framework that needs to bind dynamic packages of code together.
It is for this reason I created the Indexr open source project.
What Indexr does is it takes a folder, searches for any 'module' folders based on globs you provide and generates index files that export all the 'submodules' within the 'module' folders in whatever way you choose.
$ npm install -g indexr
Let's look at an example:
$ indexr . \
--out reducers.js \
--modules **/modules/ \
--submodules */reducer.js \
This example does the following:
- Use the current folder as a root folder
- Find module folders nested within this root folder that have the name
- Within each
modulesfolder find subfolder that contains an
- Create an ES6
reducers.jsfile within each 'modules' folder that directly imports the submodule's
- Export the reducers as named exports.
You can also do the same thing via Node API
import indexr from 'indexr';