-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild_entity_graph.ts
More file actions
62 lines (54 loc) · 1.99 KB
/
Copy pathbuild_entity_graph.ts
File metadata and controls
62 lines (54 loc) · 1.99 KB
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
/**
* Builds the schema reference graph and reports lint findings.
*
* Usage:
* ts-node build_entity_graph.ts # lint only, no asset written
* ts-node build_entity_graph.ts --output ./site # lint and write graph.json + views.json
*/
import {
buildEntityGraph,
validateEntityGraph,
writeEntityGraph,
} from "./src/js/scripts/buildEntityGraph";
import {
buildExplorerViews,
lintExplorerViews,
writeExplorerViews,
} from "./src/js/scripts/buildExplorerViews";
function getOutputDir(argv: string[]): string | undefined {
const index = argv.indexOf("--output");
if (index === -1) return undefined;
const value = argv[index + 1];
if (!value || value.startsWith("--")) {
throw new Error("--output requires a directory argument");
}
return value;
}
const outputDir = getOutputDir(process.argv.slice(2));
const { graph, lint } = buildEntityGraph();
const views = buildExplorerViews(graph);
const failures = [
...lint.failures,
...validateEntityGraph(graph),
...lintExplorerViews(graph, views),
];
const { nodeCount, edgeCount, edgeCountsByKind, sameDocumentRefCount } = graph.meta;
console.log(
`Entity graph: ${nodeCount} schemas, ${edgeCount} references ` +
`(${edgeCountsByKind.extends} extends, ${edgeCountsByKind.contains} contains, ` +
`${edgeCountsByKind.variant} variant) plus ${sameDocumentRefCount} same-document refs.`,
);
lint.warnings.forEach((warning) => console.warn(`WARNING: ${warning}`));
if (failures.length > 0) {
failures.forEach((failure) => console.error(`FAILURE: ${failure}`));
console.error(`\nSchema lint failed with ${failures.length} problem(s).`);
process.exit(1);
}
if (outputDir) {
console.log(`Wrote ${writeEntityGraph(graph, outputDir)}`);
console.log(
`Wrote ${writeExplorerViews(views, outputDir)} ` +
`(${views.categories.length} category rows, ${views.directories.length} directory rows)`,
);
}
console.log("Schema lint passed.");