-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtypegraph-size.ts
52 lines (41 loc) · 1.2 KB
/
typegraph-size.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
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
import { projectDir, runOrExit } from "./utils.ts";
import { bytes, formatDuration, resolve } from "./deps.ts";
const cargoManifestPath = resolve(projectDir, "Cargo.toml");
const arg = Deno.args[0];
if (!arg) {
const usage =
"Usage: deno run -A tools/typegraph-size.ts <path-to-typegraph>";
console.error(usage);
Deno.exit(1);
}
const tempDir = await Deno.makeTempDir();
const tgJsonPath = resolve(tempDir, "typegraph.json");
const cmd = [
"cargo",
"run",
"--manifest-path",
cargoManifestPath,
"-p",
"meta-cli",
"--",
"serialize",
"-o",
tgJsonPath,
...Deno.args,
];
if (!Deno.args.includes("-1")) {
cmd.push("-1");
}
const start = performance.now();
await runOrExit(cmd);
const processEnd = performance.now();
console.log();
console.log("Serialization time:", formatDuration(processEnd - start));
const typegraphStr = await Deno.readTextFile(tgJsonPath);
const typegraph = JSON.parse(typegraphStr);
console.log();
console.log("Typegraph:", typegraph.types[0].title);
console.log("Size:", bytes(typegraphStr.length));
console.log("Type count:", typegraph.types.length);