npm i -D auto-index-file
yarn add -D auto-index-file
Ignore directories: you can exclude directories from processing.
Named exports: this tool can handle named exports from your components.
Recursive: handle subdirectories.
Watch: observe file changes and run automatically or just once.
-h, --help Show help message and exit.
-t, --targetDir Set target directory for processing (required).
-w, --watch Observe file changes (default: false).
-e, --excludedDirectories Excluded directories (default: ).
Run recursively and observe files changes:
autoIndexFile -t src/components -w
When you split your UI code into components usually you need some methodology to organize your code.
One way to do it - use Atomic Design way. But not dependence on your methodology you will have a deal with a lot of components and folders.
As result, you may recognize next situation.
src components atoms molecules organisms
It seems not bad, but not very comfortable too.
So, let's use an index.js file. We can create an index.js file in our root directory with components and import them from there.
src components atoms molecules organisms index.js
It seems better (from my view). But now we faced with a new problem - support index.js file in a consistent state.
It means if we add / create new / delete / rename / etc any component we also must update our index.js file manualy.
Mmm, no thanks! It more badly than the first approach.
Fortunately, this work very easy to automate!
Name calculation for default export: module name will be a directory name.
For above example module name will be - Link.
Name calculation for named export: module name will be a combination of directory name, underscore, export name.
For above example module name will be - Link_Anchor.
See example: here
It works only with es6 modules syntax.
It works only with files with .js extension.
This tool expects and works only with components structured by the following scheme:
Link - component directory index.js - component implementation (сase insensitive) ...
Feel free to ask or open an issue