From 3c382e772ef2335520729172d44ea668ebe7efb0 Mon Sep 17 00:00:00 2001 From: x4storm Date: Fri, 21 Jul 2017 01:52:33 +0800 Subject: [PATCH 1/3] update Fix for that issues: If the filename like below: custom-a-b.css main-test.js the replace will apply in props the manifest.json will be: { "custom-a.css?v=b": "custom-a-b.css?v=xxxxx", "main.js?v=test": "main-test.js?v=xxxxx" } So, I parse the string to Object, then travel it, only replace the value in object. --- index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index edf4cd8..64a9569 100644 --- a/index.js +++ b/index.js @@ -5,10 +5,13 @@ module.exports = function(ver) { // convert a-xxxxxxxx.css to a.css?ver=xxxxxxxx function hashToQuery(file) { var content = new String(file.contents); - content = content.replace(/(\-(\w+))(\.\w+)/g, function($, $1, $2, $3) { - return $3 + '?' + ver + '=' + $2; - }) - file.contents = new Buffer(content); + var manifestObj = JSON.parse(content) + for(var key in manifestObj){ + manifestObj[key] = manifestObj[key].replace(/(\-(\w+))(\.\w+)/g, function($, $1, $2, $3) { + return $3 + '?' + ver + '=' + $2; + }) + } + file.contents = new Buffer(JSON.stringify(manifestObj, null, '\t')); file.ver = ver; return file; } From daf97c2da2b220d5be929a2b80aa8be5d367c3fc Mon Sep 17 00:00:00 2001 From: x4storm Date: Fri, 21 Jul 2017 14:06:42 +0800 Subject: [PATCH 2/3] update Fix for this issues: filename: jquery.1.7.0.js test.min.js for multi dots in finename --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 64a9569..3ddabec 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ module.exports = function(ver) { var content = new String(file.contents); var manifestObj = JSON.parse(content) for(var key in manifestObj){ - manifestObj[key] = manifestObj[key].replace(/(\-(\w+))(\.\w+)/g, function($, $1, $2, $3) { + manifestObj[key] = manifestObj[key].replace(/(\-(\w+))((\.\w+)+)/g, function($, $1, $2, $3) { return $3 + '?' + ver + '=' + $2; }) } From 0e14f3bc1ed0cc49ecdb577436ee1aef7e557fab Mon Sep 17 00:00:00 2001 From: x4storm Date: Fri, 21 Jul 2017 15:22:51 +0800 Subject: [PATCH 3/3] update Fix for this filename: angular-datatables.light-columnfilter.a.js beacause the gulp-rev always prepend hash in first dots. so reg should consider after .- --- index.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 3ddabec..0ac1c7e 100644 --- a/index.js +++ b/index.js @@ -1,21 +1,21 @@ var through = require('through2'); -module.exports = function(ver) { - var ver = ver || 'ver' - // convert a-xxxxxxxx.css to a.css?ver=xxxxxxxx - function hashToQuery(file) { - var content = new String(file.contents); - var manifestObj = JSON.parse(content) - for(var key in manifestObj){ - manifestObj[key] = manifestObj[key].replace(/(\-(\w+))((\.\w+)+)/g, function($, $1, $2, $3) { - return $3 + '?' + ver + '=' + $2; - }) - } - file.contents = new Buffer(JSON.stringify(manifestObj, null, '\t')); - file.ver = ver; - return file; +module.exports = function (ver) { + var ver = ver || 'ver' + // convert a-xxxxxxxx.css to a.css?ver=xxxxxxxx + function hashToQuery(file) { + var content = new String(file.contents); + var manifestObj = JSON.parse(content) + for (var key in manifestObj) { + manifestObj[key] = manifestObj[key].replace(/(\-(\w+))((\.[-\w]+)+)/g, function ($, $1, $2, $3) { + return $3 + '?' + ver + '=' + $2; + }) } - return through.obj(function(file, encoding, callback) { - callback(null, hashToQuery(file)); - }); + file.contents = new Buffer(JSON.stringify(manifestObj, null, '\t')); + file.ver = ver; + return file; + } + return through.obj(function (file, encoding, callback) { + callback(null, hashToQuery(file)); + }); };