Simple generator of index files for ES-modules. It well working with TypeScript, Flow, ESlint, Prettier.
If you have this structure in project:
src/
├── C.js
└── foo
├── A.js
└── B.js
After run npx idxgen src
, you will have this structure:
src/
├── C.js
├── foo
│ ├── A.js
│ ├── B.js
│ └── index.js
└── index.js
Where src/index.js
:
/* Auto-generated - start - do not modify in this block */
export { default as C } from './C';
/* Auto-generated - end */
And src/foo/index.js
:
/* Auto-generated - start - do not modify in this block */
export { default as A } from './A';
export { default as B } from './B';
/* Auto-generated - end */
npm install --save-dev idxgen
Generate index.js
files in src
folder. It travels recursively.
npx idxgen src/
Run in watch mode:
npx idxgen --watch src/
For disabling generation you can put this annotation:
// idxgen-disable
For configure this tool you can create .idxgenrc
:
{
"mode": "manual",
"exportMode": "single",
"template": "export { $$ } from './$$';",
"indexFile": "index.ts",
"extensions": ["ts", "tsx"],
"support": {
"flow": true,
"eslint": true,
"prettier": true
}
}
In manual
mode it will generate exports in index files if it contain // idxgen-enable
pragma.
In auto
mode it will generate exports in all index files if it isn't contain // idxgen-disable
pragma. Default value auto
.
In single
export mode it will use export { $$ } from './$$';
template instead
export { default as $$ } from './$$';
in default
mode. Important if template
variable is used
(or idxgen-template
pragma in index file) exportMode
will not been applied.
With this You can override export statement in index files. Or you can override in only one file
with // idxgen-template
pragma.
Filename of index files. Default value: index.js
.
Extensions of file for lookup in folders. Default value: [".js", "jsx"]
.
This object contain support-flags for integration with 3-rd part tools.
If this support is enabled it will insert // @flow
at the top of index file.
If this support is enabled it will insert /* eslint-disable import/prefer-default-export */
if
you have one export in a index file.
If this support is enabled it will insert // prettier-ignore
if line will be more than
printWidth
in prettier config.
This project is licensed under the MIT License - see the LICENSE.md file for details