Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Commit

Permalink
support files array format
Browse files Browse the repository at this point in the history
  • Loading branch information
hariadi committed Feb 20, 2014
1 parent 8129d8b commit 5e21a44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
27 changes: 14 additions & 13 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ module.exports = function(grunt) {

version: {
assets: {
src: ['test/fixtures/assets/css/main.min.css',
'test/fixtures/assets/js/scripts.min.js'],
dest: 'test/fixtures/script2.php'
// Files Array Format
files: {
'test/fixtures/script2.php': ['test/fixtures/assets/css/main.min.css', 'test/fixtures/assets/js/scripts.min.js']
}
},
withConfig: {
options: {
format: true,
algorithm: 'sha1',
length: 8
},
// Compact Format
src: ['test/fixtures/assets/css/main.min.css',
'test/fixtures/assets/js/scripts.min.js'],
dest: 'test/fixtures/index.html'
Expand All @@ -40,29 +42,28 @@ module.exports = function(grunt) {
script: 'roots_scripts'
}
},
src: ['test/fixtures/assets/css/main.min.css',
'test/fixtures/assets/js/scripts.min.js'],
dest: 'test/fixtures/lib/scripts2.php'
files: {
'test/fixtures/lib/scripts2.php': 'test/fixtures/assets/{css,js}/{main,scripts}.min.{css,js}'
}
},
rootsWithoutQuerystring: {
options: {
format: true,
length: 8
},
src: ['test/fixtures/assets/css/main.min.css',
'test/fixtures/assets/js/scripts.min.js'],
dest: 'test/fixtures/lib/scripts.php'
files: {
'test/fixtures/lib/scripts.php': ['test/fixtures/assets/css/main.min.css', 'test/fixtures/assets/js/scripts.min.js']
}
},

withoutFormat2times: {
options: {
length: 8,
algorithm: 'sha1'
},
src: ['test/fixtures/assets/css/main.min.css',
'test/fixtures/assets/js/scripts.min.js'],
dest: 'test/fixtures/lib/scripts3.php'

files: {
'test/fixtures/lib/scripts3.php': ['test/fixtures/assets/css/main.min.css', 'test/fixtures/assets/js/scripts.min.js']
}
}
},

Expand Down
9 changes: 4 additions & 5 deletions tasks/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = function(grunt) {

grunt.registerMultiTask('version', 'WordPress assets revving', function() {

var dest = this.data.dest;
var options = this.options({
encoding: 'utf8',
algorithm: 'md5',
Expand All @@ -44,7 +43,7 @@ module.exports = function(grunt) {
} else {
return true;
}
}).forEach(function(file) {
}).map(function(file) {

var basename = path.basename,
original = basename(file),
Expand All @@ -62,7 +61,7 @@ module.exports = function(grunt) {
[basename(file, ext), suffix, ext.slice(1)].join('.');

// Get target, find and change references assets to new hashed.
var wpcontent = grunt.file.read(dest), match, re;
var wpcontent = grunt.file.read(files.dest), match, re;

if (querystring) {

Expand All @@ -79,7 +78,7 @@ module.exports = function(grunt) {
}

wpcontent = wpcontent.replace(re, newName);
grunt.log.writeln(' ' + dest.grey + ' update to ' + name.green + ' ('+ suffix.grey +')');
grunt.log.writeln(' ' + files.dest.grey + ' update to ' + name.green + ' ('+ suffix.grey +')');
} else {

// Copy/rename file base on hash and format
Expand All @@ -104,7 +103,7 @@ module.exports = function(grunt) {
var status = (options.rename) ? ' rename' : ' change';
grunt.log.writeln(' ' + file.grey + status + ' to ' + newName.green);
}
grunt.file.write(dest, wpcontent);
grunt.file.write(files.dest, wpcontent);

});
next();
Expand Down

0 comments on commit 5e21a44

Please sign in to comment.