Conflicter(adapter, options, cwd)

The Conflicter is a module that can be used to detect conflict between files. Each Generator file system helpers pass files through this module to make sure they don't break a user file.

When a potential conflict is detected, we prompt the user and ask them for confirmation before proceeding with the actual write.

new Conflicter(adapter, options, cwd)

Parameters:
Name Type Description
adapter TerminalAdapter

The generator adapter

options Object

Conflicter options

Properties
Name Type Attributes Default Description
force Boolean <optional>
false

When set to true, we won't check for conflict. (the conflicter become a passthrough)

bail Boolean <optional>
false

When set to true, we will abort on first conflict. (used for testing reproducibility)

ignoreWhitespace Boolean <optional>
false

When set to true, whitespace changes should not generate a conflict.

regenerate Boolean <optional>
false

When set to true, identical files should be written to disc.

dryRun Boolean <optional>
false

When set to true, no write operation will be executed.

cwd Boolean <optional>
process.cwd()

Path to be used as reference for relative path.

cwd string

Set cwd for relative logs.

Properties:
Name Type Description
force Boolean

same as the constructor argument

Methods

_detectConflict(file) → {Boolean}

Detect conflicts between file contents at filepath with the contents passed to the function

If filepath points to a folder, we'll always return true.

Based on detect-conflict module

Parameters:
Name Type Description
file Object

File object respecting this interface: { path, contents }

Returns:
Boolean -

true if there's a conflict, false otherwise.

_printDiff(file)

Print the file differences to console

Parameters:
Name Type Description
file Object

File object respecting this interface: { path, contents }

checkForCollision(file) → {Promise}

Check if a file conflict with the current version on the user disk

A basic check is done to see if the file exists, if it does:

  1. Read its content from fs
  2. Compare it with the provided content
  3. If identical, mark it as is and skip the check
  4. If diverged, prepare and show up the file collision menu
Parameters:
Name Type Description
file Object

Vinyl file

Returns:
Promise -

Promise a status string ('identical', 'create', 'skip', 'force')