Skip to content

Latest commit

Β 

History

History

index-require

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

index-require

☝️ Create an index for a lib directory

Scan directory for nested directories and create an index module

Tree

β”œβ”€β”€ main.js
└── lib
    β”œβ”€β”€ index.js
    β”œβ”€β”€ module1
    β”‚   β”œβ”€β”€ index.js
    β”‚   └── spec.js
    └── module2
        β”œβ”€β”€ index.js
        └── spec.js

lib/index.js

const inedx = require('index-require');
module.exports = inedx(__dirname);

main.js

const {module1, module2} = require('./lib');

App with features structure

app.js

 β”œβ”€β”€ app.js
 β”œβ”€β”€ feature1
 β”‚Β Β  β”œβ”€β”€ index.js
 β”‚Β Β  └── spec.js
 └── feature2
     β”œβ”€β”€ index.js
     └── spec.js

app.js

const inedx = require('index-require');
const {
	feature1,
	feature2,
} = inedx(__dirname);

Optional second argument for different structures

const inedx = require('index-require');
module.exports = inedx(__dirname, name => `./${name}/main.js`);