Skip to content

Commit

Permalink
add timestamp option
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyelee committed Oct 15, 2014
1 parent cbc82a6 commit ef5e472
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
7 changes: 4 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ module.exports = function(grunt) {

mode: {
options: {
mode: '0444',
mode: '0444'
},
src: ['test/fixtures/test2.js'],
dest: 'tmp/mode.js',
dest: 'tmp/mode.js'
},
process: {
options: {
Expand All @@ -89,7 +89,8 @@ module.exports = function(grunt) {
} else {
return content;
}
}
},
timestamp: true
},
files: [
{expand: true, cwd: 'test/fixtures/time_folder/', src: ['**'], dest: 'tmp/copy_test_timestamp/'},
Expand Down
6 changes: 6 additions & 0 deletions docs/copy-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ Type: `Boolean` or `Number`
Default: `false`

Whether to copy or set the existing file permissions. Set to `true` to copy the existing file permissions. Or set to the mode, i.e.: `0644`, that copied files will be set to.

## timestamp
Type: `Boolean`
Default: `false`

Whether to preserve the timestamp attributes(`atime` and `mtime`) when copying files. Set to `true` to preserve files timestamp. But timestamp will *not* be preserved when the file contents or name are changed during copying.
20 changes: 11 additions & 9 deletions tasks/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = function(grunt) {
// processContent/processContentExclude deprecated renamed to process/noProcess
processContent: false,
processContentExclude: [],
timestamp: false,
mode: false
});

Expand Down Expand Up @@ -53,10 +54,9 @@ module.exports = function(grunt) {
grunt.verbose.writeln('Creating ' + chalk.cyan(dest));
grunt.file.mkdir(dest);

dirs[dest] = {
src: src,
dest: dest
};
if (options.timestamp) {
dirs[dest] = src;
}

tally.dirs++;
} else {
Expand All @@ -71,11 +71,13 @@ module.exports = function(grunt) {
});
});

Object.keys(dirs).sort(function (a, b) {
return b.length - a.length;
}).forEach(function (dest) {
syncTimestamp(dirs[dest].src, dest);
});
if (options.timestamp) {
Object.keys(dirs).sort(function (a, b) {
return b.length - a.length;
}).forEach(function (dest) {
syncTimestamp(dirs[dest], dest);
});
}

if (tally.dirs) {
grunt.log.write('Created ' + chalk.cyan(tally.dirs.toString()) + ' directories');
Expand Down

0 comments on commit ef5e472

Please sign in to comment.