Skip to content

Commit d18d833

Browse files
author
sladex
committed
dropCwd option, fixes yeoman#15
1 parent d432703 commit d18d833

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tasks/filerev.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ module.exports = function (grunt) {
1010
var options = this.options({
1111
encoding: 'utf8',
1212
algorithm: 'md5',
13-
length: 8
13+
length: 8,
14+
dropCwd: false
1415
});
1516
var target = this.target;
1617
var filerev = grunt.filerev || {summary: {}};
18+
var cwd = this.data.cwd || '';
1719

1820
eachAsync(this.files, function (el, i, next) {
1921
var move = true;
@@ -60,13 +62,24 @@ module.exports = function (grunt) {
6062
grunt.file.copy(file, resultPath);
6163
}
6264

63-
filerev.summary[path.normalize(file)] = path.join(dirname, newName);
65+
filerev.summary[fixPath(path.normalize(file))] = fixPath(path.join(dirname, newName));
6466
grunt.log.writeln(chalk.green('✔ ') + file + chalk.gray(' changed to ') + newName);
6567
});
6668

6769
next();
6870
}, this.async());
6971

72+
function fixPath (path) {
73+
// Drop cwd from path if relative option is set to true
74+
if (options.dropCwd === true && cwd.length) {
75+
var pos = path.indexOf(cwd);
76+
if (pos === 0) {
77+
path = path.slice(cwd.length);
78+
}
79+
}
80+
return path;
81+
}
82+
7083
grunt.filerev = filerev;
7184
});
7285
};

0 commit comments

Comments
 (0)