graph-dependencies.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // Don't include the metapackage.
  35. if (data.name === '@jupyterlab/metapackage') {
  36. return;
  37. }
  38. // Construct a URL to the package on GitHub.
  39. var Url = url.resolve(baseUrl, 'packages/' + path.basename(packagePath));
  40. // Remove the '@jupyterlab' part of the name.
  41. var name = '"' + data.name.split('/')[1] + '"';
  42. text += name + '[URL="' + Url + '"];\n';
  43. var deps = data.dependencies || [];
  44. for (var dep in deps) {
  45. // Don't include non-jupyterlab dependencies.
  46. if (dep.indexOf('@jupyterlab') === -1) {
  47. continue;
  48. }
  49. dep = '"' + dep.split('/')[1] + '"';
  50. text += name + ' -> ' + dep + ';\n';
  51. }
  52. });
  53. text += '}\n';
  54. fs.writeFileSync('./dependencies.gv', text);
  55. childProcess.execSync(
  56. 'cat dependencies.gv | tred | dot -Tsvg -o dependency-graph.svg'
  57. );
  58. fs.unlink('./dependencies.gv');