diff --git a/tasks/filerev.js b/tasks/filerev.js index 9ebb173..c95d77c 100644 --- a/tasks/filerev.js +++ b/tasks/filerev.js @@ -27,7 +27,7 @@ module.exports = function (grunt) { try { var stat = fs.lstatSync(el.dest); if (stat && !stat.isDirectory()) { - grunt.fail.fatal('Destination ' + el.dest + ' for target ' + target + ' is not a directory'); + grunt.fail.fatal('Destination ' + el.dest + ' for target ' + target + ' is not a directory'); } } catch (err) { grunt.verbose.writeln('Destination dir ' + el.dest + ' does not exists for target ' + target + ': creating'); @@ -55,7 +55,11 @@ module.exports = function (grunt) { grunt.log.error('options.process must be a function; ignoring'); } - newName = [path.basename(file, ext), suffix, ext.slice(1)].join('.'); + newName = [ + path.basename(file, ext), + suffix, + ext.slice(1) + ].join('.'); } var resultPath; @@ -101,6 +105,44 @@ module.exports = function (grunt) { next(); }, this.async()); + if (options.stripPath) { + // modify filerev summary + var strippedSummary = {}; + + for (var key in filerev.summary) { + if (filerev.summary.hasOwnProperty(key)) { + var src; + var dest; + + if (typeof options.stripPath === 'object') { + if (options.stripPath.src) { + src = options.stripPath.src; + } + + if (options.stripPath.dest) { + dest = options.stripPath.dest; + } + } else { + src = options.stripPath; + dest = options.stripPath; + } + + var value = filerev.summary[key]; + value = value.replace(dest, ''); + key = key.replace(src, ''); + strippedSummary[key] = value; + } + } + + filerev.summary = strippedSummary; + } + + if (options.summaryFilePath) { + // write filerev summary into file + fs.writeFileSync(options.summaryFilePath, JSON.stringify(filerev.summary, null, 4)); + grunt.log.writeln('Filerev summary was stored to ' + options.summaryFilePath); + } + grunt.filerev = filerev; }); };