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