# Files Generator

![draft](https://img.shields.io/badge/stability-draft-lightgrey.svg?style=flat-square)

![Branch : release](https://img.shields.io/badge/Branch-release-blue.svg)
[![version](https://img.shields.io/badge/version-0.5.0-blue.svg)](https://github.com/AlexisTessier/files-generator#readme)
[![npm version](https://badge.fury.io/js/files-generator.svg)](https://badge.fury.io/js/files-generator)

[![Build Status](https://travis-ci.org/AlexisTessier/files-generator.svg?branch=release)](https://travis-ci.org/AlexisTessier/files-generator)
[![Coverage Status](https://coveralls.io/repos/AlexisTessier/files-generator/badge.svg?branch=release&service=github)](https://coveralls.io/github/AlexisTessier/files-generator?branch=release)

[![Dependency Status](https://david-dm.org/AlexisTessier/files-generator.svg)](https://david-dm.org/AlexisTessier/files-generator)
[![devDependency Status](https://david-dm.org/AlexisTessier/files-generator/dev-status.svg)](https://david-dm.org/AlexisTessier/files-generator#info=devDependencies)

A tool to generate bunch of files, using different kinds of content definition and sources

-   [Install](#install)
-   [Basic usage](#basic-usage)
-   [Documentation](#documentation)
-   [License](#license)

## Install

    npm i files-generator

## Basic usage

```javascript
const generate = require('files-generator')();

generate({
  'path/to/file': 'file content',
  'path/to/file2': generate.use('other file content')
});
generate.on('finish', event => {
  console.log(event.success); // ["path/to/file", "path/to/file2"]
})
```

## Documentation

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### generateGenerate

Create a generate function using the defined options

**Parameters**

-   `options` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** An object containing the generate function options. (optional, default `{}`)
    -   `options.eventData` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Each time that generate will emit an event, the event handler will receive as first argument an event object with a data key containing this eventData option. (optional, default `undefined`)
    -   `options.writeFile` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** The function which will be used to create files and/or directories. (optional, default `defaultWriteFile`)
    -   `options.encoding` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The encoding to use when writing files. (optional, default `'utf-8'`)
    -   `options.cwd` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The cwd used if you try to generate some relative paths. Must be an absolute path. (optional, default `process.cwd()`)

Returns **[generate](#generate)** A generate function which uses by default the options provided as generateGenerate parameters

### generate

Generate files from different kinds of inputs

**Parameters**

-   `generateConfig` **GenerateConfig** The generate config contains all the file paths to generate.
-   `options` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** This options object can be used to overide some options defined in the generateGenerate function. (optional, default `{}`)
    -   `options.eventData`   (optional, default `_eventData`)
    -   `options.writeFile`   (optional, default `_writeFile`)
    -   `options.encoding`   (optional, default `_encoding`)
    -   `options.cwd`   (optional, default `_cwd`)

Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)** 

## License

files-generator is released under [MIT](http://opensource.org/licenses/MIT). 
Copyright (c) 2017-present [Alexis Tessier](https://github.com/AlexisTessier)
