grunt-replace-dojo-cache
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "grunt-replace-dojo-cache", | ||
"description": "Replace calls to dojo.cache in JavaScript source with the contents of the referred file.", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"homepage": "https://github.com/bvanreeven/grunt-replace-dojo-cache", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -68,3 +68,4 @@ # grunt-replace-dojo-cache | ||
## Release History | ||
* 2013-04-25 v0.1.2 Remove `dojo.require("dojo.cache");` calls to prevent unnecessary requests. | ||
* 2013-04-21 v0.1.1 Added support for multiple dots in the package name. | ||
* 2013-04-21 v0.1.0 Initial version. |
@@ -24,16 +24,10 @@ /* | ||
// Iterate over all specified file groups. | ||
this.files.forEach(function (f) { | ||
if (f.src.length !== 1) { | ||
grunt.fail.fatal("Must specify exactly one source file per destination."); | ||
return; | ||
} | ||
var replaceRequires = function (src) { | ||
var regex = /^\s*dojo\.require\(['"]dojo\.cache['"]\);$/gm; | ||
return src.replace(regex, ""); | ||
}; | ||
if (!grunt.file.exists(f.src[0])) { | ||
grunt.fail.fatal('Source file "' + f.src[0] + '" not found.'); | ||
return; | ||
} | ||
var replaceCalls = function (src) { | ||
var regex = /dojo\.cache\(['"]([a-zA-Z.]+)['"]\s*,\s*['"]([a-zA-Z.]+)['"]\)/g; | ||
var src = grunt.file.read(f.src[0]).replace(regex, function (match, packageName, fileName) { | ||
return src.replace(regex, function (match, packageName, fileName) { | ||
@@ -52,3 +46,20 @@ var cacheFilePath = path.join(options.basePath, packageName.replace(/\./g, "/"), fileName); | ||
}); | ||
}; | ||
// Iterate over all specified file groups. | ||
this.files.forEach(function (f) { | ||
if (f.src.length !== 1) { | ||
grunt.fail.fatal("Must specify exactly one source file per destination."); | ||
return; | ||
} | ||
if (!grunt.file.exists(f.src[0])) { | ||
grunt.fail.fatal('Source file "' + f.src[0] + '" not found.'); | ||
return; | ||
} | ||
var src = grunt.file.read(f.src[0]); | ||
src = replaceRequires(src); | ||
src = replaceCalls(src); | ||
// Write the destination file. | ||
@@ -55,0 +66,0 @@ grunt.file.write(f.dest, src); |
@@ -5,3 +5,2 @@ /*jslint indent: 4, forin: true */ | ||
dojo.require("dojo.cache"); | ||
dojo.require("dojo.NodeList-traverse"); | ||
@@ -8,0 +7,0 @@ dojo.require("buzz.widget.lib.mustache"); |
@@ -5,3 +5,2 @@ /*jslint indent: 4, forin: true */ | ||
dojo.require("dojo.cache"); | ||
dojo.require("dojo.NodeList-traverse"); | ||
@@ -8,0 +7,0 @@ dojo.require("buzz.widget.lib.mustache"); |
@@ -5,3 +5,2 @@ /*jslint indent: 4, forin: true */ | ||
dojo.require("dojo.cache"); | ||
dojo.require("dojo.NodeList-traverse"); | ||
@@ -8,0 +7,0 @@ dojo.require("buzz.widget.lib.mustache"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13056
236
70