diff --git a/Gruntfile.js b/Gruntfile.js index 45ff5d5..694cf6f 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -8,6 +8,8 @@ 'use strict'; +Object.assign = require('object-assign') + module.exports = function(grunt) { var _fileGlobSync; @@ -49,6 +51,16 @@ module.exports = function(grunt) { 'tmp/js/js_bundle_b.js': ['test/fake/file3.js', 'test/fake/file4.js'] } }, + options_tag_date_rename: { + options: { + tag : 'date', + renameToVersion: true + }, + files: { + 'tmp/js/js_bundle_a.js': ['test/fake/file1.js', 'test/fake/file2.js'], + 'tmp/js/js_bundle_b.js': ['test/fake/file3.js', 'test/fake/file4.js'] + } + }, options_dateFormat: { options: { tag : 'date', @@ -145,7 +157,20 @@ module.exports = function(grunt) { versionsMapTrimPath : 'tmp/options_output_trim/' } }, - options_versionsMapTemplate: { + options_versionsMapTemplateFail: { + files: [{ + expand : true, + cwd : "test/fixtures/images/", + src : ['**/*.png', '**/*.jpg', '**/*.gif'], + dest : "tmp/options_versionsMapTemplate/" + }], + options: { + versionsMapFile : 'tmp/options_versionsMapTemplateFail.php', + versionsMapTemplate : 'test/fixtures/templates/php.tpl.missing', + versionsMapTrimPath : 'tmp/options_versionsMapTemplate/' + } + }, + options_versionsMapTemplateFile: { files: [{ expand : true, cwd : "test/fixtures/images/", @@ -153,11 +178,53 @@ module.exports = function(grunt) { dest : "tmp/options_versionsMapTemplate/" }], options: { - versionsMapFile : 'tmp/options_versionsMapTemplate.php', + versionsMapFile : 'tmp/options_versionsMapTemplateFile.php', versionsMapTemplate : 'test/fixtures/templates/php.tpl', versionsMapTrimPath : 'tmp/options_versionsMapTemplate/' } }, + options_versionsMapTemplateString: { + files: [{ + expand : true, + cwd : "test/fixtures/images/", + src : ['**/*.png', '**/*.jpg', '**/*.gif'], + dest : "tmp/options_versionsMapTemplate/" + }], + options: { + delimiters : 'altDelimiters', + versionsMapFile : 'tmp/options_versionsMapTemplateString.php', + versionsMapTemplate : encodeURI('\r\n \"<%= file.originalPath %>\" => \"<%= file.versionedPath %>\",\r\n<% }); %>\r\n );\r\n}\r\n'), + versionsMapTrimPath : 'tmp/options_versionsMapTemplate/' + } + }, + options_versionsMapTemplateFunction: { + files: [{ + expand : true, + cwd : "test/fixtures/images/", + src : ['**/*.png', '**/*.jpg', '**/*.gif'], + dest : "tmp/options_versionsMapTemplate/" + }], + options: { + delimiters : 'altDelimiters', + versionsMapFile : 'tmp/options_versionsMapTemplateFunction.php', + versionsMapTemplate : function () { return encodeURI('\r\n \"<%= file.originalPath %>\" => \"<%= file.versionedPath %>\",\r\n<% }); %>\r\n );\r\n}\r\n'); }, + versionsMapTrimPath : 'tmp/options_versionsMapTemplate/' + } + }, + options_versionsMapDataFile: { + files: [{ + expand : true, + cwd : "test/fixtures/images/", + src : ['**/*.png', '**/*.jpg', '**/*.gif'], + dest : "tmp/options_versionsMapDataFile/" + }], + options: { + delimiters : 'altDelimiters', + versionsMapDataFile : 'tmp/options_versionsMapDataFile.json', + versionsMapFilesAutoDelete : true, + versionsMapTrimPath : 'tmp/options_versionsMapDataFile/' + } + }, files_compact_format: { src: [ 'test/fixtures/js/file1.js', @@ -427,6 +494,7 @@ module.exports = function(grunt) { 'clean', 'startMocking', 'assets_versioning:options_tag_date', + 'assets_versioning:options_tag_date_rename', 'assets_versioning:options_dateFormat', 'assets_versioning:options_timezoneOffset', 'stopMocking', @@ -439,7 +507,11 @@ module.exports = function(grunt) { 'assets_versioning:options_post_internal', 'assets_versioning:options_versionsMapFile', 'assets_versioning:output_versionsMapTrimPath', - 'assets_versioning:options_versionsMapTemplate', + 'assets_versioning:options_versionsMapTemplateFail', + 'assets_versioning:options_versionsMapTemplateFile', + 'assets_versioning:options_versionsMapTemplateString', + 'assets_versioning:options_versionsMapTemplateFunction', + 'assets_versioning:options_versionsMapDataFile', 'assets_versioning:files_compact_format', 'assets_versioning:files_object_format', 'assets_versioning:files_array_format', diff --git a/README.md b/README.md index 2e6f48c..58ecfd3 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# grunt-assets-versioning [![Build Status](https://travis-ci.org/theasta/grunt-assets-versioning.svg?branch=master)](https://travis-ci.org/theasta/grunt-assets-versioning) [![NPM version](https://badge.fury.io/js/grunt-assets-versioning.svg)](http://badge.fury.io/js/grunt-assets-versioning) -[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/theasta/grunt-assets-versioning?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +# grunt-assets-versioning +[![Build Status](https://travis-ci.org/theasta/grunt-assets-versioning.svg?branch=master)](https://travis-ci.org/theasta/grunt-assets-versioning) [![GitHub version](https://badge.fury.io/gh/theasta%2Fgrunt-assets-versioning.svg)](https://badge.fury.io/gh/theasta%2Fgrunt-assets-versioning) [![NPM version](https://badge.fury.io/js/grunt-assets-versioning.svg)](http://badge.fury.io/js/grunt-assets-versioning) [![dependencies](https://david-dm.org/theasta/grunt-assets-versioning.svg)](https://david-dm.org/theasta/grunt-assets-versioning) [![devDependencies](https://david-dm.org/theasta/grunt-assets-versioning/dev-status.svg)](https://david-dm.org/theasta/grunt-assets-versioning?type=dev) [![peerDependencies](https://david-dm.org/theasta/grunt-assets-versioning/peer-status.svg)](https://david-dm.org/theasta/grunt-assets-versioning?type=peer) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/theasta/grunt-assets-versioning?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) > Versioning static assets with Grunt @@ -55,6 +55,12 @@ Default value: `8` If you choose to version your files using a hash, hashLength let you set how long the hash is going to be. +#### options.renameToVersion +Type: `Boolean` +Default value: `false` + +Should the hash replace the file name before the final extension, or (default) should it be just be appended before the final extension? + #### options.dateFormat Type: `String` Default value: `YYYYMMDDHHmmss` @@ -99,17 +105,17 @@ By default you can retrieve the map of versions by accessing this configuration The versionsMapFile gives you the possibility to also output that map to a file. #### options.versionsMapTemplate -Type: `String` +Type: `String` or `Function: String` Default value: `null` -Path to a lodash template file that is going to be used to generate the versions map file (options.versionsMapFile) +Path to a lodash template file or URL-encoded string, optionally returned by a function, that is going to be used to generate the versions map file (options.versionsMapFile). -By default, when no template is indicated, the task will output a json file. +By default, when no valid template is indicated, the task will output a json file. The lo-dash template may reuse the keys from the version maps (version, originalPath, versionedPath). Here's an example of a lo-dash template to generate a php dictionary. -```php +``` = 0.10.0" + "node": ">= 0.12.0" }, "scripts": { "test": "grunt test" }, "devDependencies": { - "grunt": "~0.4.1", - "grunt-contrib-clean": "~0.4.1", - "grunt-contrib-concat": "~0.2.0", - "grunt-contrib-jshint": "~0.1.1", - "grunt-contrib-nodeunit": "~0.1.2", + "grunt": "^0.4.5", + "grunt-cli": "^1.2.0", + "grunt-contrib-clean": "~1", + "grunt-contrib-concat": "~1", + "grunt-contrib-jshint": "~1", + "grunt-contrib-nodeunit": "~1", "grunt-jsdoc": "^0.6.1", - "mock-fs": "^2.3.1" + "mock-fs": "~4", + "nodeunit": "^0.11.0" }, "peerDependencies": { "grunt": ">=0.4.0" @@ -43,8 +45,9 @@ "gruntplugin" ], "dependencies": { - "lodash": "^2.4.1", - "moment": "^2.9.0", + "lodash": "^4", + "moment": "^2.18.1", + "object-assign": "^4.1.1", "slash": "^1.0.0" } } diff --git a/tasks/assets_versioning.js b/tasks/assets_versioning.js index 2810878..a78b9bf 100755 --- a/tasks/assets_versioning.js +++ b/tasks/assets_versioning.js @@ -11,6 +11,7 @@ var path = require('path'); var versionerFactory = require('./versioners/versionerFactory'); var _ = require('lodash'); +var taggers = require('./taggers'); module.exports = function(grunt) { @@ -24,11 +25,10 @@ module.exports = function(grunt) { encoding: 'utf8', dateFormat: 'YYYYMMDDHHmmss', timezoneOffset: 0, - versionize: function(destPath, version) { + versionize: function(destPath, version, onlyVersion) { return path.dirname(destPath) + path.sep + - path.basename(destPath, path.extname(destPath)) + - '.'+ + (onlyVersion ? '' : path.basename(destPath, path.extname(destPath)) + '.') + version + path.extname(destPath); }, @@ -41,8 +41,8 @@ module.exports = function(grunt) { runTask: true }); - if (!_.contains(['hash', 'date'], options.tag)) { - grunt.fail.warn('Invalid argument : options.tag should be equal to date or hash', 1); + if (!_.includes(Object.keys(taggers), options.tag)) { + grunt.fail.warn('Invalid argument : options.tag should be one of: ' + Object.keys(taggers).join(', '), 1); } if (options.post && options.skipExisting) { diff --git a/tasks/taggers/hash.js b/tasks/taggers/hash.js index cd54006..cf55318 100644 --- a/tasks/taggers/hash.js +++ b/tasks/taggers/hash.js @@ -14,20 +14,24 @@ var fs = require('fs'); * @returns {string} */ module.exports = function (src, options) { - var hash = ''; + 'use strict'; + var hash = crypto.createHash('md5'); - src.forEach(function(f){ - hash += crypto.createHash('md5').update(fs.readFileSync(f, options.encoding)).digest('hex'); + var digest = null; + + src.forEach(function (f) { + var input = fs.readFileSync(f, options.encoding); + hash.update(input, 'binary'); + hash.update(f, 'binary'); }); - if (src.length > 1){ - hash = crypto.createHash('md5').update(hash).digest('hex'); - } + var hashLength = parseInt(options.hashLength, 10); + digest = hash.digest('hex'); // can't use typeof since typeof NaN == 'number' if (Object.prototype.toString.call(hashLength) === '[object Number]') { - hash = hash.substr(0, options.hashLength); + digest = digest.substr(0, hashLength); } - return hash; + return digest; }; diff --git a/tasks/versioners/abstractVersioner.js b/tasks/versioners/abstractVersioner.js index 13b82ea..3c560a6 100644 --- a/tasks/versioners/abstractVersioner.js +++ b/tasks/versioners/abstractVersioner.js @@ -2,6 +2,7 @@ * @module versioners/AbstractVersioner */ +var path = require('path'); var grunt = require('grunt'); var taggers = require('../taggers'); var _ = require('lodash'); @@ -26,23 +27,26 @@ var slash = require('slash'); * @param {object} taskData - Grunt Assets Versioning Task Object */ function AbstractVersioner(options, taskData) { - this.options = options; - this.taskData = taskData; - - /** - * Map of versioned files - * @type {Array.<{version, originalPath: string, versionedPath: string}>} - */ - this.versionsMap = []; - - /** - * Get one of the tagger functions: hash or date - * @type {function} - */ - this.versionTagger = taggers[this.options.tag]; - - // is task a post versioning task? - this.isPostVersioningTask = grunt.config(this.getAssetsVersioningTaskConfigKey() + '.isPostVersioningTaskFor'); + this.options = options; + this.taskData = taskData; + + /** + * Map of versioned files + * @type {Array.<{version, originalPath: string, versionedPath: string}>} + */ + this.versionsMap = []; + if (this.options.versionsMapDataFile != null && grunt.file.exists(this.options.versionsMapDataFile)) { + this.versionsMap = grunt.file.readJSON(options.versionsMapDataFile); + } + + /** + * Get one of the tagger functions: hash or date + * @type {function} + */ + this.versionTagger = taggers[this.options.tag]; + + // is task a post versioning task? + this.isPostVersioningTask = grunt.config(this.getAssetsVersioningTaskConfigKey() + '.isPostVersioningTaskFor'); } /** @@ -55,13 +59,13 @@ AbstractVersioner.prototype.initialize = function () {}; * Set the property surrogateTasks */ AbstractVersioner.prototype.setSurrogateTasks = function () { - if (this.options.post) { - grunt.log.debug("Post-Versioning Mode"); - this.surrogateTasks = this.getPostVersioningSurrogateTasks(); - } else { - grunt.log.debug("Pre-Versioning Mode"); - this.surrogateTasks = this.getPreVersioningSurrogateTasks(); - } + if (this.options.post) { + grunt.log.debug("Post-Versioning Mode"); + this.surrogateTasks = this.getPostVersioningSurrogateTasks(); + } else { + grunt.log.debug("Pre-Versioning Mode"); + this.surrogateTasks = this.getPreVersioningSurrogateTasks(); + } }; /** @@ -69,7 +73,7 @@ AbstractVersioner.prototype.setSurrogateTasks = function () { * @abstract */ AbstractVersioner.prototype.getPostVersioningSurrogateTasks = function () { - throw new Error('Should be implemented by the subclass'); + throw new Error('Should be implemented by the subclass'); }; /** @@ -77,7 +81,7 @@ AbstractVersioner.prototype.getPostVersioningSurrogateTasks = function () { * @returns {Array} Array of tasks names */ AbstractVersioner.prototype.getPreVersioningSurrogateTasks = function () { - return this.getTargetTasks().map(this.createPreVersioningSurrogateTask.bind(this)); + return this.getTargetTasks().map(this.createPreVersioningSurrogateTask.bind(this)); }; /** @@ -85,13 +89,13 @@ AbstractVersioner.prototype.getPreVersioningSurrogateTasks = function () { * @returns {string} */ AbstractVersioner.prototype.createPostVersioningTask = function () { - var intermediateDestFiles = _.flatten(this.getTargetTasks().map(this.retrieveDestFiles.bind(this))); - grunt.log.debug("Retrieved all destination files: " + intermediateDestFiles.join(', ')); - var filesArray = intermediateDestFiles.map(function (destFile) { - return {src: [destFile], dest: destFile}; - }); - var task = new TaskClass(this.getAssetsVersioningTaskName(), filesArray); - return task.createPostVersioningTask(filesArray); + var intermediateDestFiles = _.flatten(this.getTargetTasks().map(this.retrieveDestFiles.bind(this))); + grunt.log.debug("Retrieved all destination files: " + intermediateDestFiles.join(', ')); + var filesArray = intermediateDestFiles.map(function (destFile) { + return {src: [destFile], dest: destFile}; + }); + var task = new TaskClass(this.getAssetsVersioningTaskName(), filesArray); + return task.createPostVersioningTask(filesArray); }; /** @@ -99,7 +103,7 @@ AbstractVersioner.prototype.createPostVersioningTask = function () { * @returns {string} */ AbstractVersioner.prototype.getAssetsVersioningTaskName = function () { - return this.taskData.name + ':' + this.taskData.target; + return this.taskData.name + ':' + this.taskData.target; }; /** @@ -107,7 +111,7 @@ AbstractVersioner.prototype.getAssetsVersioningTaskName = function () { * @returns {string} */ AbstractVersioner.prototype.getAssetsVersioningTaskConfigKey = function () { - return this.taskData.name + '.' + this.taskData.target; + return this.taskData.name + '.' + this.taskData.target; }; /** @@ -118,24 +122,24 @@ AbstractVersioner.prototype.getAssetsVersioningTaskConfigKey = function () { * @returns {*} */ AbstractVersioner.prototype.checkFilesObjValidity = function (filesObj, filesMapIndex, filesMapLength) { - grunt.log.debug("Iterating through file mapping - " + ( filesMapIndex + 1 ) + "/" + filesMapLength); + grunt.log.debug("Iterating through file mapping - " + ( filesMapIndex + 1 ) + "/" + filesMapLength); - var src = filesObj.src.filter(function (file) { - return grunt.file.isFile(file); - }); + var src = filesObj.src.filter(function (file) { + return grunt.file.isFile(file); + }); - grunt.log.debug('Source files: ', src); - if (src.length === 0) { - grunt.log.debug(JSON.stringify(filesObj.orig)); - return false; - } + grunt.log.debug('Source files: ', src); + if (src.length === 0) { + grunt.log.debug(JSON.stringify(filesObj.orig)); + return false; + } - if (typeof filesObj.dest !== 'string') { - grunt.log.debug(JSON.stringify(filesObj.orig)); - return false; - } + if (typeof filesObj.dest !== 'string') { + grunt.log.debug(JSON.stringify(filesObj.orig)); + return false; + } - return src; + return src; }; /** @@ -144,16 +148,16 @@ AbstractVersioner.prototype.checkFilesObjValidity = function (filesObj, filesMap * @returns {Array} */ AbstractVersioner.prototype.retrieveDestFiles = function (task) { - var destFiles = []; - var filesMapLength = task.taskFiles.length; - task.taskFiles.forEach(function(f, index) { - if (!this.checkFilesObjValidity(f, index, filesMapLength)) { return false; } - destFiles.push(f.dest); - }.bind(this)); - if (destFiles.length === 0) { - grunt.fail.warn("Task '" + task.taskName + "' has no destination files!"); - } - return destFiles; + var destFiles = []; + var filesMapLength = task.taskFiles.length; + task.taskFiles.forEach(function(f, index) { + if (!this.checkFilesObjValidity(f, index, filesMapLength)) { return false; } + destFiles.push(f.dest); + }.bind(this)); + if (destFiles.length === 0) { + grunt.fail.warn("Task '" + task.taskName + "' has no destination files!"); + } + return destFiles; }; /** @@ -162,71 +166,103 @@ AbstractVersioner.prototype.retrieveDestFiles = function (task) { */ AbstractVersioner.prototype.createPreVersioningSurrogateTask = function (task) { - var updatedTaskFiles = []; - var allVersionedPath = []; - - var filesMapLength = task.taskFiles.length; - var filesMapSkipCount = 0; - task.taskFiles.forEach(function(taskFilesObj, index) { - var src = this.checkFilesObjValidity(taskFilesObj, index, filesMapLength); - if (!src) { - filesMapSkipCount++; - return false; - } - - var version = this.versionTagger(src, this.options); - grunt.log.debug('Version tag (' + this.options.tag + '): ' + version); - - if (version === '') { - grunt.fail.warn("Failed at generating a version tag for " + taskFilesObj.dest, 1); - return false; - } - - var destFilePath = this.options.versionize.call(this, taskFilesObj.dest, version); - grunt.log.debug('Destination filename: ' + destFilePath); - - // push to the map of versions - - var versionedPath = destFilePath.replace(this.options.versionsMapTrimPath, ''); - if (_.contains(allVersionedPath, versionedPath)) { - grunt.fail.warn("Duplicate versioned path detected: '" + versionedPath +"'."); - } else { - allVersionedPath.push(versionedPath); - this.versionsMap.push({ - version: version, - originalPath: taskFilesObj.dest.replace(this.options.versionsMapTrimPath, ''), - versionedPath: slash(versionedPath) - }); - } - - // check if file already exists - if (this.options.skipExisting === true) { - grunt.log.debug('options.skipExisting is true, checking if destination file already exists.'); - if (grunt.file.exists(destFilePath)) { - grunt.log.debug('Destination file already exists. Task skipped.'); - return false; - } - grunt.log.debug("Destination file doesn't exist. Task will be processed."); - } else if (Array.isArray(this.options.skipExisting)) { - if (this.options.skipExisting.indexOf(destFilePath) !== -1) { - grunt.log.debug('Destination file listed in options.skipExisting. Task skipped'); - return false; - } - grunt.log.debug("Destination file not list in options.skipExisting. Task will be processed."); - } - - // log the src and dest data - updatedTaskFiles.push({ src: src, dest: destFilePath }); - - }.bind(this)); - - if (filesMapSkipCount === filesMapLength) { - grunt.fail.warn("File configuration for Task '" + task.taskName + "' is incorrect. Missing valid source files and/or destination files!"); - } - - grunt.log.debug("Versioned Files Object: ", updatedTaskFiles); - - return this.createSurrogateTask(updatedTaskFiles, task); + var updatedTaskFiles = []; + var allVersionedPath = []; + + var filesMapLength = task.taskFiles.length; + var filesMapSkipCount = 0; + task.taskFiles.forEach(function(taskFilesObj, index) { + var src = this.checkFilesObjValidity(taskFilesObj, index, filesMapLength); + if (!src) { + filesMapSkipCount++; + return false; + } + + var version = this.versionTagger(src, this.options); + grunt.log.debug('Version tag (' + this.options.tag + '): ' + version); + + if (version === '') { + grunt.fail.warn("Failed at generating a version tag for " + taskFilesObj.dest, 1); + return false; + } + + var destFilePath = this.options.versionize.call(this, taskFilesObj.dest, version, this.options.renameToVersion); + grunt.log.debug('Destination filename: ' + destFilePath); + + // push to the map of versions + + var versionedPath = destFilePath.replace(this.options.versionsMapTrimPath, ''); + if (_.includes(allVersionedPath, versionedPath)) { + grunt.fail.warn("Duplicate versioned path detected: '" + versionedPath +"'."); + } else { + if (this.options.versionsMapFilesAutoDelete === true) { + var versionsMapTrimPath = this.options.versionsMapTrimPath; + // delete items from the map and file system that we are about to re-create + this.versionsMap = this.versionsMap.filter(function (item) { + if (path.join(versionsMapTrimPath, item.originalPath) === taskFilesObj.dest) { + grunt.file.delete(path.join(versionsMapTrimPath, item.versionedPath)); + return false; + } else { + return true; + } + }); + } + allVersionedPath.push(versionedPath); + this.versionsMap.push({ + version: version, + originalPath: taskFilesObj.dest.replace(this.options.versionsMapTrimPath, ''), + versionedPath: slash(versionedPath) + }); + } + + // check if file already exists + if (this.options.skipExisting === true) { + grunt.log.debug('options.skipExisting is true, checking if destination file already exists.'); + if (grunt.file.exists(destFilePath)) { + grunt.log.debug('Destination file already exists. Task skipped.'); + return false; + } + grunt.log.debug("Destination file doesn't exist. Task will be processed."); + } else if (Array.isArray(this.options.skipExisting)) { + if (this.options.skipExisting.indexOf(destFilePath) !== -1) { + grunt.log.debug('Destination file listed in options.skipExisting. Task skipped'); + return false; + } + grunt.log.debug("Destination file not list in options.skipExisting. Task will be processed."); + } + + // log the src and dest data + updatedTaskFiles.push({src: src, dest: destFilePath}); + + }.bind(this)); + + // make sure there are no desinations that are also sources + var destinations = this.versionsMap.map(function (versionMap) { + return versionMap.versionedPath; + }); + this.versionsMap = this.versionsMap.filter(function (item) { + return !_.find(destinations, + function (destination) { + return destination === item.originalPath; + }); + }); + + if (filesMapSkipCount === filesMapLength) { + grunt.fail.warn("File configuration for Task '" + task.taskName + "' is incorrect. Missing valid source files and/or destination files!"); + } + + Object.keys(updatedTaskFiles).filter(function (key) { + updatedTaskFiles[key].src = updatedTaskFiles[key].src.filter(function (fileSrc) { + return grunt.file.exists(fileSrc); + }); + if (updatedTaskFiles[key].src.length === 0) { + delete updatedTaskFiles[key]; + } + }); + + grunt.log.debug("Versioned Files Object: ", updatedTaskFiles); + + return this.createSurrogateTask(updatedTaskFiles, task); }; /** @@ -234,39 +270,55 @@ AbstractVersioner.prototype.createPreVersioningSurrogateTask = function (task) { * and also optionally to a file */ AbstractVersioner.prototype.saveVersionsMap = function () { - if (this.options.post) { return; } - if (typeof this.options.versionsMapFile === "string") { - var versionsMapContent; - - // Are we generating a json file or are we using a template file? - var templateFile = this.options.versionsMapTemplate; - if (typeof templateFile === "string") { - if (!grunt.file.exists(templateFile)) { - - } - var template = grunt.util.normalizelf(grunt.file.read(templateFile, 'utf8')); - versionsMapContent = grunt.template.process(template, { - data: { - files: this.versionsMap - } - }).replace(/[\n]{2}/g,"\n"); - } else { - versionsMapContent = JSON.stringify(this.versionsMap); - } - grunt.file.write(this.options.versionsMapFile, versionsMapContent); - } - - grunt.config.set(this.getAssetsVersioningTaskConfigKey() + '.versionsMap', this.versionsMap); - //var originalTask = grunt.config(this.getAssetsVersioningTaskConfigKey() + '.isPostVersioningTaskFor'); - //if (typeof originalTask === 'string') { - // grunt.config.set(originalTask + '.versionsMap', this.versionsMap); - //} - - if (typeof this.isPostVersioningTask === 'string') { - grunt.config.set(this.isPostVersioningTask + '.versionsMap', this.versionsMap); - } - - grunt.log.debug("Versions Map: ", this.versionsMap); + if (this.options.post) { return; } + if (typeof this.options.versionsMapFile === "string") { + var versionsMapContent; + + // Are we generating a json file or are we using a template file? + var templateFile = this.options.versionsMapTemplate; + var template; + if (typeof templateFile === "function") { + // This could be a function that returns a string + template = templateFile(); + template = grunt.util.normalizelf(decodeURI(template)); + } + if (typeof templateFile === "string") { + if (!grunt.file.exists(templateFile)) { + // This could be a template + template = grunt.util.normalizelf(decodeURI(templateFile)); + } else { + template = grunt.util.normalizelf(grunt.file.read(templateFile, 'utf8')); + } + } + if (template != null) { + versionsMapContent = grunt.template.process(template, { + data: { + files: this.versionsMap + } + }).replace(/[\n]{2}/g, "\n"); + } + if (versionsMapContent == null || versionsMapContent === template) { + // We didn't make any template so far, use the default + versionsMapContent = JSON.stringify(this.versionsMap); + } + grunt.file.write(this.options.versionsMapFile, versionsMapContent); + } + + grunt.config.set(this.getAssetsVersioningTaskConfigKey() + '.versionsMap', this.versionsMap); + var originalTask = grunt.config(this.getAssetsVersioningTaskConfigKey() + '.isPostVersioningTaskFor'); + if (typeof originalTask === 'string') { + grunt.config.set(originalTask + '.versionsMap', this.versionsMap); + } + + if (typeof this.isPostVersioningTask === 'string') { + grunt.config.set(this.isPostVersioningTask + '.versionsMap', this.versionsMap); + } + + if (typeof this.options.versionsMapDataFile === 'string') { + grunt.file.write(this.options.versionsMapDataFile, JSON.stringify(this.versionsMap)); + } + + grunt.log.debug("Versions Map: ", this.versionsMap); }; /* ---- ABSTRACT METHODS ---- */ @@ -279,7 +331,7 @@ AbstractVersioner.prototype.saveVersionsMap = function () { * @returns {TaskClass} */ AbstractVersioner.prototype.getTargetTasks = function () { - throw new Error('Should be implemented by the subclass'); + throw new Error('Should be implemented by the subclass'); }; /** @@ -287,7 +339,7 @@ AbstractVersioner.prototype.getTargetTasks = function () { * @abstract */ AbstractVersioner.prototype.createSurrogateTask = function () { - throw new Error('Should be implemented by the subclass'); + throw new Error('Should be implemented by the subclass'); }; /** @@ -295,7 +347,7 @@ AbstractVersioner.prototype.createSurrogateTask = function () { * @abstract */ AbstractVersioner.prototype.doVersion = function () { - throw new Error('Should be implemented by the subclass'); + throw new Error('Should be implemented by the subclass'); }; module.exports = AbstractVersioner; diff --git a/test/assets_versioning_test.js b/test/assets_versioning_test.js index c618b04..2eb76ac 100755 --- a/test/assets_versioning_test.js +++ b/test/assets_versioning_test.js @@ -21,6 +21,19 @@ exports.assets_versioning = { test.done(); }, + options_tag_date_rename: function(test) { + test.expect(1); + + var versionsMap = grunt.config.get('assets_versioning.options_tag_date_rename.versionsMap'); + var expectedVersionsMap = [ + { version: '20140925013734', originalPath: 'tmp/js/js_bundle_a.js', versionedPath: 'tmp/js/20140925013734.js'}, + { version: '20140101080000', originalPath: 'tmp/js/js_bundle_b.js', versionedPath: 'tmp/js/20140101080000.js'} + ]; + + test.deepEqual(versionsMap, expectedVersionsMap, 'should create a map of versions with all versioned files'); + test.done(); + }, + options_timezoneOffset: function(test) { test.expect(1); @@ -52,8 +65,8 @@ exports.assets_versioning = { options_hashLength: function (test) { test.expect(2); - test.ok(grunt.file.exists('tmp/js/options_hashlength_a.3d04f3759854724f.js'), 'should create a versioned file with a 16 character long hash'); - test.equal(grunt.file.read('tmp/js/options_hashlength_a.3d04f3759854724f.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.ok(grunt.file.exists('tmp/js/options_hashlength_a.5042cab73cfe30e5.js'), 'should create a versioned file with a 16 character long hash'); + test.equal(grunt.file.read('tmp/js/options_hashlength_a.5042cab73cfe30e5.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); test.done(); }, @@ -68,7 +81,7 @@ exports.assets_versioning = { // when skipExisting=false, run the task anyway options_skipExisting_false: function (test) { test.expect(1); - test.notEqual(grunt.file.read('tmp/skip_existing_false.3d04f375.js'), grunt.file.read('test/expected/js/skip.js')); + test.notEqual(grunt.file.read('tmp/skip_existing_false.5042cab7.js'), grunt.file.read('test/expected/js/skip.js')); test.done(); }, @@ -81,17 +94,17 @@ exports.assets_versioning = { test.equal(grunt.file.read('tmp/js/skip_existing_array_1.3d04f375.js'), grunt.file.read('test/expected/js/skip.js')); // skip_ - test.notEqual(grunt.file.read('tmp/js/skip_existing_array_2.bfcf287e.js'), grunt.file.read('test/expected/js/skip.js')); - test.equal(grunt.file.read('tmp/js/skip_existing_array_2.bfcf287e.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.notEqual(grunt.file.read('tmp/js/skip_existing_array_2.5c726b9a.js'), grunt.file.read('test/expected/js/skip.js')); + test.equal(grunt.file.read('tmp/js/skip_existing_array_2.5c726b9a.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); test.done(); }, options_post_external: function (test) { test.expect(5); - test.ok(grunt.file.exists('tmp/js/options_post_a.27951afe.js'), 'should create a versioned file with a different hash'); - test.equal(grunt.file.read('tmp/js/options_post_a.27951afe.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); - test.equal(grunt.file.read('tmp/js/options_post_b.d3be530f.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.ok(grunt.file.exists('tmp/js/options_post_a.ccc03b4c.js'), 'should create a versioned file with a different hash'); + test.equal(grunt.file.read('tmp/js/options_post_a.ccc03b4c.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.equal(grunt.file.read('tmp/js/options_post_b.a7dd5963.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); var versionsMapAlt = grunt.config.get('assets_versioning.options_post_external_post_assets_versioning.versionsMap'); test.equal(versionsMapAlt.length, 2, 'map of versions should contain 2 entities'); @@ -105,10 +118,10 @@ exports.assets_versioning = { options_post_internal: function (test) { test.expect(6); - test.ok(grunt.file.exists('tmp/js/options_post_internal_a.27951afe.js'), 'should create a versioned file with a different hash'); - test.equal(grunt.file.read('tmp/js/options_post_internal_a.27951afe.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); - test.ok(grunt.file.exists('tmp/js/options_post_internal_b.d3be530f.js'), 'should create a second versioned file with a different hash'); - test.equal(grunt.file.read('tmp/js/options_post_internal_b.d3be530f.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.ok(grunt.file.exists('tmp/js/options_post_internal_a.efa0ffa4.js'), 'should create a versioned file with a different hash'); + test.equal(grunt.file.read('tmp/js/options_post_internal_a.efa0ffa4.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.ok(grunt.file.exists('tmp/js/options_post_internal_b.e4f3be42.js'), 'should create a second versioned file with a different hash'); + test.equal(grunt.file.read('tmp/js/options_post_internal_b.e4f3be42.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); var versionsMapAlt = grunt.config.get('assets_versioning.options_post_internal_post_assets_versioning.versionsMap'); test.equal(versionsMapAlt.length, 2, 'map of versions should contain 2 entities'); @@ -139,12 +152,52 @@ exports.assets_versioning = { test.done(); }, - options_versionsMapTemplate: function (test) { + options_versionsMapTemplateFail: function (test) { + test.expect(1); + + var actual = grunt.util.normalizelf(grunt.file.read('tmp/options_versionsMapTemplateFail.php')); + var expected = grunt.util.normalizelf(grunt.file.read('test/expected/output/options_output_trim.json')); + test.equal(actual, expected, 'should create a file using the default JSON template and the versions map data'); + + test.done(); + }, + + options_versionsMapTemplateFile: function (test) { + test.expect(1); + + var actual = grunt.util.normalizelf(grunt.file.read('tmp/options_versionsMapTemplateFile.php')); + var expected = grunt.util.normalizelf(grunt.file.read('test/expected/output/dict.php')); + test.equal(actual, expected, 'should create a file using a template from a file and the versions map data'); + + test.done(); + }, + + options_versionsMapTemplateString: function (test) { + test.expect(1); + + var actual = grunt.util.normalizelf(grunt.file.read('tmp/options_versionsMapTemplateString.php')); + var expected = grunt.util.normalizelf(grunt.file.read('test/expected/output/dict.php')); + test.equal(actual, expected, 'should create a file using a template from the provided string and the versions map data'); + + test.done(); + }, + + options_versionsMapTemplateFunction: function (test) { + test.expect(1); + + var actual = grunt.util.normalizelf(grunt.file.read('tmp/options_versionsMapTemplateFunction.php')); + var expected = grunt.util.normalizelf(grunt.file.read('test/expected/output/dict.php')); + test.equal(actual, expected, 'should create a file using a template returned by the function and the versions map data'); + + test.done(); + }, + + options_versionsMapDataFile: function (test) { test.expect(1); - var actual = grunt.file.read('tmp/options_versionsMapTemplate.php'); - var expected = grunt.file.read('test/expected/output/dict.php'); - test.equal(actual, expected, 'should create a file using a template and the versions map data'); + var actual = grunt.util.normalizelf(grunt.file.read('tmp/options_versionsMapDataFile.json')); + var expected = grunt.util.normalizelf(grunt.file.read('test/expected/output/options_output_trim.json')); + test.equal(actual, expected, 'should create a file data file representing the currently mapped files'); test.done(); }, @@ -153,7 +206,7 @@ exports.assets_versioning = { test.expect(2); test.ok(!grunt.file.exists('tmp/js/files_compact_format.js'), 'should not create an un-versioned file'); - test.ok(grunt.file.exists('tmp/js/files_compact_format.906eac86.js'), 'should create a versioned file'); + test.ok(grunt.file.exists('tmp/js/files_compact_format.94184eb4.js'), 'should create a versioned file'); test.done(); }, @@ -161,11 +214,11 @@ exports.assets_versioning = { files_object_format: function(test) { test.expect(4); - test.ok(grunt.file.exists('tmp/js/files_object_format_a.3d04f375.js'), 'should create a versioned a bundle.'); - test.ok(grunt.file.exists('tmp/js/files_object_format_b.bfcf287e.js'), 'should create a versioned b bundle.'); + test.ok(grunt.file.exists('tmp/js/files_object_format_a.5042cab7.js'), 'should create a versioned a bundle.'); + test.ok(grunt.file.exists('tmp/js/files_object_format_b.5c726b9a.js'), 'should create a versioned b bundle.'); - test.equal(grunt.file.read('tmp/js/files_object_format_a.3d04f375.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); - test.equal(grunt.file.read('tmp/js/files_object_format_b.bfcf287e.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.equal(grunt.file.read('tmp/js/files_object_format_a.5042cab7.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.equal(grunt.file.read('tmp/js/files_object_format_b.5c726b9a.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); test.done(); }, @@ -173,11 +226,11 @@ exports.assets_versioning = { files_array_format: function(test) { test.expect(4); - test.ok(grunt.file.exists('tmp/js/files_object_format_a.3d04f375.js'), 'should create a versioned default_a bundle.'); - test.ok(grunt.file.exists('tmp/js/files_object_format_b.bfcf287e.js'), 'should create a versioned default_b bundle.'); + test.ok(grunt.file.exists('tmp/js/files_object_format_a.5042cab7.js'), 'should create a versioned default_a bundle.'); + test.ok(grunt.file.exists('tmp/js/files_object_format_b.5c726b9a.js'), 'should create a versioned default_b bundle.'); - test.equal(grunt.file.read('tmp/js/files_object_format_a.3d04f375.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); - test.equal(grunt.file.read('tmp/js/files_object_format_b.bfcf287e.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.equal(grunt.file.read('tmp/js/files_object_format_a.5042cab7.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.equal(grunt.file.read('tmp/js/files_object_format_b.5c726b9a.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); test.done(); }, @@ -189,16 +242,16 @@ exports.assets_versioning = { test.equal(versionsMap.length, 4, 'map of versions should contain 4 entities'); test.ok(!grunt.file.exists('tmp/files_expand_format/folder/subfolder/img3.png'), 'should not create an un-versioned img3.png'); - test.ok(grunt.file.exists('tmp/files_expand_format/folder/subfolder/img3.f69ba99c.png'), 'should create a versioned img3.png'); + test.ok(grunt.file.exists('tmp/files_expand_format/folder/subfolder/img3.d8deeedb.png'), 'should create a versioned img3.png'); test.ok(!grunt.file.exists('tmp/files_expand_format/img1.png'), 'should not create an un-versioned img1.png'); - test.ok(grunt.file.exists('tmp/files_expand_format/img1.0aab5fd0.png'), 'should create a versioned img1.png'); + test.ok(grunt.file.exists('tmp/files_expand_format/img1.64317d28.png'), 'should create a versioned img1.png'); test.ok(!grunt.file.exists('tmp/files_expand_format/img2.jpg'), 'should not create an un-versioned img2.jpg'); - test.ok(grunt.file.exists('tmp/files_expand_format/img2.ec1bd0de.jpg'), 'should create a versioned img2.jpg'); + test.ok(grunt.file.exists('tmp/files_expand_format/img2.08abdf2a.jpg'), 'should create a versioned img2.jpg'); test.ok(!grunt.file.exists('tmp/files_expand_format/folder/img2.gif'), 'should not create an un-versioned img2.gif'); - test.ok(grunt.file.exists('tmp/files_expand_format/folder/img2.05953adc.gif'), 'should create a versioned img2.gif'); + test.ok(grunt.file.exists('tmp/files_expand_format/folder/img2.77e84a5f.gif'), 'should create a versioned img2.gif'); test.done(); }, @@ -218,13 +271,13 @@ exports.assets_versioning = { var versionsMap = grunt.config.get('assets_versioning.task_files_compact_format.versionsMap'); var expectedVersionsMap = [ { - version: '906eac86', versionedPath: 'tmp/js/task_files_compact_format.906eac86.js', originalPath: 'tmp/js/task_files_compact_format.js' + version: '94184eb4', versionedPath: 'tmp/js/task_files_compact_format.94184eb4.js', originalPath: 'tmp/js/task_files_compact_format.js' } ]; test.deepEqual(versionsMap, expectedVersionsMap, 'should set a config object listing all files'); test.ok(!grunt.file.exists('tmp/js/task_files_compact_format.js'), 'should not create an un-versioned file'); - test.ok(grunt.file.exists('tmp/js/task_files_compact_format.906eac86.js'), 'should create a versioned file'); + test.ok(grunt.file.exists('tmp/js/task_files_compact_format.94184eb4.js'), 'should create a versioned file'); test.done(); }, @@ -232,11 +285,11 @@ exports.assets_versioning = { task_files_object_format: function(test) { test.expect(4); - test.ok(grunt.file.exists('tmp/js/task_files_object_format_a.3d04f375.js'), 'should create a versioned a bundle.'); - test.ok(grunt.file.exists('tmp/js/task_files_object_format_b.bfcf287e.js'), 'should create a versioned b bundle.'); + test.ok(grunt.file.exists('tmp/js/task_files_object_format_a.5042cab7.js'), 'should create a versioned a bundle.'); + test.ok(grunt.file.exists('tmp/js/task_files_object_format_b.5c726b9a.js'), 'should create a versioned b bundle.'); - test.equal(grunt.file.read('tmp/js/task_files_object_format_a.3d04f375.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); - test.equal(grunt.file.read('tmp/js/task_files_object_format_b.bfcf287e.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.equal(grunt.file.read('tmp/js/task_files_object_format_a.5042cab7.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.equal(grunt.file.read('tmp/js/task_files_object_format_b.5c726b9a.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); test.done(); }, @@ -244,11 +297,11 @@ exports.assets_versioning = { task_files_array_format: function(test) { test.expect(4); - test.ok(grunt.file.exists('tmp/js/task_files_array_format_a.3d04f375.js'), 'should create a versioned a bundle.'); - test.ok(grunt.file.exists('tmp/js/task_files_array_format_b.bfcf287e.js'), 'should create a versioned b bundle.'); + test.ok(grunt.file.exists('tmp/js/task_files_array_format_a.5042cab7.js'), 'should create a versioned a bundle.'); + test.ok(grunt.file.exists('tmp/js/task_files_array_format_b.5c726b9a.js'), 'should create a versioned b bundle.'); - test.equal(grunt.file.read('tmp/js/task_files_array_format_a.3d04f375.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); - test.equal(grunt.file.read('tmp/js/task_files_array_format_b.bfcf287e.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.equal(grunt.file.read('tmp/js/task_files_array_format_a.5042cab7.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.equal(grunt.file.read('tmp/js/task_files_array_format_b.5c726b9a.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); test.done(); }, @@ -260,16 +313,16 @@ exports.assets_versioning = { test.equal(versionsMap.length, 4, 'map of versions should contain 4 entities'); test.ok(!grunt.file.exists('tmp/task_files_expand_format/folder/subfolder/img3.png'), 'should not create an un-versioned img3.png'); - test.ok(grunt.file.exists('tmp/task_files_expand_format/folder/subfolder/img3.f69ba99c.png'), 'should create a versioned img3.png'); + test.ok(grunt.file.exists('tmp/task_files_expand_format/folder/subfolder/img3.d8deeedb.png'), 'should create a versioned img3.png'); test.ok(!grunt.file.exists('tmp/task_files_expand_format/img1.png'), 'should not create an un-versioned img1.png'); - test.ok(grunt.file.exists('tmp/task_files_expand_format/img1.0aab5fd0.png'), 'should create a versioned img1.png'); + test.ok(grunt.file.exists('tmp/task_files_expand_format/img1.64317d28.png'), 'should create a versioned img1.png'); test.ok(!grunt.file.exists('tmp/task_files_expand_format/img2.jpg'), 'should not create an un-versioned img2.jpg'); - test.ok(grunt.file.exists('tmp/task_files_expand_format/img2.ec1bd0de.jpg'), 'should create a versioned img2.jpg'); + test.ok(grunt.file.exists('tmp/task_files_expand_format/img2.08abdf2a.jpg'), 'should create a versioned img2.jpg'); test.ok(!grunt.file.exists('tmp/task_files_expand_format/folder/img2.gif'), 'should not create an un-versioned img2.gif'); - test.ok(grunt.file.exists('tmp/task_files_expand_format/folder/img2.05953adc.gif'), 'should create a versioned img2.gif'); + test.ok(grunt.file.exists('tmp/task_files_expand_format/folder/img2.77e84a5f.gif'), 'should create a versioned img2.gif'); test.done(); }, @@ -280,11 +333,11 @@ exports.assets_versioning = { test.equal(versionsMap.length, 5, 'should accumulate all the files created by all the tasks'); - test.equal(grunt.file.read('tmp/js/multiple_task_2.906eac86.js'), grunt.file.read('test/expected/js/concat_file1_file2_file3.js')); - test.equal(grunt.file.read('tmp/js/multiple_task_1_a.3d04f375.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); - test.equal(grunt.file.read('tmp/js/multiple_task_1_b.bfcf287e.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); - test.equal(grunt.file.read('tmp/js/multiple_task_3_a.3d04f375.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); - test.equal(grunt.file.read('tmp/js/multiple_task_3_b.bfcf287e.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.equal(grunt.file.read('tmp/js/multiple_task_2.94184eb4.js'), grunt.file.read('test/expected/js/concat_file1_file2_file3.js')); + test.equal(grunt.file.read('tmp/js/multiple_task_1_a.5042cab7.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.equal(grunt.file.read('tmp/js/multiple_task_1_b.5c726b9a.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.equal(grunt.file.read('tmp/js/multiple_task_3_a.5042cab7.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.equal(grunt.file.read('tmp/js/multiple_task_3_b.5c726b9a.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); test.done(); }, @@ -295,23 +348,23 @@ exports.assets_versioning = { var versionsMap = grunt.config.get('assets_versioning.files_default_behaviour.versionsMap'); var expectedVersionsMap = [ - { version: '3d04f375', - versionedPath: 'tmp/js/default_a.3d04f375.js', + { version: '5042cab7', + versionedPath: 'tmp/js/default_a.5042cab7.js', originalPath: 'tmp/js/default_a.js' }, { - version: 'bfcf287e', - versionedPath: 'tmp/js/default_b.bfcf287e.js', + version: '5c726b9a', + versionedPath: 'tmp/js/default_b.5c726b9a.js', originalPath: 'tmp/js/default_b.js' } ]; test.deepEqual(versionsMap, expectedVersionsMap, 'should set a config object listing all files'); - test.ok(grunt.file.exists('tmp/js/default_a.3d04f375.js'), 'should create a versioned default_a bundle.'); - test.ok(grunt.file.exists('tmp/js/default_b.bfcf287e.js'), 'should create a versioned default_b bundle.'); + test.ok(grunt.file.exists('tmp/js/default_a.5042cab7.js'), 'should create a versioned default_a bundle.'); + test.ok(grunt.file.exists('tmp/js/default_b.5c726b9a.js'), 'should create a versioned default_b bundle.'); - test.equal(grunt.file.read('tmp/js/default_a.3d04f375.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); - test.equal(grunt.file.read('tmp/js/default_b.bfcf287e.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); + test.equal(grunt.file.read('tmp/js/default_a.5042cab7.js'), grunt.file.read('test/expected/js/concat_file1_file2.js')); + test.equal(grunt.file.read('tmp/js/default_b.5c726b9a.js'), grunt.file.read('test/expected/js/concat_file3_file4.js')); test.done(); }, diff --git a/test/expected/output/dict.php b/test/expected/output/dict.php index 72d1463..f6660bd 100644 --- a/test/expected/output/dict.php +++ b/test/expected/output/dict.php @@ -2,9 +2,9 @@ class MyDict { public static $myDict = array( - "folder/subfolder/img3.png" => "folder/subfolder/img3.f69ba99c.png", - "img1.png" => "img1.0aab5fd0.png", - "img2.jpg" => "img2.ec1bd0de.jpg", - "folder/img2.gif" => "folder/img2.05953adc.gif", + "folder/subfolder/img3.png" => "folder/subfolder/img3.d8deeedb.png", + "img1.png" => "img1.64317d28.png", + "img2.jpg" => "img2.08abdf2a.jpg", + "folder/img2.gif" => "folder/img2.77e84a5f.gif", ); } diff --git a/test/expected/output/options_output.json b/test/expected/output/options_output.json index 26ed8fb..4da550e 100644 --- a/test/expected/output/options_output.json +++ b/test/expected/output/options_output.json @@ -1 +1 @@ -[{"version":"f69ba99c","originalPath":"tmp/options_output/folder/subfolder/img3.png","versionedPath":"tmp/options_output/folder/subfolder/img3.f69ba99c.png"},{"version":"0aab5fd0","originalPath":"tmp/options_output/img1.png","versionedPath":"tmp/options_output/img1.0aab5fd0.png"},{"version":"ec1bd0de","originalPath":"tmp/options_output/img2.jpg","versionedPath":"tmp/options_output/img2.ec1bd0de.jpg"},{"version":"05953adc","originalPath":"tmp/options_output/folder/img2.gif","versionedPath":"tmp/options_output/folder/img2.05953adc.gif"}] +[{"version":"d8deeedb","originalPath":"tmp/options_output/folder/subfolder/img3.png","versionedPath":"tmp/options_output/folder/subfolder/img3.d8deeedb.png"},{"version":"64317d28","originalPath":"tmp/options_output/img1.png","versionedPath":"tmp/options_output/img1.64317d28.png"},{"version":"08abdf2a","originalPath":"tmp/options_output/img2.jpg","versionedPath":"tmp/options_output/img2.08abdf2a.jpg"},{"version":"77e84a5f","originalPath":"tmp/options_output/folder/img2.gif","versionedPath":"tmp/options_output/folder/img2.77e84a5f.gif"}] \ No newline at end of file diff --git a/test/expected/output/options_output_trim.json b/test/expected/output/options_output_trim.json index 26f4816..a4f614f 100644 --- a/test/expected/output/options_output_trim.json +++ b/test/expected/output/options_output_trim.json @@ -1 +1 @@ -[{"version":"f69ba99c","originalPath":"folder/subfolder/img3.png","versionedPath":"folder/subfolder/img3.f69ba99c.png"},{"version":"0aab5fd0","originalPath":"img1.png","versionedPath":"img1.0aab5fd0.png"},{"version":"ec1bd0de","originalPath":"img2.jpg","versionedPath":"img2.ec1bd0de.jpg"},{"version":"05953adc","originalPath":"folder/img2.gif","versionedPath":"folder/img2.05953adc.gif"}] +[{"version":"d8deeedb","originalPath":"folder/subfolder/img3.png","versionedPath":"folder/subfolder/img3.d8deeedb.png"},{"version":"64317d28","originalPath":"img1.png","versionedPath":"img1.64317d28.png"},{"version":"08abdf2a","originalPath":"img2.jpg","versionedPath":"img2.08abdf2a.jpg"},{"version":"77e84a5f","originalPath":"folder/img2.gif","versionedPath":"folder/img2.77e84a5f.gif"}] \ No newline at end of file