Skip to content

thekoushik/safe-merge-files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

safe-merge-files

npm version issues contributors

Merge two files like git

Install

npm install safe-merge-files

API

safeMergeFiles(oldFile, newFile[, options][, callback])

Content of oldFile and newFile will be merged and written into newFile. If conflict occurs, it will create git like merge conflict result which should be resolved manually. To resolve conflict automatically, use force option.

  • oldFile <string> Old filename
  • newFile <string> New filename
  • options <object>
    • outputFile <string> Defaults to null. If specified, the merged output will be written in outputFile instead of newFile
    • force <boolean> Defaults to false. If set to true, conflicts will be resolved by prefering new changes.
  • callback <Function>
    • Error <Error> Emitted when an error occurs.
    • Change Flag <Integer> 0 = no change, 1 = no conflict, -1 = conflict

safeMergeFiles.Sync(oldFile, newFile[, options])

Content of oldFile and newFile will be merged and written into newFile. If conflict occurs, it will create git like merge conflict result which should be resolved manually. To resolve conflict automatically, use force option.

Usage

Simple

var safeMergeFiles = require('safe-merge-files');

safeMergeFiles('before-change.txt', 'after-change.txt',function(err,change){
	if(change==0) console.log('No change');
	else if(change==1) console.log('Modified');
	else console.log('Conflict - please resolve it mannually');
})

Force Apply Incoming Changes

var safeMergeFiles = require('safe-merge-files');

safeMergeFiles('before-change.txt', 'after-change.txt',{
	force: true
},function(err,change){
	if(change==0) console.log('No change');
	else if(change==1) console.log('Modified');
	else console.log('Conflict - resolved');
})

Sync

var safeMergeFiles = require('safe-merge-files');

var stream= safeMergeFiles.Sync(fs.createReadStream("old_file"), fs.createReadStream("new_file"), {
 stream:true
});
var output=fs.createWriteStream("output_file");
stream.pipe(output);

Run Test

npm test

Releases

No releases published

Packages

No packages published