Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dsherret/barrel-maintainer
Automated real-time maintenance of barrels in JavaScript and TypeScript.
https://github.com/dsherret/barrel-maintainer
automation code-manipulation typescript
Last synced: 3 months ago
JSON representation
Automated real-time maintenance of barrels in JavaScript and TypeScript.
- Host: GitHub
- URL: https://github.com/dsherret/barrel-maintainer
- Owner: dsherret
- License: mit
- Archived: true
- Created: 2017-12-27T02:20:45.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-17T20:58:21.000Z (over 4 years ago)
- Last Synced: 2024-07-12T18:18:36.610Z (4 months ago)
- Topics: automation, code-manipulation, typescript
- Language: TypeScript
- Homepage:
- Size: 2.04 MB
- Stars: 19
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Barrel Maintainer
[![npm version](https://badge.fury.io/js/barrel-maintainer.svg)](https://badge.fury.io/js/barrel-maintainer)
Automatically maintains [barrels](https://basarat.gitbooks.io/typescript/docs/tips/barrel.html) in real-time.
[![Automated real-time barrel maintenance](https://github.com/dsherret/barrel-maintainer/raw/master/demo.gif)](https://youtu.be/gFi7kQnD69k)
[Video Overview](https://youtu.be/gFi7kQnD69k)
## Installation
```bash
npm install -g barrel-maintainer
```## Usage
```bash
barrel-maintainer [options] [path]
```Options:
- `--includeRootDir` - Create a barrel in the root directory.
- Quote type (specify one)
- Defaults to the quote type used in the first found import declaration in your project.
- `--singleQuotes` - Use single quotes.
- `--doubleQuotes` - Use double quotes.
- File extension for barrel (specify one)
- Defaults to whichever file type your project has more of.
- `--ts` - Create index.ts files.
- `--js` - Create index.js files.
- New lines (specify one)
- `--crlf` - Use carriage return line feed newlines (default on windows)
- `--lf` - Use line feed newlines (default elsewhere)## Ignoring Files
Add a `/* barrel:ignore */` statement to the file:
```ts
/* barrel:ignore */
export function log(message: string) {
console.log(message);
}
```## Exporting a Subset of a File's Exports
Given the following setup:
```js
// classes.js
export ClassA {}
export ClassB {}// index.js
export * from "./classes";
```If you want the barrel to export a subset of the exports from _classes.js_, then edit the barrel to say so:
```js
// index.js
export { ClassA } from "./classes";
```These kind of changes won't be overwritten by the code manipulation.
## Api
```ts
import BarrelMaintainer from "barrel-maintainer";const maintainer = new BarrelMaintainer("myProject/src/", {
includeRootDir: false,
fileExtension: "js", // or "ts" (extension for barrel)
quoteType: "'", // or "\""
newLineType: "\r\n", // or "\n"
});await maintainer.updateDirectory("myProject/src/subdir");
const watcher = maintainer.watchDirectory("myProject/src");// then later (if necessary)
watcher.stop();
```## About
This project uses [ts-morph](https://github.com/dsherret/ts-morph) to navigate and manipulate source code.
## Disclaimer
This library will modify and delete source code. I am not responsible for any of its modifications or deletions!
Always use version control to verify and to be able to easily revert the changes it makes!