@@ -10,14 +10,14 @@ module.exports = function (grunt) {
10
10
var options = this . options ( {
11
11
encoding : 'utf8' ,
12
12
algorithm : 'md5' ,
13
- length : 8
13
+ length : 8 ,
14
+ copy : null
14
15
} ) ;
15
16
var target = this . target ;
16
17
var filerev = grunt . filerev || { summary : { } } ;
17
18
18
19
eachAsync ( this . files , function ( el , i , next ) {
19
- var move = true ;
20
-
20
+
21
21
// If dest is furnished it should indicate a directory
22
22
if ( el . dest ) {
23
23
// When globbing is used, el.dest contains basename, we remove it
@@ -34,8 +34,6 @@ module.exports = function (grunt) {
34
34
grunt . log . writeln ( 'Destination dir ' + el . dest + ' does not exists for target ' + target + ': creating' ) ;
35
35
grunt . file . mkdir ( el . dest ) ;
36
36
}
37
- // We need to copy file as we now have a dest different from the src
38
- move = false ;
39
37
}
40
38
41
39
el . src . forEach ( function ( file ) {
@@ -46,14 +44,20 @@ module.exports = function (grunt) {
46
44
var newName = [ path . basename ( file , ext ) , suffix , ext . slice ( 1 ) ] . join ( '.' ) ;
47
45
var resultPath ;
48
46
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 ) {
56
58
grunt . file . copy ( file , resultPath ) ;
59
+ } else {
60
+ fs . renameSync ( file , resultPath ) ;
57
61
}
58
62
59
63
filerev . summary [ path . normalize ( file ) ] = path . join ( dirname , newName ) ;
0 commit comments