Skip to content

Instantly share code, notes, and snippets.

@monolithed
Created January 9, 2015 16:04
Show Gist options
  • Save monolithed/f8e50d6f5cbffd980f2c to your computer and use it in GitHub Desktop.
Save monolithed/f8e50d6f5cbffd980f2c to your computer and use it in GitHub Desktop.
grunt-copy-sync.js
/**
* 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