From 870b21114f9982ddb4bf3585bd1542c27a0b30bc Mon Sep 17 00:00:00 2001 From: Frederick Ros Date: Tue, 7 May 2013 17:01:40 +0200 Subject: [PATCH] Added an option to create a summary file --- Gruntfile.js | 6 ++++++ tasks/rev.js | 6 +++++- test/fixtures/revsummary.txt | 1 + test/rev_test.js | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/revsummary.txt diff --git a/Gruntfile.js b/Gruntfile.js index a9e2b22..61de6f5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -56,6 +56,12 @@ module.exports = function(grunt) { }, src: ['tmp/international.txt'] }, + summary_options: { + options: { + summary: 'tmp/rev_summary.js' + }, + src: ['tmp/revsummary.txt'] + } }, // Unit tests. diff --git a/tasks/rev.js b/tasks/rev.js index f6f77c2..2212d6a 100644 --- a/tasks/rev.js +++ b/tasks/rev.js @@ -28,6 +28,7 @@ module.exports = function(grunt) { algorithm: 'md5', length: 8 }); + var summary = {}; this.files.forEach(function(filePair) { filePair.src.forEach(function(f) { @@ -36,7 +37,7 @@ module.exports = function(grunt) { prefix = hash.slice(0, options.length), renamed = [prefix, path.basename(f)].join('.'), outPath = path.resolve(path.dirname(f), renamed); - + summary[f] = path.join(path.dirname(f), renamed); grunt.verbose.ok().ok(hash); fs.renameSync(f, outPath); grunt.log.write(f + ' ').ok(renamed); @@ -44,6 +45,9 @@ module.exports = function(grunt) { }); }); + if (options.summary) { + grunt.file.write(options.summary, JSON.stringify(summary)); + } }); }; diff --git a/test/fixtures/revsummary.txt b/test/fixtures/revsummary.txt new file mode 100644 index 0000000..ff3bb63 --- /dev/null +++ b/test/fixtures/revsummary.txt @@ -0,0 +1 @@ +The quick brown fox jumps over the lazy dog \ No newline at end of file diff --git a/test/rev_test.js b/test/rev_test.js index b876642..549419c 100644 --- a/test/rev_test.js +++ b/test/rev_test.js @@ -49,6 +49,16 @@ exports.rev = { var exists = grunt.file.exists('tmp/faa07745.international.txt'); test.ok(exists, '8 character MD5 hash prefix for international content'); + test.done(); + }, + rev_summary_options: function(test) { + test.expect(2); + + var exists = grunt.file.exists('tmp/rev_summary.js'); + test.ok(exists, 'summary file produced'); + + var summary = grunt.file.readJSON('tmp/rev_summary.js'); + test.equal(summary['tmp/revsummary.txt'], 'tmp/9e107d9d.revsummary.txt'); test.done(); } };