-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdependencies-manager.mjs
101 lines (82 loc) · 2.62 KB
/
dependencies-manager.mjs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { readFileSync, writeFileSync } from "fs";
import modules from "./module-dependencies.mjs"
const buildPath = "../build";
function generateDependenciesGraph() {
let graph = "graph";
for (const module of modules) {
for (const dependency of module.dependencies) {
graph += `\n\t${module.id} --> ${dependency}`;
}
}
graph += "\n"
for (const module of modules) {
switch (module.type) {
case "AXIOM":
graph += `\n\tstyle ${module.id} fill:#ffefd3, stroke:#000, stroke-width:1.5px`
break;
case "INSTANCE":
graph += `\n\tstyle ${module.id} fill:#adb6c4, stroke:#000, stroke-width:1.5px`
break;
case "THEOREM":
graph += `\n\tstyle ${module.id} fill:#ffc49b, stroke:#000, stroke-width:1.5px`
break;
}
}
const graphMd = "```mermaid\n" + graph + "\n```"
writeFile(`${buildPath}/dependencies-graph.md`, graphMd);
}
function readFile(path) {
try {
return readFileSync(path);
} catch (err) {
console.error(err);
process.exit(1);
}
}
function writeFile(path, contents) {
try {
writeFileSync(path, contents, { encoding: "utf-8"});
} catch (err) {
console.error(err);
process.exit(1);
}
}
function joinModules(orderedModules) {
let joinedContents = "";
for (const module of orderedModules) {
const contents = readFile(module.path);
joinedContents += `% -------------------------- ${module.id} --------------------------`;
joinedContents += `\n\n${contents}\n`;
}
return joinedContents;
}
function generateTheoryFile() {
const axiomModules = modules.filter((module) => module.type === "AXIOM");
const theoryContents = joinModules(axiomModules);
writeFile(`${buildPath}/theory.p`, theoryContents)
}
function generateTheoremFiles() {
const axiomModules = modules.filter((module) => module.type === "AXIOM");
const theoremModules = modules.filter((module) => module.type === "THEOREM")
for (const module of theoremModules) {
const contents = joinModules([...axiomModules, module]);
const path = module.path.replace("/src/","/build/");
writeFile(path, contents)
}
}
function generateInstanceFiles() {
const axiomModules = modules.filter((module) => module.type === "AXIOM");
const instanceModules = modules.filter((module) => module.type === "INSTANCE")
for (const module of instanceModules) {
const contents = joinModules([...axiomModules, module]);
const path = module.path.replace("/src/","/build/");
writeFile(path, contents)
}
}
function main() {
generateDependenciesGraph();
generateTheoryFile();
generateTheoremFiles();
generateInstanceFiles();
}
main();