asset-smasher
Advanced tools
Comparing version 0.2.9 to 0.2.10
# Asset Smasher Changelog | ||
## 0.2.10 (April 29, 2013) | ||
- Ensure assets required by a manifest are of the right type. (Fixes #15) | ||
## 0.2.9 (April 29, 2013) | ||
@@ -4,0 +8,0 @@ |
@@ -33,2 +33,33 @@ /** | ||
/** | ||
* Get the "type" of the manifest - e.g. '.js', '.css' | ||
*/ | ||
function getManifestBaseType(manifest) { | ||
return path.extname(path.basename(manifest.assetFilePath, '.mf')); | ||
} | ||
/** | ||
* Checks that the file has the specified type in one of its extensions | ||
* | ||
* E.g. | ||
* | ||
* hasFileType('foo.js.dust.ejs', '.js') => true | ||
* hasFileType('foo.css.less', '.js') => false | ||
* hasFileType('foo.css.less', '.css') => true | ||
* | ||
*/ | ||
function hasFileType(file, fileExt) { | ||
file = path.basename(file); | ||
var ext = path.extname(file); | ||
do { | ||
if (ext === fileExt) { | ||
return true; | ||
} else { | ||
file = path.basename(file, ext); | ||
ext = path.extname(file); | ||
} | ||
} while (ext); | ||
return false; | ||
} | ||
var ManifestWalker = exports.ManifestWalker = function ManifestWalker(options) { | ||
@@ -136,9 +167,9 @@ options = options || {}; | ||
if (file.match(ABSOLUTE_PATH)) { | ||
this.resolveFile(file, '', afterResolve); | ||
this.resolveFile(manifest, file, '', afterResolve); | ||
} else if (file.match(RELATIVE_PATH)) { | ||
this.resolveFile(file, manifestDir, afterResolve); | ||
this.resolveFile(manifest, file, manifestDir, afterResolve); | ||
} else { | ||
async.eachSeries(this.paths, function (p, eachCb) { | ||
setImmediateCompat(function () { | ||
self.resolveFile(file, p, function (e, f) { | ||
self.resolveFile(manifest, file, p, function (e, f) { | ||
if (e) { | ||
@@ -163,2 +194,3 @@ eachCb(e); | ||
var manifestFilePath = manifest.assetFilePath; | ||
var manifestBaseType = getManifestBaseType(manifest); | ||
var dirPath; | ||
@@ -188,3 +220,7 @@ var self = this; | ||
var extn = path.extname(f); | ||
if (filePath !== manifestFilePath && _.contains(self.extensions, extn)) { | ||
if (filePath !== manifestFilePath && | ||
// It is one of our supported extensions to transform | ||
_.contains(self.extensions, extn) && | ||
// One of its extensions is the manifest type | ||
hasFileType(filePath, manifestBaseType)) { | ||
self.registerRequiredAsset(manifest, assetBundle, filePath, eachCb); | ||
@@ -201,2 +237,3 @@ } else { | ||
var manifestFilePath = manifest.assetFilePath; | ||
var manifestBaseType = getManifestBaseType(manifest); | ||
var dirPath; | ||
@@ -219,3 +256,7 @@ var self = this; | ||
var extn = path.extname(f); | ||
if (f !== manifestFilePath && _.contains(self.extensions, extn)) { | ||
if (f !== manifestFilePath && | ||
// It is one of our supported extensions to transform | ||
_.contains(self.extensions, extn) && | ||
// One of its extensions is the manifest type | ||
hasFileType(f, manifestBaseType)) { | ||
self.registerRequiredAsset(manifest, assetBundle, f, eachCb); | ||
@@ -246,3 +287,4 @@ } else { | ||
}, | ||
resolveFile:function (file, dir, cb) { | ||
resolveFile:function (manifest, file, dir, cb) { | ||
var manifestBaseType = getManifestBaseType(manifest); | ||
var filePath = path.join(dir, file); | ||
@@ -271,14 +313,17 @@ var fileDir = path.dirname(filePath); | ||
var found = false; | ||
if (lookupBase === fBase) { | ||
found = true; | ||
} else { | ||
var extn; | ||
do { | ||
extn = path.extname(fBase); | ||
fBase = path.basename(fBase, extn); | ||
if (lookupBase === fBase) { | ||
found = true; | ||
break; | ||
} | ||
} while (_.contains(self.extensions, extn)); | ||
// If the file is of the right type for this manifest | ||
if (hasFileType(fBase, manifestBaseType)) { | ||
if (lookupBase === fBase) { | ||
found = true; | ||
} else { | ||
var extn; | ||
do { | ||
extn = path.extname(fBase); | ||
fBase = path.basename(fBase, extn); | ||
if (lookupBase === fBase) { | ||
found = true; | ||
break; | ||
} | ||
} while (_.contains(self.extensions, extn) && hasFileType(fBase, manifestBaseType)); | ||
} | ||
} | ||
@@ -285,0 +330,0 @@ if (found) { |
{ | ||
"name": "asset-smasher", | ||
"description": "Asset pre-processor, merger, and compressor.", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"author": "Jim Riecken <jriecken@gmail.com>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -96,2 +96,4 @@ # Asset Smasher | ||
Only files that will be transformed down to a file of a manifest's "type" (e.g. `manifest.css.mf` => `.css`, `manifest.js.mf` => `.js`) will be included. This means that, for example, if you `require_dir` a directory in a JavaScript manifest that happens to contain both JavaScript and CSS, only the JavaScript files will be required. | ||
A simple manifest file might look like | ||
@@ -132,3 +134,3 @@ | ||
<li> | ||
If the file does not exist/can't be resolved, it will be ignored (will be logged in verbose mode). | ||
If the file does not exist/can't be resolved/isn't of the right type for the manifest, it will be ignored (will be logged in verbose mode). | ||
</li> | ||
@@ -151,6 +153,2 @@ </ul> | ||
<li> | ||
Make sure the directory only contains assets of the type you want. E.g. for <code>myManifest.js.mf</code>, the dir required had better | ||
only contain javascript files, or else bad things will happen. | ||
</li> | ||
<li> | ||
If the directory does not exist, it will be ignored (will be logged in verbose mode). | ||
@@ -157,0 +155,0 @@ </li> |
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
88616
2031
441