# base-fs-conflicts [![NPM version](https://img.shields.io/npm/v/base-fs-conflicts.svg?style=flat)](https://www.npmjs.com/package/base-fs-conflicts) [![NPM downloads](https://img.shields.io/npm/dm/base-fs-conflicts.svg?style=flat)](https://npmjs.org/package/base-fs-conflicts) [![Build Status](https://img.shields.io/travis/node-base/base-fs-conflicts.svg?style=flat)](https://travis-ci.org/node-base/base-fs-conflicts)

Detect potential file system conflicts and if necessary prompt the user before overwriting files.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save base-fs-conflicts
```

## Attribution

Some of the logic in this plugin, in particular [lib/diffs.js](./lib/diffs.js), is based on the conflicter code in [yeoman-generator](http://yeoman.io), Copyright (c) 2015, Google, licensed under [BSD-2-Clause](http://yeoman.io/learning/faq.html#license).

## Usage

The following code should work with any [base](https://github.com/node-base/base) application, including [verb](https://github.com/verbose/verb), [assemble](https://github.com/assemble/assemble), and [generate](https://github.com/generate/generate).

```js
var path = require('path');
var Base = require('base');
var fs = require('base-fs');
var conflicts = require('base-fs-conflicts');
var base = new Base();

// register the `conflicts` and `fs` plugins
base.use(conflicts());
base.use(fs());

// pass the same `dest` to both `.dest()` and `.conflicts()`
var dest = 'fixtures/dist';

base.src('fixtures/*.txt')
  .pipe(base.conflicts(dest)) // adds a `.conflicts()` method
  .pipe(base.dest(dest));
```

**Example**

If a file conflict is detected, you'll see something like this in the terminal:

<img width="570" alt="screen shot 2016-03-17 at 8 05 53 pm" src="https://cloud.githubusercontent.com/assets/383994/13864890/d9f67420-ec7b-11e5-973d-47462989d773.png">

## API

1. The existing file's contents is compared with `file.contents` on the vinyl file
2. If the contents of both are identical, no action is taken
3. If the contents differ, the user is prompted for action
4. If no conflicting file exists, the vinyl file is written to the file system

**Params**

* `dest` **{String}**: The same desination directory passed to `app.dest()`
* `returns` **{String}**

**Example**

```js
app.src('foo/*.js')
  .pipe(app.conflicts('foo'))
  .pipe(app.dest('foo'));
```

## Related projects

You might also be interested in these projects:

* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit")
* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate "Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.")
* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.")
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.")

## Contributing

This document was generated by [verb-readme-generator](https://github.com/verbose/verb-readme-generator) (a [verb](https://github.com/verbose/verb) generator), please don't edit directly. Any changes to the readme must be made in [.verb.md](.verb.md). See [Building Docs](#building-docs).

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). Or visit the [verb-readme-generator](https://github.com/verbose/verb-readme-generator) project to submit bug reports or pull requests for the readme layout template.

## Building docs

Generate readme and API documentation with [verb](https://github.com/verbose/verb):

```sh
$ npm install -g verb verb-readme-generator && verb
```

## Running tests

Install dev dependencies:

```sh
$ npm install -d && npm test
```

## Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License

Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/node-base/base-fs-conflicts/blob/master/LICENSE).

***

_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on July 26, 2016._