graph-dependencies.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var childProcess = require('child_process');
  2. var fs = require('fs-extra');
  3. var glob = require('glob');
  4. var path = require('path');
  5. var url = require('url');
  6. var basePath = path.resolve('..');
  7. var baseUrl = 'https://github.com/jupyterlab/jupyterlab/tree/master/packages';
  8. var packages = glob.sync(path.join(basePath, 'packages/*'));
  9. // Begin the graph specification
  10. var text = 'digraph G {\n';
  11. text += 'ratio = 0.6;\n';
  12. text += 'rankdir=LR;\n';
  13. packages.forEach(function(packagePath) {
  14. // Load the package.json data.
  15. var dataPath = path.join(packagePath, 'package.json');
  16. try {
  17. var data = require(dataPath);
  18. } catch (e) {
  19. return;
  20. }
  21. // Don't include private packages.
  22. if (data.private === true) {
  23. return;
  24. }
  25. // Only include packages in the @jupyterlab namespace.
  26. if (data.name.indexOf('@jupyterlab') === -1) {
  27. return;
  28. }
  29. // In order to cut down on the number of graph nodes,
  30. // don't include "*-extension" packages.
  31. if (data.name.indexOf('-extension') !== -1 ) {
  32. return;
  33. }
  34. // Construct a URL to the package on GitHub.
  35. var Url = url.resolve(baseUrl, 'packages/'+path.basename(packagePath));
  36. // Remove the '@jupyterlab' part of the name.
  37. var name = '"'+data.name.split('/')[1] +'"';
  38. text += name + '[URL="' + Url + '"];\n';
  39. var deps = data.dependencies || [];
  40. for (var dep in deps) {
  41. // Don't include non-jupyterlab dependencies.
  42. if (dep.indexOf('@jupyterlab') === -1) {
  43. continue;
  44. }
  45. dep = '"'+dep.split('/')[1]+'"';
  46. text += name + ' -> ' + dep + ';\n';
  47. }
  48. });
  49. text += '}\n';
  50. fs.writeFileSync('./dependencies.gv', text);
  51. childProcess.execSync('cat dependencies.gv | tred | dot -Tsvg -o dependency-graph.svg')
  52. fs.unlink('./dependencies.gv');