barrelgun
v1.3.0
Published
Generate your barrel files like a cowboy 🤠
Downloads
579
Maintainers
Readme
barrelgun
Generate your barrel files like a cowboy 🤠
Flexible NodeJS generator for barrel files (index.js) and more!
Usage
Create a config file barrelgun.config.js
/** @type {Array<import("barrelgun").BarrelgunConfigBarrel>} */
const barrels = [
{
path: "src/components/index.ts",
files: "*.component.{ts,tsx}",
},
{
path: "test/tests.spec.js",
files: "**/*.spec.js",
lineTemplate: (file) => `export {${file.replace(/[/.]/, '_')} from '${file}';`,
fileTemplate: (files, lineTemplate: LineTemplate) =>
`// Do not touch of you will be fired!
${files.reverse().map(file => lineTemplate(file))}
// You have been warned!`,
},
];
module.exports = {barrels};
and run barrelgun
npx barrelgun shoot -c barrelgun.config.js
The following structure will be created
.
├── barrelgun.config.js
├── src
│ └── components
│ ├── button.component.tsx
│ ├── dialog.component.ts
│ └── index.js <- this file is created
└── test
├── ignore.js
├── all.spec.js
├── components
│ └── button.spec.js
└── tests.spec.js <- this file is created
src/components/index.js
now contains
// Generated by barrelgun. DO NOT EDIT
export * from './button.component.tsx';
export * from './dialog.component.ts';
src/components/index.js
content is
// Do not touch of you will be fired!
export {components_button_spec_js} from './components/button.spec.js';
export {all_spec_js} from './all.spec.js';
// You have been warned!
Features
- Import files recursively with globs
- Create all barrels at once with globs
- Custom templates
- Sort lines
- Ignore empty files
Related projects
Inspired by
- https://github.com/jmeyers91/barro
- https://github.com/imjuni/ctix
- https://github.com/bencoveney/barrelsby