forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayerCheck.ts
125 lines (104 loc) · 3.47 KB
/
layerCheck.ts
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { LayerGraph } from "./layerGraph";
import { commonOptions, commonOptionString, parseOption } from "../common/commonOptions";
import { Timer } from "../common/timer";
import { getResolvedFluidRoot } from "../common/fluidUtils";
import { writeFileAsync } from "../common/utils";
import { FluidRepo } from "../common/fluidRepo";
import path from "path";
function printUsage() {
console.log(
`
Usage: fluid-layer-check <options>
Options:
--dot <path> Generate *.dot for GraphViz
--info <path> Path to the layer graph json file
--md Generate PACKAGES.md file for human consumption
${commonOptionString}
`);
}
const packagesMdFileName: string = "PACKAGES.md";
let dotGraphFilePath: string | undefined;
let writePackagesMd: boolean = false;
let layerInfoPath: string | undefined;
function parseOptions(argv: string[]) {
let error = false;
for (let i = 2; i < process.argv.length; i++) {
const argParsed = parseOption(argv, i);
if (argParsed < 0) {
error = true;
break;
}
if (argParsed > 0) {
i += argParsed - 1;
continue;
}
const arg = process.argv[i];
if (arg === "-?" || arg === "--help") {
printUsage();
process.exit(0);
}
if (arg === "--dot") {
if (i !== process.argv.length - 1) {
dotGraphFilePath = process.argv[++i];
continue;
}
console.error("ERROR: Missing argument for --dot");
error = true;
break;
}
if (arg === "--md") {
writePackagesMd = true;
continue;
}
if (arg === "--info") {
if (i !== process.argv.length - 1) {
layerInfoPath = path.resolve(process.argv[++i]);
continue;
}
console.error("ERROR: Missing argument for --info");
error = true;
break;
}
console.error(`ERROR: Invalid arguments ${arg}`);
error = true;
break;
}
if (error) {
printUsage();
process.exit(-1);
}
}
parseOptions(process.argv);
async function main() {
const timer = new Timer(commonOptions.timer);
const resolvedRoot = await getResolvedFluidRoot();
// Load the package
const packages = new FluidRepo(resolvedRoot, false).packages;
timer.time("Package scan completed");
try {
const layerGraph = LayerGraph.load(resolvedRoot, packages, layerInfoPath);
// Write human-readable package list organized by layer
if (writePackagesMd) {
const packagesMdFilePath: string = path.join(resolvedRoot, "docs", packagesMdFileName);
await writeFileAsync(packagesMdFilePath, layerGraph.generatePackageLayersMarkdown(resolvedRoot));
}
// Write machine-readable dot file used to render a dependency graph
if (dotGraphFilePath !== undefined) {
await writeFileAsync(dotGraphFilePath, layerGraph.generateDotGraph());
}
const success = layerGraph.verify();
timer.time("Layer check completed");
if (!success) {
process.exit(-1);
}
console.log(`Layer check passed (${packages.packages.length} packages)`)
} catch (e) {
console.error(e.message);
process.exit(-2);
}
}
main();