Last active
February 25, 2017 13:42
-
-
Save gregdeane/8bcc4b527588a16e99c0 to your computer and use it in GitHub Desktop.
Helper method to visually display SystemJS dependency relationships using http://yuml.me/
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
System.trace = true; | |
window.showModuleRelationships = function () { | |
var modules = Object.keys(System.loads) | |
.map(function (moduleName) { | |
return System.loads[moduleName]; | |
}); | |
function displayName(module) { | |
return module | |
.replace(System.baseURL, '') | |
.replace('jspm_packages/github/', '') | |
.replace('jspm_packages/npm/', '') | |
.replace('app/js/', '') | |
.replace('controllers/', '') | |
.replace('angular/', ''); | |
} | |
var moduleDefinitions = modules.map(function (module) { | |
var name = displayName(module.name); | |
return '[' + name + '|' + 'type: ' + module.metadata.format + ']'; | |
}); | |
var dependencyDefinitions = []; | |
modules | |
.filter(function (module) { | |
return module.deps.length > 0; | |
}) | |
.forEach(function (module) { | |
var name = displayName(module.name); | |
var dependencies = module.deps | |
.map(function (dependency) { | |
return System.normalizeSync(dependency, module.name, module.address); | |
}) | |
.map(displayName) | |
.map(function (dependencyName) { | |
return '[' + name + ']->[' + dependencyName + ']' | |
}); | |
dependencyDefinitions = dependencyDefinitions.concat(dependencies); | |
}); | |
var definitions = moduleDefinitions.concat(dependencyDefinitions); | |
window.open('http://yuml.me/diagram/plain/class/' + definitions); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use, place this snippet before the call to System.import():
Then in the console, run
showModuleRelationships()
Note: Do not use this in a production environment.