Skip to content

Commit 369a0c8

Browse files
author
Dean Sofer
committed
Added options.copy (Fixes yeoman#20)
1 parent 801cb60 commit 369a0c8

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

tasks/filerev.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ module.exports = function (grunt) {
1010
var options = this.options({
1111
encoding: 'utf8',
1212
algorithm: 'md5',
13-
length: 8
13+
length: 8,
14+
copy: null
1415
});
1516
var target = this.target;
1617
var filerev = grunt.filerev || {summary: {}};
1718

1819
eachAsync(this.files, function (el, i, next) {
19-
var move = true;
20-
20+
2121
// If dest is furnished it should indicate a directory
2222
if (el.dest) {
2323
// When globbing is used, el.dest contains basename, we remove it
@@ -34,8 +34,6 @@ module.exports = function (grunt) {
3434
grunt.log.writeln('Destination dir ' + el.dest + ' does not exists for target ' + target + ': creating');
3535
grunt.file.mkdir(el.dest);
3636
}
37-
// We need to copy file as we now have a dest different from the src
38-
move = false;
3937
}
4038

4139
el.src.forEach(function (file) {
@@ -46,14 +44,20 @@ module.exports = function (grunt) {
4644
var newName = [path.basename(file, ext), suffix, ext.slice(1)].join('.');
4745
var resultPath;
4846

49-
if (move) {
50-
dirname = path.dirname(file);
51-
resultPath = path.resolve(dirname, newName);
52-
fs.renameSync(file, resultPath);
53-
} else {
54-
dirname = el.dest;
55-
resultPath = path.resolve(dirname, newName);
47+
dirname = el.dest ? el.dest : path.dirname(file);
48+
resultPath = path.resolve(dirname, newName);
49+
50+
if (options.copy === null) {
51+
// If options.copy is null, defer to wether or not destination is defined (old behavior)
52+
if (el.dest) {
53+
grunt.file.copy(file, resultPath);
54+
} else {
55+
fs.renameSync(file, resultPath);
56+
}
57+
} else if (options.copy) {
5658
grunt.file.copy(file, resultPath);
59+
} else {
60+
fs.renameSync(file, resultPath);
5761
}
5862

5963
filerev.summary[path.normalize(file)] = path.join(dirname, newName);

0 commit comments

Comments
 (0)