deps.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. const madge = require("madge");
  3. const path = require("path");
  4. const ts = require("typescript");
  5. const DIR = "./lib";
  6. async function main() {
  7. const tsconfigPath = ts.findConfigFile("./", ts.sys.fileExists);
  8. const tsconfig = ts.readConfigFile(tsconfigPath, ts.sys.readFile).config;
  9. const parsedConfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, "./");
  10. const typedPaths = parsedConfig.fileNames.map(filename => path.resolve("./", filename));
  11. const excludeTypedPaths = path => !typedPaths.includes(path);
  12. const res = await madge(DIR, {
  13. dependencyFilter: excludeTypedPaths
  14. });
  15. const untypedLeaves = res.leaves().map(filename => path.resolve(DIR, filename)).filter(excludeTypedPaths);
  16. if (untypedLeaves.length) {
  17. console.log("Convert next:");
  18. console.log(untypedLeaves.join("\n"));
  19. } else {
  20. console.log("No untyped leaf dependencies found.");
  21. console.log("Try looking at circular dependencies, or the image to decide what to convert next:");
  22. const untypedCircular = res.circular().flat().map(filename => path.resolve(DIR, filename)).filter(excludeTypedPaths);
  23. console.log(untypedCircular.join("\n"));
  24. }
  25. const imagePath = await res.image("graph.svg");
  26. console.log();
  27. console.log("Image written to " + imagePath);
  28. }
  29. main();