Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed unnecessary rightjs dependency.

  • Loading branch information...
commit 9932f30332bdfebd0f2d2161ed1dacc82e4ca82b 1 parent ee8f97f
@jakubpawlowicz authored
Showing with 63 additions and 28 deletions.
  1. +63 −25 lib/assets.js
  2. +0 −3  package.json
View
88 lib/assets.js
@@ -1,7 +1,6 @@
var fs = require('fs'),
path = require('path'),
- yaml = require('../vendor/yaml'),
- rightjs = require('rightjs');
+ yaml = require('../vendor/yaml');
var AssetsExpander = function(pathToYaml, options) {
if (!pathToYaml) return;
@@ -31,16 +30,20 @@ AssetsExpander.prototype = {
var expandAsset = function(root, asset) {
var matches = [];
- 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 {
var expanded = path.join(root, asset) + '.' + options.type;
if (path.existsSync(expanded)) matches.push(expanded);
@@ -50,25 +53,24 @@ AssetsExpander.prototype = {
};
var expandGroup = function(root, group) {
- var groupAssetsExpander = [];
+ var groupAssets = [];
- if (group.includes('[')) {
+ if (group.indexOf('[') > -1) {
var tokens = group.split(/[\[\]]/);
root = path.join(root, tokens[0]);
group = tokens[1];
}
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();
},
processGroup: function(type, name, localOptions) {
@@ -86,22 +88,24 @@ AssetsExpander.prototype = {
options.root = path.join(options.root, type);
var processLevel = function(levelDefinition, levelOptions) {
- if (rightjs.isString(levelDefinition)) {
- assets.push(self.processList(levelDefinition, levelOptions));
- } else if (rightjs.isHash(levelDefinition)) {
- Object.each(levelDefinition, function(key, value) {
- processLevel(value, Object.merge(levelOptions, { root: path.join(levelOptions.root, key) }));
+ if (typeof levelDefinition == 'string') {
+ self.processList(levelDefinition, levelOptions).forEach(function(asset) {
+ assets.push(asset);
});
- } else { // Array
- levelDefinition.each(function(value) {
+ } 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) }));
+ });
}
};
processLevel(definition, options);
- return assets.flatten().uniq();
+ return assets.unique();
},
// private
@@ -125,7 +129,9 @@ AssetsExpander.prototype = {
if (recursive) {
dirs.forEach(function(dir) {
- matches.push(self._scanDir(dir, '*', true, extension));
+ self._scanDir(dir, '*', true, extension).forEach(function(match) {
+ matches.push(match);
+ });
});
}
@@ -160,4 +166,36 @@ AssetsExpander.UnknownTypeError = function(message) {
};
AssetsExpander.UnknownTypeError.prototype.__proto__ = Error.prototype;
-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;
+};
View
3  package.json
@@ -10,9 +10,6 @@
},
"version": "0.2.3",
"main": "index.js",
- "dependencies": {
- "rightjs": "2.2.x"
- },
"devDependencies": {
"vows": "*"
}
Please sign in to comment.
Something went wrong with that request. Please try again.