Created
August 14, 2012 18:14
-
-
Save dustinboston/3351410 to your computer and use it in GitHub Desktop.
Generate dependency tree for RequireJS apps with xrayquire
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
xrayquire = { | |
// ... | |
getTree: function (contextName) { | |
var context = requirejs.s.contexts[contextName || '_'], | |
xray = getX(context), | |
traced = xray.traced, | |
tree = {}; | |
sortTraceOrder(xray.traceOrder); | |
each(xray.traceOrder, function (id) { | |
var mod = traced[id]; | |
if (isRequire(mod.map.id) && (!mod.deps || !mod.deps.length)) { | |
return; | |
} | |
if (mod.map.name.indexOf("_@") > -1) { | |
return; | |
} | |
tree[mod.map.name] = []; | |
each(mod.deps || [], function (dep) { | |
tree[mod.map.name].push(dep.name); | |
}); | |
}); | |
return tree; | |
}, | |
generateUml: function () { | |
var dep, key, rt, uml, val, _i, _len, _ref; | |
rt = this.getTree(); | |
uml = []; | |
for (key in rt) { | |
val = rt[key]; | |
if (rt.hasOwnProperty(key)) { | |
_ref = val; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
dep = _ref[_i]; | |
uml.push("[" + key + "]->[" + dep + "]"); | |
} | |
} | |
} | |
return uml.join("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know if require.js allows the inclusion of "_@" in your module name somehow, but if it is, then it would be safer to write