auto-index-file
Index.js file without your tears 😉
Last updated 6 months ago by mbalabash .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install auto-index-file -g
SYNC missed versions from official npm registry.

AutoIndexFile

Install

npm i -D auto-index-file

or

yarn add -D auto-index-file

Features

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.

Usage

CLI arguments:

-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

Motivation

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
...
import Text from 'components/atoms/Text'
import Icon from 'components/atoms/Icon'
import Block from 'components/atoms/Block'
import Button from 'components/molecules/Button'
import Modal from 'components/organisms/Modal'
import Link, { Anchor } from 'components/molecules/Link'
...

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.

As result:

src
  components
    atoms
    molecules
    organisms
    index.js
...
import {
    Text, Icon, Block, Button, Modal, Link, Anchor
} from 'components'
...

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 resolving

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

Restrictions

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)
  ...

See examples: here or here

Support

Feel free to ask or open an issue

Licence

MIT

Current Tags

  • 0.1.10                                ...           latest (6 months ago)

6 Versions

  • 0.1.10                                ...           6 months ago
  • 0.1.9                                ...           a year ago
  • 0.1.8                                ...           a year ago
  • 0.1.7                                ...           a year ago
  • 0.1.6                                ...           a year ago
  • 0.1.5                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 6
Dependencies (4)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |