Skip to content

Commit

Permalink
Support for cwd + source path
Browse files Browse the repository at this point in the history
This adds support for changing the current working directory via
options, and uses the source path (relative to the cwd) instead of just
the filename when determining the destination path.
  • Loading branch information
dgieselaar committed Apr 3, 2013
1 parent 95273c5 commit 7dd9475
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/grunt-text-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ exports.replaceFileMultiple = function (settings) {

gruntTextReplace = {
replace: function (settings) {
var src = grunt.file.expand(settings.src || []);
var src = settings.src || '';
var dest = settings.dest;
var cwd = settings.cwd;
var prevCwd;
var overwrite = settings.overwrite;
var replacements = settings.replacements;
var isDestinationDirectory = (/\/$/).test(dest);
var initialWarnCount = grunt.fail.warncount;

if(cwd) {
prevCwd = process.cwd();
grunt.file.setBase(cwd);
}

if (typeof dest === 'undefined' &&
typeof src === 'undefined' &&
Expand All @@ -53,6 +60,10 @@ gruntTextReplace = {
replacements: replacements
});
}

if(prevCwd) {
grunt.file.setBase(prevCwd);
}
},

errorMessages: {
Expand Down Expand Up @@ -114,12 +125,11 @@ gruntTextReplace = {

getPathToDestination: function (pathToSource, pathToDestinationFile) {
var isDestinationDirectory = (/\/$/).test(pathToDestinationFile);
var fileName = path.basename(pathToSource);
var newPathToDestination;
if (typeof pathToDestinationFile === 'undefined') {
newPathToDestination = pathToSource;
} else {
newPathToDestination = pathToDestinationFile + (isDestinationDirectory ? fileName : '');
newPathToDestination = pathToDestinationFile + (isDestinationDirectory ? pathToSource : '');
}
return newPathToDestination;
},
Expand Down Expand Up @@ -172,4 +182,4 @@ gruntTextReplace = {
return isProcessTemplateTrue ? grunt.template.process(string) : string;
}

}
}

0 comments on commit 7dd9475

Please sign in to comment.