From b4cb832c5e5ea880bd9d85babaee65081eab1dda Mon Sep 17 00:00:00 2001 From: eversteini Date: Fri, 20 Mar 2015 11:48:59 +0100 Subject: [PATCH 1/5] store summary to file --- tasks/filerev.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tasks/filerev.js b/tasks/filerev.js index 9ebb173..782105e 100644 --- a/tasks/filerev.js +++ b/tasks/filerev.js @@ -101,6 +101,35 @@ module.exports = function (grunt) { next(); }, this.async()); + if (options.summaryFilePath) { + // modify filerev summary + var customSummary = {}; + + _.forEach(filerev.summary, function(value, key) { + var src; + var dest; + if (_.isObject(options.stripPath)){ + if (options.stripPath.src) { + src = options.stripPath.src; + } + if (options.stripPath.dest) { + dest = options.stripPath.dest; + } + } + else { + src = options.stripPath; + dest = options.stripPath; + } + key = key.replace(src, ''); + value = value.replace(dest, ''); + customSummary[key] = value; + }); + + // write filerev summary into file + fs.writeFileSync(options.summaryFilePath, JSON.stringify(customSummary, null, 4)); + grunt.log.writeln('Filerev summary was stored to ' + options.summaryFilePath); + } + grunt.filerev = filerev; }); }; From 206beb5403dd5adb1c0c2c36fd1ee7c06dee027e Mon Sep 17 00:00:00 2001 From: eversteini Date: Fri, 20 Mar 2015 12:34:07 +0100 Subject: [PATCH 2/5] saving summary and stripping summery are now independent --- tasks/filerev.js | 67 +++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/tasks/filerev.js b/tasks/filerev.js index 782105e..961119d 100644 --- a/tasks/filerev.js +++ b/tasks/filerev.js @@ -27,9 +27,10 @@ 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) { + } + catch (err) { grunt.verbose.writeln('Destination dir ' + el.dest + ' does not exists for target ' + target + ': creating'); grunt.file.mkdir(el.dest); } @@ -50,12 +51,17 @@ module.exports = function (grunt) { if (typeof options.process === 'function') { newName = options.process(path.basename(file, ext), suffix, ext.slice(1)); - } else { + } + else { if (options.process) { 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; @@ -64,7 +70,8 @@ module.exports = function (grunt) { dirname = path.dirname(file); resultPath = path.resolve(dirname, newName); fs.renameSync(file, resultPath); - } else { + } + else { dirname = el.dest; resultPath = path.resolve(dirname, newName); grunt.file.copy(file, resultPath); @@ -78,7 +85,8 @@ module.exports = function (grunt) { if (grunt.file.exists(map)) { if (move) { fs.renameSync(map, resultPath); - } else { + } + else { grunt.file.copy(map, resultPath); } sourceMap = true; @@ -101,32 +109,39 @@ module.exports = function (grunt) { next(); }, this.async()); - if (options.summaryFilePath) { + if (options.stripPath) { // modify filerev summary - var customSummary = {}; - - _.forEach(filerev.summary, function(value, key) { - var src; - var dest; - if (_.isObject(options.stripPath)){ - if (options.stripPath.src) { - src = options.stripPath.src; + 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; + } } - 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; } - else { - src = options.stripPath; - dest = options.stripPath; - } - key = key.replace(src, ''); - value = value.replace(dest, ''); - customSummary[key] = value; - }); + } + + filerev.summary = strippedSummary; + } + if (options.summaryFilePath) { // write filerev summary into file - fs.writeFileSync(options.summaryFilePath, JSON.stringify(customSummary, null, 4)); + fs.writeFileSync(options.summaryFilePath, JSON.stringify(filerev.summary, null, 4)); grunt.log.writeln('Filerev summary was stored to ' + options.summaryFilePath); } From ff8f2a9cf4f07a996cbe0b0d860d12940b6653f5 Mon Sep 17 00:00:00 2001 From: eversteini Date: Mon, 23 Mar 2015 10:57:25 +0100 Subject: [PATCH 3/5] Restructured code based on comments --- .idea/.name | 1 + .idea/encodings.xml | 4 + .idea/grunt-filerev.iml | 9 + .idea/jsLibraryMappings.xml | 6 + .../libraries/grunt_filerev_node_modules.xml | 14 ++ .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/scopes/scope_settings.xml | 5 + .idea/vcs.xml | 6 + .idea/workspace.xml | 212 ++++++++++++++++++ tasks/filerev.js | 18 +- 11 files changed, 277 insertions(+), 10 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/encodings.xml create mode 100644 .idea/grunt-filerev.iml create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/libraries/grunt_filerev_node_modules.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..9af2615 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +grunt-filerev \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..d821048 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/grunt-filerev.iml b/.idea/grunt-filerev.iml new file mode 100644 index 0000000..10070c8 --- /dev/null +++ b/.idea/grunt-filerev.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..0e84c87 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/grunt_filerev_node_modules.xml b/.idea/libraries/grunt_filerev_node_modules.xml new file mode 100644 index 0000000..58e597f --- /dev/null +++ b/.idea/libraries/grunt_filerev_node_modules.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8662aa9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9519c1a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..7641580 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $PROJECT_DIR$/Gruntfile.js + + + false + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1427104042137 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tasks/filerev.js b/tasks/filerev.js index 961119d..a06acc9 100644 --- a/tasks/filerev.js +++ b/tasks/filerev.js @@ -29,8 +29,7 @@ module.exports = function (grunt) { if (stat && !stat.isDirectory()) { grunt.fail.fatal('Destination ' + el.dest + ' for target ' + target + ' is not a directory'); } - } - catch (err) { + } catch (err) { grunt.verbose.writeln('Destination dir ' + el.dest + ' does not exists for target ' + target + ': creating'); grunt.file.mkdir(el.dest); } @@ -51,8 +50,7 @@ module.exports = function (grunt) { if (typeof options.process === 'function') { newName = options.process(path.basename(file, ext), suffix, ext.slice(1)); - } - else { + } else { if (options.process) { grunt.log.error('options.process must be a function; ignoring'); } @@ -70,8 +68,7 @@ module.exports = function (grunt) { dirname = path.dirname(file); resultPath = path.resolve(dirname, newName); fs.renameSync(file, resultPath); - } - else { + } else { dirname = el.dest; resultPath = path.resolve(dirname, newName); grunt.file.copy(file, resultPath); @@ -85,8 +82,7 @@ module.exports = function (grunt) { if (grunt.file.exists(map)) { if (move) { fs.renameSync(map, resultPath); - } - else { + } else { grunt.file.copy(map, resultPath); } sourceMap = true; @@ -117,18 +113,20 @@ module.exports = function (grunt) { 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 { + } else { src = options.stripPath; dest = options.stripPath; } + var value = filerev.summary[key]; value = value.replace(dest, ''); key = key.replace(src, ''); From 5beef65fc67d8ea3aca8b83271f3240d36564a7f Mon Sep 17 00:00:00 2001 From: eversteini Date: Mon, 23 Mar 2015 11:23:49 +0100 Subject: [PATCH 4/5] Removed .idea folder --- .idea/.name | 1 - .idea/encodings.xml | 4 - .idea/grunt-filerev.iml | 9 - .idea/jsLibraryMappings.xml | 6 - .../libraries/grunt_filerev_node_modules.xml | 14 -- .idea/misc.xml | 4 - .idea/modules.xml | 8 - .idea/scopes/scope_settings.xml | 5 - .idea/vcs.xml | 6 - .idea/workspace.xml | 212 ------------------ 10 files changed, 269 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/grunt-filerev.iml delete mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/libraries/grunt_filerev_node_modules.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 9af2615..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -grunt-filerev \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index d821048..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/grunt-filerev.iml b/.idea/grunt-filerev.iml deleted file mode 100644 index 10070c8..0000000 --- a/.idea/grunt-filerev.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index 0e84c87..0000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/libraries/grunt_filerev_node_modules.xml b/.idea/libraries/grunt_filerev_node_modules.xml deleted file mode 100644 index 58e597f..0000000 --- a/.idea/libraries/grunt_filerev_node_modules.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 8662aa9..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 9519c1a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 7641580..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,212 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $PROJECT_DIR$/Gruntfile.js - - - false - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1427104042137 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From b2dde35d6bc308f7c05e647e37782daec40583c3 Mon Sep 17 00:00:00 2001 From: eversteini Date: Mon, 23 Mar 2015 11:30:58 +0100 Subject: [PATCH 5/5] Removed empty line --- tasks/filerev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/filerev.js b/tasks/filerev.js index a06acc9..c95d77c 100644 --- a/tasks/filerev.js +++ b/tasks/filerev.js @@ -126,7 +126,7 @@ module.exports = function (grunt) { src = options.stripPath; dest = options.stripPath; } - + var value = filerev.summary[key]; value = value.replace(dest, ''); key = key.replace(src, '');