This repository has been archived by the owner on Feb 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-sizes.js
80 lines (76 loc) · 1.8 KB
/
update-sizes.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { build } from "esbuild";
import { gzipSize } from "gzip-size";
import { readFile, writeFile } from "node:fs/promises";
/** @param {number} bytes */
const kibSize = bytes => (bytes / 1024).toFixed(2);
/**
* @param {string} packagePath
*/
const updateSize = packagePath => {
const outFile = `./packages/${packagePath}/dist/index.bundle.js`;
const packageJsonLocation = `./packages/${packagePath}/package.json`;
return build({
allowOverwrite: true,
bundle: true,
entryPoints: [`./packages/${packagePath}/dist/index.js`],
format: "esm",
minify: true,
outfile: outFile,
platform: "node",
})
.then(() => readFile(outFile, "utf-8"))
.then(gzipSize)
.then(kibSize)
.then(
size =>
(
// eslint-disable-next-line no-console
console.log(`${packagePath}: ${size} KiB`),
Promise.all([
size,
readFile(packageJsonLocation, "utf-8").then(JSON.parse),
])
),
)
.then(
/** @param {[size: string, package: import("./package.json")]} packageJson */ ([
size,
packageJson,
]) =>
Object.fromEntries(
Object.entries(packageJson).map(([key, value]) => [
key,
key === "size" ? size : value,
]),
),
)
.then(packageJson =>
writeFile(
packageJsonLocation,
`${JSON.stringify(packageJson, undefined, "\t")}\n`,
"utf-8",
),
);
};
void Promise.all(
[
"@vangware/ansi",
"@vangware/cron",
"@vangware/diff",
"@vangware/iterables",
"@vangware/notify",
"@vangware/parsers",
"@vangware/predicates",
"@vangware/prompts",
"@vangware/test",
"@vangware/types",
"@vangware/utils",
"@vangware/window-open-promise",
"preact-pair",
"react-pair",
].map(updateSize),
)
// eslint-disable-next-line no-console
.then(() => console.log("All Done"))
// eslint-disable-next-line no-console
.catch(console.error);