assets-expander
Advanced tools
Comparing version 0.2.3 to 0.3.0
@@ -0,1 +1,6 @@ | ||
0.3.0 / 2012-07-09 | ||
================== | ||
* Removed 'rightjs' dependency as it's an overkill to use it. | ||
0.2.3 / 2012-06-17 | ||
@@ -2,0 +7,0 @@ ================== |
var fs = require('fs'), | ||
path = require('path'), | ||
yaml = require('../vendor/yaml'), | ||
rightjs = require('rightjs'); | ||
yaml = require('../vendor/yaml'); | ||
@@ -34,12 +33,16 @@ var AssetsExpander = function(pathToYaml, options) { | ||
if (asset.includes('**/*')) { | ||
if (asset.indexOf('**/*') > -1) { | ||
var prefix = asset.substring(0, asset.indexOf('**/*')); | ||
matches.push(self._scanDir(path.join(root, prefix), '*', true, options.type)); | ||
} else if (asset.includes('*')) { | ||
self._scanDir(path.join(root, prefix), '*', true, options.type).forEach(function(matched) { | ||
matches.push(matched); | ||
}); | ||
} else if (asset.indexOf('*') > -1) { | ||
var prefix = ''; | ||
if (asset.indexOf('/') >= 0) { | ||
if (asset.indexOf('/') > -1) { | ||
prefix = asset.substring(0, asset.lastIndexOf('/')); | ||
asset = asset.substring(prefix.length + 1); | ||
} | ||
matches.push(self._scanDir(path.join(root, prefix), asset, false, options.type)); | ||
self._scanDir(path.join(root, prefix), asset, false, options.type).forEach(function(matched) { | ||
matches.push(matched); | ||
}); | ||
} else { | ||
@@ -54,5 +57,5 @@ var expanded = path.join(root, asset) + '.' + options.type; | ||
var expandGroup = function(root, group) { | ||
var groupAssetsExpander = []; | ||
var groupAssets = []; | ||
if (group.includes('[')) { | ||
if (group.indexOf('[') > -1) { | ||
var tokens = group.split(/[\[\]]/); | ||
@@ -64,12 +67,11 @@ root = path.join(root, tokens[0]); | ||
group.split(',').forEach(function(asset) { | ||
var expanded = expandAsset(root, asset); | ||
if (expanded.length == 0) return; | ||
groupAssetsExpander.push(expanded); | ||
expandAsset(root, asset).forEach(function(expanded) { | ||
groupAssets.push(expanded); | ||
}); | ||
}); | ||
return groupAssetsExpander; | ||
return groupAssets; | ||
}; | ||
return expandGroup(options.root, mainGroup).flatten().uniq(); | ||
return expandGroup(options.root, mainGroup).unique(); | ||
}, | ||
@@ -92,12 +94,14 @@ | ||
var processLevel = function(levelDefinition, levelOptions) { | ||
if (rightjs.isString(levelDefinition)) { | ||
assets.push(self.processList(levelDefinition, levelOptions)); | ||
} else if (rightjs.isHash(levelDefinition)) { | ||
if (typeof levelDefinition == 'string') { | ||
self.processList(levelDefinition, levelOptions).forEach(function(asset) { | ||
assets.push(asset); | ||
}); | ||
} else if (levelDefinition instanceof Array) { | ||
levelDefinition.forEach(function(value) { | ||
processLevel(value, levelOptions); | ||
}); | ||
} else { // Hash | ||
Object.each(levelDefinition, function(key, value) { | ||
processLevel(value, Object.merge(levelOptions, { root: path.join(levelOptions.root, key) })); | ||
}); | ||
} else { // Array | ||
levelDefinition.each(function(value) { | ||
processLevel(value, levelOptions); | ||
}); | ||
} | ||
@@ -108,3 +112,3 @@ }; | ||
return assets.flatten().uniq(); | ||
return assets.unique(); | ||
}, | ||
@@ -133,3 +137,5 @@ | ||
dirs.forEach(function(dir) { | ||
matches.push(self._scanDir(dir, '*', true, extension)); | ||
self._scanDir(dir, '*', true, extension).forEach(function(match) { | ||
matches.push(match); | ||
}); | ||
}); | ||
@@ -169,2 +175,34 @@ } | ||
module.exports = AssetsExpander; | ||
module.exports = AssetsExpander; | ||
// Core extensions | ||
Array.prototype.unique = function() { | ||
var uniques = []; | ||
this.forEach(function(value) { | ||
if (uniques.indexOf(value) == -1) | ||
uniques.push(value); | ||
}); | ||
return uniques; | ||
}; | ||
Object.each = function(object, callback, scope) { | ||
for (var key in object) { | ||
callback.call(scope, key, object[key]); | ||
} | ||
}; | ||
Object.clone = function(object) { | ||
var clone = {}; | ||
Object.each(object, function(key, value) { | ||
clone[key] = value; | ||
}); | ||
return clone; | ||
}; | ||
Object.merge = function(object1, object2) { | ||
var target = Object.clone(object1); | ||
Object.each(object2, function(key, value) { | ||
target[key] = value; | ||
}); | ||
return target; | ||
}; |
@@ -11,7 +11,4 @@ { | ||
}, | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"main": "index.js", | ||
"dependencies": { | ||
"rightjs": "2.2.x" | ||
}, | ||
"devDependencies": { | ||
@@ -18,0 +15,0 @@ "vows": "*" |
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
26841
0
730
- Removedrightjs@2.2.x
- Removedrightjs@2.2.3(transitive)