Last active
December 25, 2022 19:44
-
-
Save dlidstrom/a2f787cef41ea4fcb8aa74d459f49270 to your computer and use it in GitHub Desktop.
Outputs all dependencies in the Angular module in a graphviz friendly format
This file contains hidden or 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
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