# cattleman

> a helper library that gathers files and entry points

Latest version **3.0.1** (published 2019-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install cattleman
pnpm add cattleman
yarn add cattleman
bun add cattleman
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2019-01-08 |
| First published | 2017-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Christopher Voigt |
| Maintainers | chlorophyllkid |
| Keywords | multiple, file, entry, bundle, modular, helper, library |

## Links

- npm: https://www.npmjs.com/package/cattleman
- Repository: https://github.com/chlorophyllkid/cattleman
- Homepage: https://github.com/chlorophyllkid/cattleman#readme
- Issues: https://github.com/chlorophyllkid/cattleman/issues
- npm.io page: https://npm.io/package/cattleman

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 3.0.1 (latest) — 2019-01-08
- 3.0.0 — 2018-05-17
- 2.0.2 — 2017-07-29
- 1.4.0 — 2017-07-23
- 1.3.3 — 2017-07-23
- 1.3.2 — 2017-07-23
- 1.3.1 — 2017-07-22
- 1.3.0 — 2017-07-22
- 1.2.2 — 2017-07-20
- 1.2.1 — 2017-07-14
- 1.2.0 — 2017-07-11
- 1.1.0 — 2017-07-11
- 1.0.1 — 2017-07-09
- 1.0.0 — 2017-07-09

## README

# Cattleman
[![Build Status](https://travis-ci.org/chlorophyllkid/cattleman.svg?branch=master)](https://travis-ci.org/chlorophyllkid/cattleman)
[![Coverage Status](https://coveralls.io/repos/github/chlorophyllkid/cattleman/badge.svg?branch=master)](https://coveralls.io/github/chlorophyllkid/cattleman?branch=master)
[![Dependency Status](https://david-dm.org/chlorophyllkid/cattleman.svg)](https://david-dm.org/chlorophyllkid/cattleman)
[![CodeFactor](https://www.codefactor.io/repository/github/chlorophyllkid/cattleman/badge)](https://www.codefactor.io/repository/github/chlorophyllkid/cattleman)

Cattleman is a small helper library. It parses a given directory and gathers files and entry objects.
These objects can be used in bundler configurations (e.g. [webpack](https://github.com/webpack/webpack) or [rollup](https://github.com/rollup/rollup)) to extend the entry property.


## Installation
Install it with npm:
```shell
$ npm install cattleman --save-dev
```


## Usage
Require it for example in your `webpack.config.js` like:

```javascript
const Cattleman = require('cattleman')

let config = {
    entry: {
        bundle: [ 'src/bundle.js', 'src/bundle.css' ]
    },
    output: {
        filename: 'modules/[name].js',
        path: __dirname + '/dist'
    },
    module: {
        rules: [ ... ]
    },
    plugins: [ ... ]
}

const cattleman = new Cattleman('src/modules')
const entries = cattleman.gatherEntries()

config.entry = Object.assign({}, config.entry, entries)

module.exports = config

```


## Options
You can init a cattleman instance without options. These are the defaults:
```javascript
defaults = {
    directory:   'src',    // search directory
    excludes:  [ 'test' ]  // filepaths, which include a string listed here, are ignored
}
```
If you just pass a string to the constructor, cattleman interprets it as the directory.


## Methods
* **gatherFiles( extentionFilter )** - returns the list of files in the search directory

[optional] *extentionFilter* - (string | array) - valid file type(s) (e.g. `'.js'` or `['.js', '.css']`)

**Warning**: If extentionFilter equals an empty array, no extention is valid.


## Example
Let's say you got a `src/` folder in your projects directory containing the code of your site:
```bash
src/
└─ modules/
  ├─ footer/
  │ ├─ footer.css
  │ ├─ footer.html
  │ └─ footer.js
  ├─ header/
  │ ├─ header.css
  │ ├─ header.html
  │ └─ header.js
  └─ ...
```
Imagine there are 20 - 30 modules more.


```javascript
const cattleman = new Cattleman('src/modules')

const files = cattleman.gatherFiles()
// now files whould look like this
[
    'src/modules/footer/footer.css',
    'src/modules/footer/footer.html',
    'src/modules/footer/footer.js',
    'src/modules/header/header.css',
    'src/modules/header/header.html',
    'src/modules/header/header.js',
    ...
]

const jsFiles = cattleman.gatherFiles('.js')
// now jsFiles whould look like this
[
    'src/modules/footer/footer.js',
    'src/modules/header/header.js',
    ...
]

config.entry = {
    bundle: jsFiles
}

module.exports = config
```


## License
This library was written by [Christopher Voigt](https://twitter.com/chlorophyllkid) and is licensed under [MIT](https://github.com/chlorophyllkid/cattleman/blob/master/LICENSE).

---
_Source: https://npm.io/package/cattleman · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
