diff --git a/.travis.yml b/.travis.yml index 4a83e22..19c4e52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,5 @@ language: node_js node_js: - "0.11" - "0.10" - - "0.8" + - "4.3.0" + - "5.6.0" diff --git a/package.json b/package.json index e002d38..5d38485 100644 --- a/package.json +++ b/package.json @@ -27,10 +27,10 @@ "test": "node ./node_modules/vows/bin/vows --spec" }, "devDependencies": { - "grunt-contrib-jshint": "~0.7", - "grunt": "0.4.1", - "grunt-vows": "0.3.1", - "vows": "~0.7", + "grunt-contrib-jshint": "0.11.0", + "grunt": "0.4.5", + "grunt-vows": "~0.4.0", + "vows": "0.8.1", "grunt-cli": "~0.1.6" }, "keywords": [ diff --git a/tasks/hashresHelper.js b/tasks/hashresHelper.js index b30bcc8..0cfac0a 100644 --- a/tasks/hashresHelper.js +++ b/tasks/hashresHelper.js @@ -78,7 +78,9 @@ exports.hashAndSub = function(grunt, options) { var destContents = fs.readFileSync(f, encoding); files.forEach(function(value) { grunt.log.debug('Substituting ' + value[0] + ' by ' + value[1]) - destContents = destContents.replace(new RegExp(utils.preg_quote(value[0])+"(\\?[0-9a-z]+)?", "g"), value[1]); + //destContents = destContents.replace(new RegExp(utils.preg_quote(value[0])+"(\\?[0-9a-z]+)?", "g"), value[1]); + destContents = destContents.replace(new RegExp(utils.preg_quote(value[0])+"(\\?[0-9a-z\?=-]+)?", "g"), value[1]); + grunt.log.debug('Substituting ' + nameToNameSearch[value[0]] + ' by ' + value[1]) destContents = destContents.replace( diff --git a/test/fixtures/subfolders-querystring/index.html b/test/fixtures/subfolders-querystring/index.html new file mode 100644 index 0000000..ce01886 --- /dev/null +++ b/test/fixtures/subfolders-querystring/index.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring/scripts/myscripts1.js b/test/fixtures/subfolders-querystring/scripts/myscripts1.js new file mode 100644 index 0000000..1001058 --- /dev/null +++ b/test/fixtures/subfolders-querystring/scripts/myscripts1.js @@ -0,0 +1,3 @@ +(function() { + // Nothing to do +}) \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring/scripts/myscripts2.js b/test/fixtures/subfolders-querystring/scripts/myscripts2.js new file mode 100644 index 0000000..1001058 --- /dev/null +++ b/test/fixtures/subfolders-querystring/scripts/myscripts2.js @@ -0,0 +1,3 @@ +(function() { + // Nothing to do +}) \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring/styles/mystyles1.css b/test/fixtures/subfolders-querystring/styles/mystyles1.css new file mode 100644 index 0000000..63e5c49 --- /dev/null +++ b/test/fixtures/subfolders-querystring/styles/mystyles1.css @@ -0,0 +1 @@ +.style {} \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring/styles/mystyles2.css b/test/fixtures/subfolders-querystring/styles/mystyles2.css new file mode 100644 index 0000000..63e5c49 --- /dev/null +++ b/test/fixtures/subfolders-querystring/styles/mystyles2.css @@ -0,0 +1 @@ +.style {} \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/index.html b/test/fixtures/subfolders-querystring2/index.html new file mode 100644 index 0000000..5d2e646 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/index.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/scripts/myscripts1.js b/test/fixtures/subfolders-querystring2/scripts/myscripts1.js new file mode 100644 index 0000000..1001058 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/scripts/myscripts1.js @@ -0,0 +1,3 @@ +(function() { + // Nothing to do +}) \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/scripts/myscripts2.js b/test/fixtures/subfolders-querystring2/scripts/myscripts2.js new file mode 100644 index 0000000..1001058 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/scripts/myscripts2.js @@ -0,0 +1,3 @@ +(function() { + // Nothing to do +}) \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/styles/mystyles1.css b/test/fixtures/subfolders-querystring2/styles/mystyles1.css new file mode 100644 index 0000000..63e5c49 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/styles/mystyles1.css @@ -0,0 +1 @@ +.style {} \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/styles/mystyles2.css b/test/fixtures/subfolders-querystring2/styles/mystyles2.css new file mode 100644 index 0000000..63e5c49 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/styles/mystyles2.css @@ -0,0 +1 @@ +.style {} \ No newline at end of file diff --git a/test/hashresHelper.spec.js b/test/hashresHelper.spec.js index 6e104f0..cb616e3 100644 --- a/test/hashresHelper.spec.js +++ b/test/hashresHelper.spec.js @@ -60,6 +60,48 @@ vows.describe('hashresHelper').addBatch({ assert(html.indexOf('scripts/5a7a5b61-myscripts2.js') !== -1); assert(html.indexOf('styles/3b97b071-mystyles1.css') !== -1); assert(html.indexOf('styles/3b97b071-mystyles2.css') !== -1); + }, +'for using has as querystring': function(grunt) { + helper.hashAndSub( + grunt, { + files: [{ + src : grunt.file.expand([ + './temp/helper/subfolders-querystring/scripts/*.js', + './temp/helper/subfolders-querystring/styles/mystyles1.css', + './temp/helper/subfolders-querystring/styles/mystyles2.css']), + dest: './temp/helper/subfolders-querystring/index.html' + }], + fileNameFormat: '${name}.${ext}?v=${hash}', + encoding : 'utf8', + renameFiles : true + }); + var html = fs.readFileSync('./temp/helper/subfolders-querystring/index.html', 'utf8'); + assert(html.indexOf('scripts/myscripts1.js?v=5a7a5b61') !== -1); + assert(html.indexOf('scripts/myscripts2.js?v=5a7a5b61') !== -1); + assert(html.indexOf('styles/mystyles1.css?v=3b97b071') !== -1); + assert(html.indexOf('styles/mystyles2.css?v=3b97b071') !== -1); + }, +'for using has as querystring twice or multiple times': function(grunt) { + helper.hashAndSub( + grunt, { + files: [{ + src : grunt.file.expand([ + './temp/helper/subfolders-querystring2/scripts/*.js', + './temp/helper/subfolders-querystring2/styles/mystyles1.css', + './temp/helper/subfolders-querystring2/styles/mystyles2.css']), + dest: './temp/helper/subfolders-querystring2/index.html' + }], + fileNameFormat: '${name}.${ext}?v=${hash}', + encoding : 'utf8', + renameFiles : true + }); + + var html = fs.readFileSync('./temp/helper/subfolders-querystring2/index.html', 'utf8'); + assert(html.indexOf('"scripts/myscripts1.js?v=5a7a5b61"') !== -1); + assert(html.indexOf('"scripts/myscripts2.js?v=5a7a5b61"') !== -1); + assert(html.indexOf('"styles/mystyles1.css?v=3b97b071"') !== -1); + assert(html.indexOf('"styles/mystyles2.css?v=3b97b071"') !== -1); } - } +} + }).export(module); \ No newline at end of file