https://github.com/mattriley/node-module-indexgen
Generates barrel (index.js) files that rollup exports for each module in a directory and re-exports them as a single module.
https://github.com/mattriley/node-module-indexgen
barrel code-generator indexjs javascript nodejs npm-package rollup
Last synced: 3 months ago
JSON representation
Generates barrel (index.js) files that rollup exports for each module in a directory and re-exports them as a single module.
- Host: GitHub
- URL: https://github.com/mattriley/node-module-indexgen
- Owner: mattriley
- Created: 2020-07-04T02:13:07.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-22T13:04:32.000Z (over 1 year ago)
- Last Synced: 2025-01-31T19:18:43.421Z (4 months ago)
- Topics: barrel, code-generator, indexjs, javascript, nodejs, npm-package, rollup
- Language: JavaScript
- Homepage:
- Size: 2.49 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README-TEMPLATE.md
Awesome Lists containing this project
README
<%- lib.renderOpening() %>
## Install
<%- await lib.renderCode('npm install module-indexgen', '', 'https://www.npmjs.com/package/module-indexgen') %>
Not to be confused with `indexgen` which is similar but deprecated.
## Usage
```
npx indexgen [...] [options]
```Options:
`--watch`: Regenerate on file changes.
`--watchDelay`: Number of milliseconds to delay before reacting to file changes. Default is `1000`.
`--type`: `cjs` or `esm`. Default is `cjs`.
`--fullySpecified`: Maintain fully specified import paths as required by `esm`. Default is `true` for `esm`, otherwise `false`.
`--only`: Glob pattern to limit included files. Default is `*.{cjs,mjs,js,json,jsx}`.
`--ignore`: Paths to ignore. Default is `node_modules`.
`--case`: Case to apply to generated keys. Options are `camel`, `pascal`, `auto`, `none`. Default is `auto`.
`--sortSeparator`: Ignores the left side for the purpose of ordering, e.g. `1--b.js` and `2--a.js` becomes `b` and `a` in that order. Default is `--`.
`--reverseDelimiter`: Reverses generated keys by comma, e.g. `bar,foo` becomes `fooBar`. Default is `,`.
## Example
Given the following directory structure:
```
proj/
src/
components/
foo.js
bar.js
```Running `indexgen` from the `proj` directory produces:
```
proj/
src/
index.js
components/
bar.js
foo.js
foo-bar.js
index.js
```Contents of `proj/src/components/index.js`:
```js
module.exports = {
bar: require('./bar'),
foo: require('./foo'),
fooBar: require('./foo-bar')
}
```Notice the key for `foo-bar` is camel cased to `fooBar`.
Contents of `proj/src/index.js`:
```js
module.exports = {
components: require('./components')
}
````require('./src')` produces:
```
{
components: {
foo: (exported value for foo.js),
bar: (exported value for bar.js),
fooBar: (exported value for foo-bar.js)
}
}
```## Architecture
<%- await lib.renderModuleDiagram() %>