Created
July 12, 2013 08:16
-
-
Save mikaelkaron/5982749 to your computer and use it in GitHub Desktop.
Process RequireJS configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Processes a RequireJS config | |
* @scope {Object} RequireJS config | |
* @param {Object} Components from bower.lock | |
* @returns {Object} Processed RequireJS config | |
*/ | |
function process(components) { | |
var ARRAY_PUSH = Array.prototype.push; | |
var NAME = "name"; | |
var LOCATION = "location"; | |
var MAIN = "main"; | |
var me = this; | |
var config_paths = me.paths || {}; | |
var config_packages = me.packages || []; | |
var ignore_packages = [ "requirejs" ]; | |
Object | |
.keys(config_paths) | |
.forEach(function (path) { | |
if (components.hasOwnProperty(path)) { | |
var component = components[path]; | |
if (component.hasOwnProperty(MAIN)) { | |
config_paths[path] = [ component[LOCATION], component[NAME] ].join("/") | |
} | |
} | |
}); | |
config_packages.forEach(function (pkg) { | |
var name = pkg[NAME]; | |
var component; | |
if (components.hasOwnProperty(name)) { | |
component = components[name]; | |
Object | |
.keys(component) | |
.forEach(function (key) { | |
if (!pkg.hasOwnProperty(key)) { | |
pkg[key] = component[key]; | |
} | |
}); | |
} | |
switch (name) { | |
case "troopjs": | |
ARRAY_PUSH.apply(config_packages, [ | |
"troopjs-core", | |
"troopjs-browser", | |
"troopjs-data", | |
"troopjs-jquery", | |
"troopjs-requirejs", | |
"troopjs-utils" | |
].map(function (troop_pkg) { | |
return { | |
"name" : troop_pkg, | |
"location" : [ pkg[LOCATION], "lib", troop_pkg ].join("/") | |
}; | |
})); | |
break; | |
} | |
}); | |
Object | |
.keys(components) | |
.filter(function (key) { | |
return !ignore_packages.some(function (name) { | |
return key === name; | |
}); | |
}) | |
.filter(function (key) { | |
return !config_packages.some(function (pkg) { | |
return key === pkg[NAME]; | |
}); | |
}) | |
.forEach(function (key) { | |
var component = components[key]; | |
config_packages.push({ | |
"name" : key, | |
"location" : component[LOCATION], | |
"main" : component[MAIN] | |
}); | |
}); | |
return me; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment