This repository was archived by the owner on Mar 26, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 70
Added options.copy #21
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,14 @@ module.exports = function (grunt) { | |
var options = this.options({ | ||
encoding: 'utf8', | ||
algorithm: 'md5', | ||
length: 8 | ||
length: 8, | ||
copy: null | ||
}); | ||
var target = this.target; | ||
var filerev = grunt.filerev || {summary: {}}; | ||
|
||
eachAsync(this.files, function (el, i, next) { | ||
var move = true; | ||
|
||
|
||
// If dest is furnished it should indicate a directory | ||
if (el.dest) { | ||
// When globbing is used, el.dest contains basename, we remove it | ||
|
@@ -34,8 +34,6 @@ module.exports = function (grunt) { | |
grunt.log.writeln('Destination dir ' + el.dest + ' does not exists for target ' + target + ': creating'); | ||
grunt.file.mkdir(el.dest); | ||
} | ||
// We need to copy file as we now have a dest different from the src | ||
move = false; | ||
} | ||
|
||
el.src.forEach(function (file) { | ||
|
@@ -46,14 +44,20 @@ module.exports = function (grunt) { | |
var newName = [path.basename(file, ext), suffix, ext.slice(1)].join('.'); | ||
var resultPath; | ||
|
||
if (move) { | ||
dirname = path.dirname(file); | ||
resultPath = path.resolve(dirname, newName); | ||
fs.renameSync(file, resultPath); | ||
} else { | ||
dirname = el.dest; | ||
resultPath = path.resolve(dirname, newName); | ||
dirname = el.dest ? el.dest : path.dirname(file); | ||
resultPath = path.resolve(dirname, newName); | ||
|
||
if (options.copy === null) { | ||
// If options.copy is null, defer to wether or not destination is defined (old behavior) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mwillerich I think this third case is missing from the tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ProLoser I just added 2 more tests for this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all this can be rewritten as if (options.copy || (options.copy === null && el.dest)) {
grunt.file.copy(file, resultPath);
}
else {
fs.renameSync(file, resultPath);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eddiemonge yes, makes sense. I've added it to the PR on @ProLoser's fork. |
||
if (el.dest) { | ||
grunt.file.copy(file, resultPath); | ||
} else { | ||
fs.renameSync(file, resultPath); | ||
} | ||
} else if (options.copy) { | ||
grunt.file.copy(file, resultPath); | ||
} else { | ||
fs.renameSync(file, resultPath); | ||
} | ||
|
||
filerev.summary[path.normalize(file)] = path.join(dirname, newName); | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be
if (!options.copy) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a 3-state option. True, False and null. Perhaps the check should be rearranged so that it explicitly does
options.copy === true
,options.copy === false
and then just use this case for the rest. Sincenull != undefined