Skip to content

Detects when a new file is different than an existing file and prompts the user for action.

License

Notifications You must be signed in to change notification settings

jonschlinkert/conflicts

Repository files navigation

conflicts NPM version NPM monthly downloads NPM total downloads Linux Build Status

Detects when a new file is different than an existing file and prompts the user for action.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save conflicts

Usage

const Conflicts = require('conflicts');
const conflicts = new Conflicts();

API

Create an instance of Conflicts with the given options and optional Vinyl constructor.

Params

  • options {Object}
  • File {Function}: Optionally pass a vinyl contructor, otherwise the default File class is used.
  • returns {Conflicts}: Returns an instance of Conflicts.

Example

const Conflicts = require('conflicts');
const conflicts = new Conflicts({}, require('vinyl'));

Compares an existing (old) file to a new proposed file, then prompts for an action if the files are not equal. If the contents of both files is identical, no action is taken, otherwise you will be prompted to choose the action to take. See the unit tests for examples of how to skip prompts.

Params

  • proposedFile {Object}: New file.
  • existingFile {Object}: Existing file.
  • options {Object}
  • returns {Promise}: Returns a promise with the action that was taken.

Example

conflicts.detect(fileA, fileB)
  .then(action => console.log('Action taken:', action))
  .catch(console.error)

Same as .detect, except the second argument is a string to an existing file on the file system.

Params

  • proposed {Object}: New file.
  • existingPath {Object}: File path to existing file.
  • options {Object}
  • returns {Promise}: Returns a promise with the action that was taken.

Example

conflicts.detectFile(file, 'path/to/file.txt')
  .then(action => console.log('Action taken:', action))
  .catch(console.error)

Runs detect on an array of "proposed" files.

Params

  • files {Array}: Array of file objects.
  • options {Object}
  • returns {Array}

    Example

    conflicts.files([fileA, fileB, fileC])
      .then(action => console.log('Action taken:', action))
      .catch(console.error)

    Takes an array of "proposed" files, and returns an array of strings, where each string represents a diff of the proposed file's contents versus an existing file's contents.

    Params

    • files {Array}
    • options {Object}
    • returns {Array}

    Example

    conflicts.diffFiles([fileA, fileB, fileC])
      .then(diffs => {
        diffs.forEach(diff => console.log(diff));
      })
      .catch(console.error)

    Returns true if an fileA (existing/old) file appears to be identical to a fileB (proposed/new) file.

    Params

    • proposed {Object}: vinyl file representing a proposed (new) file
    • existing {Object}: vinyl file representing an existing (old) file
    • options {Object}
    • returns {Boolean}

    Example

    console.log(conflicts.isEqual(fileA, fileB));

    About

    Contributing

    Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

    Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

    Running Tests

    Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

    $ npm install && npm test
    Building docs

    (This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

    To generate the readme, run the following command:

    $ npm install -g verbose/verb#dev verb-generate-readme && verb

    Author

    Jon Schlinkert

    License

    Copyright © 2018, Jon Schlinkert. Released under the MIT License.


    This file was generated by verb-generate-readme, v0.8.0, on December 08, 2018.