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 = let config = entry: bundle: 'src/bundle.js' 'src/bundle.css' output: filename: 'modules/[name].js' path: __dirname + '/dist' module: rules: ... plugins: ... const cattleman = 'src/modules'const entries = cattleman configentry = Object moduleexports = config
Options
You can init a cattleman instance without options. These are the defaults:
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:
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 = 'src/modules' const files = cattleman// 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// now jsFiles whould look like this 'src/modules/footer/footer.js' 'src/modules/header/header.js' ... configentry = bundle: jsFiles moduleexports = config
License
This library was written by Christopher Voigt and is licensed under MIT.