grunt-sync
Advanced tools
Comparing version 0.2.4 to 0.3.0
{ | ||
"name": "grunt-sync", | ||
"description": "Task to synchronize two directories. Similar to grunt-copy but updates only files that have been changed.", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/tomusdrw/grunt-sync.git", | ||
@@ -36,2 +36,3 @@ "author": { | ||
"lodash": "^2.4.1", | ||
"md5-file": "^2.0.3", | ||
"promised-io": "0.3.3" | ||
@@ -38,0 +39,0 @@ }, |
@@ -51,3 +51,4 @@ # Grunt-sync | ||
ignoreInDest: "**/*.js", // Never remove js files from destination. Default: none | ||
updateAndDelete: true // Remove all files from dest that are not found in src. Default: false | ||
updateAndDelete: true, // Remove all files from dest that are not found in src. Default: false | ||
compareUsing: "md5" // compares via md5 hash of file contents, instead of file modification time. Default: "mtime" | ||
@@ -70,3 +71,3 @@ } | ||
1. [1] Overwrite destination if modification time is newer or destination is directory not file. | ||
1. [2nd phase] Read all files in `dest` and calculate difference between files in destination and source files. | ||
1. [2nd phase] Get a list of the files in `dest` and calculate difference between destination and source. | ||
1. [2] Delete all files (and directories) that have been found in `dest` but are not found `src` excluding ignored files. | ||
@@ -76,2 +77,3 @@ | ||
## Changelog | ||
* 0.3.0 - Comparison using md5 hash of file contents or modification time | ||
* 0.2.4 - `failOnError` option | ||
@@ -86,2 +88,3 @@ * 0.2.3 - Fixed issue with files defined as array when using `updateAndDelete`. | ||
## Migration 0.1.x -> 0.2.x | ||
@@ -92,4 +95,10 @@ In version 0.2 you have to explicitly specify that you want the plugin to remove files from destination. See `updateAndDelete` option and run with `pretend:true` first to make sure that it doesn't remove any crucial files. You can tune what files should be left untouched with `ignoreInDest` property. | ||
## Contributors | ||
* Michael Mifsud ([xzyfer](https://github.com/xzyfer)) | ||
* Erwan Jegouzo ([erwanjegouzo](https://github.com/erwanjegouzo)) | ||
* Janek Lasocki-Biczysko ([janeklb](https://github.com/janeklb)) | ||
## TODO | ||
* Research if it's possible to have better integration with `grunt-contrib-watch` - update only changed files instead of scanning everything. | ||
@@ -96,0 +105,0 @@ * Some tests for common problems |
@@ -17,2 +17,3 @@ var fs = require('promised-io/fs'); | ||
var ignoredPatterns = this.data.ignoreInDest; | ||
var comparatorFactory = getComparatorFactory(this.data.compareUsing || 'mtime', logger); | ||
var expandedPaths = {}; | ||
@@ -52,3 +53,3 @@ | ||
// Process pair | ||
return processPair(justPretend, failOnError, logger, path.join(cwd, src), dest); | ||
return processPair(justPretend, failOnError, logger, comparatorFactory, path.join(cwd, src), dest); | ||
})); | ||
@@ -138,3 +139,3 @@ | ||
function processPair (justPretend, failOnError, logger, src, dest) { | ||
function processPair (justPretend, failOnError, logger, comparatorFactory, src, dest) { | ||
@@ -148,4 +149,5 @@ // stat destination file | ||
var typeDiffers = isSrcDirectory !== destStat.isDirectory(); | ||
var haventChangedFn = comparatorFactory(src, srcStat, dest, destStat); | ||
overwriteOrUpdate(isSrcDirectory, typeDiffers, srcStat, destStat); | ||
overwriteOrUpdate(isSrcDirectory, typeDiffers, haventChangedFn); | ||
}, function () { | ||
@@ -209,3 +211,3 @@ // we got an error which means that destination file does not exist | ||
function overwriteOrUpdate (isSrcDirectory, typeDiffers, srcStat, destStat) { | ||
function overwriteOrUpdate (isSrcDirectory, typeDiffers, haventChangedFn) { | ||
@@ -222,4 +224,4 @@ // If types differ we have to overwrite destination. | ||
// we can now compare modification dates of files | ||
if (isSrcDirectory || srcStat.mtime.getTime() <= destStat.mtime.getTime()) { | ||
// we can now compare the files | ||
if (isSrcDirectory || haventChangedFn()) { | ||
return; | ||
@@ -315,2 +317,30 @@ } | ||
function getComparatorFactory(compareUsing, logger) { | ||
var md5; | ||
switch (compareUsing) { | ||
case 'md5': | ||
md5 = require('md5-file'); | ||
return createMd5Comparator; | ||
case 'mtime': | ||
return createMTimeComparator; | ||
default: | ||
logger.writeln("Invalid 'compareUsing' option, falling back to default 'mtime'"); | ||
return createMTimeComparator; | ||
} | ||
function createMTimeComparator(src, srcStat, dest, destStat) { | ||
return function() { | ||
return srcStat.mtime.getTime() <= destStat.mtime.getTime(); | ||
}; | ||
} | ||
function createMd5Comparator(src, srcStat, dest, destStat) { | ||
return function() { | ||
return md5(src) == md5(dest); | ||
}; | ||
} | ||
} | ||
}; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18031
371
103
0
4
+ Addedmd5-file@^2.0.3
+ Addedmd5-file@2.0.7(transitive)