Created
January 9, 2015 16:04
-
-
Save monolithed/f8e50d6f5cbffd980f2c to your computer and use it in GitHub Desktop.
grunt-copy-sync.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* utils/sync | |
*/ | |
'use strict'; | |
var fs = require('fs'), | |
grunt = require('grunt'), | |
path = require('path'); | |
var Sync = function (target) { | |
this.target = target || []; | |
}; | |
Sync.prototype = { | |
constructor: Sync, | |
time: function (file) { | |
return fs.statSync(file).mtime.getTime(); | |
}, | |
path: function (path) { | |
var target = this.target.concat(path); | |
return grunt.config(target); | |
}, | |
files: function (src) { | |
var dest = this.path('dest'), | |
cwd = this.path('cwd'); | |
dest = path.join(dest, cwd ? path.relative(cwd, src) : src); | |
try { | |
return this.time(src) > this.time(dest); | |
} | |
catch (error) { | |
grunt.log.errorlns('Sync files:', error); | |
return true; | |
} | |
} | |
}; | |
module.exports = Sync; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment