Crates.io | reexport |
lib.rs | reexport |
version | 1.0.0 |
source | src |
created_at | 2023-03-05 03:09:47.88692 |
updated_at | 2023-03-05 03:09:47.88692 |
description | Reexport js/ts files made easy with rust |
homepage | |
repository | https://github.com/ErikMedeiros/reexport |
max_upload_size | |
id | 801043 |
size | 17,381 |
A common pattern in the javascript world is a index file that reexport all other files in the same folder, an exemple can be the following file hierarchy
src/hooks
├── use-auth.ts
├── use-filter.ts
├── use-something-else.ts
└── index.ts
the index.ts content will be
export * from './use-auth';
export * from './use-filter';
export * from './use-something-else';
when you have multiple folder with multiple files, manually reexporting each is very painfull, this package comes to solve this!
consider the following folder
src/components
├── component1.js
└── component2.ts
simply pass the path to the folder
reexport src/components
and a index.ts file will be created reexporting all files on that folder!
// src/components/index.ts
export * from './component1';
export * from './component2';
you also can pass multiple paths to be reexported like
reexport src/components src/hooks
now let's take a look in a more complex file tree
src/components
├── a
│ ├── a1
│ │ ├── file2.ts
│ │ └── file.ts
│ ├── a2
│ │ └── aa1
│ │ ├── file2.js
│ │ └── file.ts
│ └── file.ts
├── b
│ ├── b1
│ │ └── file.ts
│ └── file.ts
├── c
│ └── file.ts
└── test.json
try running the command bellow
reexport src/components
it will create the file bellow
// src/components/index.ts
// test.json was ignored!
export * from './a';
export * from './b';
export * from './c';
but notice that none of the exported folder has an index.ts file, making the created file useless. But do not worry! This can be solved by passing recursive flag
passing this flag will tell reexport to create an index.ts file for each subfolder that is reexported.
reexport src/components --recursive
executing the above command will result in a file hierarchy like the bellow
src/components
├── a
│ ├── a1
│ │ ├── file2.ts
│ │ ├── file.ts
│ │ └── index.ts
│ ├── a2
│ │ ├── aa1
│ │ │ ├── file2.js
│ │ │ ├── file.ts
│ │ │ └── index.ts
│ │ └── index.ts
│ ├── file.ts
│ └── index.ts
├── b
│ ├── b1
│ │ ├── file.ts
│ │ └── index.ts
│ ├── file.ts
│ └── index.ts
├── c
│ ├── file.ts
│ └── index.ts
├── index.ts
└── test.json
If you find this explanation confunsing or have some feature to be implemented, contact me or do a pull request (i don't know how this works)