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

@droppedcode/index-generator

v1.0.4

Published

Create index files from a folder.

Downloads

5,019

Readme

Index file generator

Create index files from a folder.

The tool will collect all files with exports (recursively) and creates an export from these in the format:

export * from './file-1';
export * from './dir-1/file-1';
export * from './dir-1/file-2';

Only files with export-s will be added to the list (files containing any rows that starts with the export word).

Usage

igen [--exclude ...]

e.g. igen ./src ./src/index.ts --exclude (\.spec|\.test)\.ts$ ^docs\.ts$

This will create the index file "src/index.ts" for all files in the "src" folder except all files that ends with ".spec.ts" or ".test.ts" and the file "src/docs.ts".

Command line arguments

Path to the folder: the path that will be processed. Path to the created file: the path of the file that will be created.

Options

--path/-p (string, first argument by default): Specify a root folder to use. With this option (used multiple times or listing the folder after each other), you can specify multiple entry points.

--out/-o (string, second argument by default): Specify the output file name and path (relative to root) or the name of the output files (see modes).

--config/-c (string): Read a json file as the config.

--mode/-m (string): Set the generator mode:

  • path (this is the default): Put the output file to the path defined, if not absolute then relative to the cwd.
  • root: Put the output file into the root folder(s).
  • folder: File per folder, including sub folder files from the individual files.
  • sub: File per folder, including all sub folder index files, ignoring the individual files.

--include/-i (string): include files by regex. The regex will be matched against the relative path from the root of the processed folder. You can list any number of regex after the option or use it multiple times, e.g. -e regex1 regex2. Defaults to [/\.ts$/].

--exclude/-e (string): exclude files by regex. The regex will be matched against the relative path from the root of the processed folder. You can list any number of regex after the option or use it multiple times, e.g. -e regex1 regex2.

--eol/-l (string): The line ending used. Possible values: 'os' (the current operating system line ending), 'unix', 'lf', 'n' (use the unix line ending \n), 'win', 'crlf', 'rn' (use the windows line ending \r\n), 'r' (\r), anything else (you can define anything else). Defaults to 'os'.

--eol-at-eof (boolean): Should an empty line added at the end of the file (defaults to true).

--header/-h (string): Set the header text at the beginning of the generated file. Defaults to:

This file was generated by a tool.
Do not modify it.

--header-mode (string): Set how the header should be generated, defaults to multi:

  • 'disabled': Do not add the header.
  • 'raw': Add the header as is.
  • 'single': Write each line as a single line comment // header.
  • 'multi': Write the header as a multiline comment, surrounded with /* */, each line stating with a *.

--if-needed/-n (boolean): Should files without exports generated.

--format/-f (string): The format the export should be generated. Default to: export * from '{rel}/{name}'; You can use the following variables:

  • {name}: The name of the file.
  • {ext}: The extension of the file.
  • {rel}: The relative path of the directory.
  • {abs}: The absolute path of the directory.

From code

From code you can use it by importing the IndexGenerator class from the package.

import { IndexGenerator, Options } from '@droppedcode/index-generator';

Ignore files

You can ignore files with adding "// index-generator-ignore" comment to the file (anywhere).

Modes

The different modes generate the following for this input:

src
|- f0
 |- f1
  |- b.ts
 |- c.ts
|- a.ts

path

Put the output file to the path defined (with path ./src and no out defined), if not absolute then relative to the cwd (this is the default).

The generated file will not compile because the paths are not valid. You always should define the output path for the generated file (e.g. ./src/index.ts) or modify the format to contain the needed path.

src
|- f0
 |- f1
  |- b.ts
 |- c.ts
|- a.ts
index.ts
  export * from './f0/f1/b.ts';
  export * from './f0/c.ts';
  export * from './a.ts';

root

Put the output file into the root folder(s).

src
|- f0
 |- f1
  |- b.ts
 |- c.ts
|- a.ts
|- index.ts
     export * from './f0/f1/b';
     export * from './f0/c';
     export * from './a';

folder

File per folder, including sub folder files from the individual files.

src
|- f0
 |- f1
  |- b.ts
  |- index.ts
       export * from './b';
 |- c.ts
 |- index.ts
      export * from './f1/b';
      export * from './c';
|- a.ts
|- index.ts
     export * from './f0/f1/b';
     export * from './f0/c';
     export * from './a';

sub

File per folder, including all sub folder index files, ignoring the individual files.

src
|- f0
 |- f1
  |- b.ts
  |- index.ts
       export * from './b';
 |- c.ts
 |- index.ts
      export * from './f1/index';
      export * from './c';
|- a.ts
|- index.ts
     export * from './f0/index';
     export * from './a';