npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

auto-index-file

v0.1.10

Published

Index.js file without your tears 😉

Downloads

10

Readme

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