barrelgun
TypeScript icon, indicating that this package has built-in type declarations

1.3.0Β β€’Β PublicΒ β€’Β Published

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

Package Sidebar

Install

npm i barrelgun

Weekly Downloads

47

Version

1.3.0

License

MIT

Unpacked Size

15.9 kB

Total Files

8

Last publish

Collaborators

  • petrzjunior