3.0.1 • Published 5 years ago

cattleman v3.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

Cattleman

Build Status Coverage Status Dependency Status CodeFactor

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',    // 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 = 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 and is licensed under MIT.

3.0.1

5 years ago

3.0.0

6 years ago

2.0.2

7 years ago

1.4.0

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago