Skip to content

Commit

Permalink
Merge pull request #10 from vHeemstra/patch-2
Browse files Browse the repository at this point in the history
Added support for multiple files & fix for multiple dependencies
  • Loading branch information
raulghm committed Mar 10, 2019
2 parents 3a133af + 77fbf7b commit 963200f
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions index.js
Expand Up @@ -28,16 +28,25 @@ module.exports = function (options) {

file.contents = new Buffer(String(file.contents));

if (options.css && options.cssHandle) {
var regexCss = new RegExp("(wp_(?:register|enqueue)_style\\(\\s?'" + options.cssHandle + "',(\\s*[^,]+,){2})\\s*[^,]+(,\\s*[^\\)]+)?\\);");
var hashCss = md5(options.css);
file.contents = new Buffer(String(file.contents).replace(regexCss, "$1 '" + hashCss + "'$3);"));
}

if (options.js && options.jsHandle) {
var regexJs = new RegExp("(wp_(?:register|enqueue)_script\\(\\s?'" + options.jsHandle + "',(\\s*[^,]+,){2})\\s*[^,]+(,\\s*[^\\)]+)?\\);");
var hashJs = md5(options.js);
file.contents = new Buffer(String(file.contents).replace(regexJs, "$1 '" + hashJs + "'$3);"));
if (options && options.length > 0) {
for (var i = 0; i < options.length; i++) {
if (options[ i ].file && options[ i ].handle && options[ i ].type) {
switch (options[ i ].type) {
case 'css':
var regexCss = new RegExp("(wp_(?:register|enqueue)_style\\(\\s?'" + options[ i ].handle + "',(\\s*[^,]+,){2})\\s*[^,]+(,\\s*[^\\)]+)?\\);");
var hashCss = md5(options[ i ].file);
file.contents = new Buffer(String(file.contents).replace(regexCss, "$1 '" + hashCss + "'$3);"));
break;
case 'js':
var regexJs = new RegExp("(wp_(?:register|enqueue)_script\\(\\s?'" + options[ i ].handle + "',(\\s*[^,]+,\\s*.+,))\\s*'[a-zA-Z0-9]+'\\s*(,\\s*[^\\)]+)?\\);");
var hashJs = md5(options[ i ].file);
file.contents = new Buffer(String(file.contents).replace(regexJs, "$1 '" + hashJs + "'$3);"));
break;
default:
break;
}
}
}
}

this.push(file);
Expand Down

0 comments on commit 963200f

Please sign in to comment.