Skip to content

petrzjunior/barrelgun

Repository files navigation

barrelgun

Generate your barrel files like a cowboy 🤠

npm version MIT license GitHub code size in bytes npm

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

About

Node.js barrel generator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published