graph-dependencies.js 1.7 KB

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