auto-barrel-sync
v1.0.9
Published
This module helps you to create barrel files for your application
Downloads
13
Maintainers
Readme
Auto Barrel Sync
Description
auto-barrel-sync is a Node.js module that simplifies the process of auto-generating a barrel file for your project. A barrel file is used to consolidate and export multiple modules from different folders, making it easier to import them in other parts of your application.
Installation
You can install auto-barrel-sync using npm:
npm install auto-barrel-sync
Usage
To use auto-barrel-sync in your Node.js project, follow these steps:
1 - Create your desired folder structure inside src.
Example:
- src
- controllers
- services
- utils
2 - Inside each folder, create your modules.
Example:
- src
- utils
- calculatorUtil.js
- utils
3 - Inside calculatorUtil.js create your functions and export as an object with a name.
Example:
const sum = (a, b) => a + b;
const subtract = (a, b) => a - b;
module.exports = {
name: 'CalculatorUtil',
sum,
subtract
}
4 - Import the package where you want to use the modules:
const Barrels = require('auto-barrel-sync');
The barrel object will contain the exported modules from your specified folders such as CalculatorUtil.
So, you can also use as:
const { Utils } = require('auto-barrel-sync');
const { CalculatorUtil } = Utils;
CalculatorUtil.sum(10, 20);
CalculatorUtil.subtract(20, 30);
Notice that the the auto-barrel-sync use the name you added when you create an object to export your functions.
See more examples of usage bellow:
const { Services, Controllers } = Barrels;
const { UserService, AuthService } = Services;
const { UserController, AuthController } = Controllers;
Configuration
By default, auto-barrel-sync looks for folders in the src directory. At the moment you cannot customize.
License
This project is licensed under the ISC License.
Contributing
Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or create a pull request on the GitHub repository.
Acknowledgments
Node.js: The JavaScript runtime used to build this package.