-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
62 lines (48 loc) · 1.58 KB
/
cli.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
import { fileURLToPath } from "url";
import * as path from "path";
import { saveToDotFile } from "./dot-graph.js";
import yargs from "yargs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
import { readFileSync } from "fs";
console.log(readFileSync(path.resolve(__dirname, "./logo.txt")).toString());
const argv = yargs(process.argv.slice(2))
.usage("Usage: $0 <file> [options]")
.option("includeModules", {
alias: "m",
description: "Optionally groups components by modules",
default: false,
})
.option("prefix", {
alias: "p",
description: "The angular app prefix to remove from the components",
})
.demandCommand(1).argv;
import * as detective from "./index.js";
const filename = argv._[0];
const rootDir = path.dirname(filename);
async function main() {
console.log("Finding angular dependencies...");
try {
// Find all angular components below directory (component.html)
// Find associated ts component file (by convention)
// Find selector for component
// Build up depedency-tree of all html files that reference that selector
// Generate dot file based on dep tree
const modules = await detective.glob(rootDir + "/**/*.module.ts", {});
const moduleDependencies = modules
.map((module) => detective.getFlatModuleDeps(module))
.flat();
const file = path.basename(filename);
saveToDotFile(
file + ".dot",
moduleDependencies,
argv.includeModules,
argv.prefix || ""
);
console.log("Completed!");
} catch (e) {
console.error(e);
}
}
main();