Skip to content

Instantly share code, notes, and snippets.

@dlidstrom
Last active Jan 21, 2019
Embed
What would you like to do?
Outputs all dependencies in the Angular module in a graphviz friendly format
includeList = {
// put desired module names here
};
skipList = {};
handledList = {};
handleModule(window.app);
function handleModule(module) {
module.requires.forEach(requireName => {
if (!includeList[requireName]) {
if (!skipList[requireName]) {
console.log('Skipping', requireName);
}
skipList[requireName] = true;
return;
}
if (handledList[requireName]) {
return;
}
handledList[requireName] = true;
console.log('cluster_' + requireName.replace(/\./g, '_') + ' {');
console.log('label = "' + requireName + '"');
angular.module(requireName)._invokeQueue.forEach(x => {
let depsInfo = x[2];
if (x[1] === 'constant') {
outputDependency(depsInfo[0], depsInfo[0] + "Constant", depsInfo[1]);
}
else if (typeof depsInfo[1] === 'function') {
if (!depsInfo[1]) {
console.log('hmmm');
}
else {
if (!depsInfo[1] || !depsInfo[1].$inject) {
outputDependency(depsInfo[0], depsInfo[0] + "Factory");
} else {
depsInfo[1].$inject.forEach(y => outputDependency(depsInfo[0], y));
}
}
}
else if (_.isArray(depsInfo[1])) {
depsInfo[1].forEach(y => {
if (typeof y === 'string') {
outputDependency(depsInfo[0], y);
}
});
}
else {
outputDependency(depsInfo[0], depsInfo[0], depsInfo[1]);
}
function outputDependency(left, right, value) {
if (right.indexOf('$') === 0) return;
if (right === '_') return;
left = left.replace(/\./g, '_');
right = right.replace(/\./g, '_');
if (value) {
console.log(left, "->", right + "Value [label = \"" + right + " " + JSON.stringify(value).replace(/"/g, '\\"') + "\"]");
}
else {
console.log(left, "->", right);
}
}
});
console.log('}');
handleModule(angular.module(requireName));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment