Skip to content

Latest commit

 

History

History
94 lines (65 loc) · 2 KB

README-TEMPLATE.md

File metadata and controls

94 lines (65 loc) · 2 KB

<%- 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 <targetDir> [<targetDir>...] [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:

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:

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() %>