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 or rollup) to extend the entry property.

Installation

Install it with npm:

$ npm install cattleman --save-dev

Usage

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

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:

defaults = { directory : ' src ' , excludes : [ ' test ' ] }

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:

src/ └─ modules/ ├─ footer/ │ ├─ footer.css │ ├─ footer.html │ └─ footer.js ├─ header/ │ ├─ header.css │ ├─ header.html │ └─ header.js └─ ...

Imagine there are 20 - 30 modules more.

const cattleman = new Cattleman ( ' src/modules ' ) const files = cattleman . gatherFiles ( ) [ ' 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 ' ) [ ' 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 and is licensed under MIT.