Skip to content

Commit

Permalink
refactor(examples): update package-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 20, 2024
1 parent eff1959 commit 0a16795
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
6 changes: 3 additions & 3 deletions examples/package-stats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typescript": "^5.5.3"
},
"dependencies": {
"@thi.ng/checks": "workspace:^",
"@thi.ng/dgraph": "workspace:^",
"@thi.ng/file-io": "workspace:^",
"@thi.ng/hiccup": "workspace:^",
"@thi.ng/hiccup-svg": "workspace:^",
"@thi.ng/math": "workspace:^",
Expand All @@ -32,10 +32,10 @@
"online": false,
"readme": [
"dgraph",
"file-io",
"hiccup",
"hiccup-svg",
"transducers",
"vectors"
"transducers"
],
"screenshot": "examples/package-stats.png"
}
Expand Down
20 changes: 5 additions & 15 deletions examples/package-stats/src/dep-chart.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { exists } from "@thi.ng/checks";
import { DGraph } from "@thi.ng/dgraph";
import { files, readJSON, writeText } from "@thi.ng/file-io";
import { serialize } from "@thi.ng/hiccup";
import { group, text } from "@thi.ng/hiccup-svg";
import {
comp,
filter,
map,
mapcat,
mapIndexed,
Expand All @@ -16,30 +15,21 @@ import {
transduce,
zip,
} from "@thi.ng/transducers";
import * as fs from "node:fs";
import { barChart, labeledTickX, labeledTickY } from "./viz.js";

const BASE_DIR = "../../packages/";
const BASE_DIR = "../../packages";

const packages: { id: string; v: string; deps: string[] }[] = transduce(
comp(
map((f) => BASE_DIR + f),
filter((f) => fs.statSync(f).isDirectory()),
map((f) => {
try {
return fs.readFileSync(f + "/package.json");
} catch (_) {}
}),
filter(exists),
map((p) => JSON.parse(p!.toString())),
map(readJSON),
map((p) => ({
id: p.name,
v: p.version,
deps: p.dependencies ? Object.keys(p.dependencies) : [],
}))
),
push(),
fs.readdirSync(BASE_DIR)
files(BASE_DIR, "package.json", 2)
);

const graph = transduce(
Expand All @@ -59,7 +49,7 @@ const maxDeps = transduce<any, number, number>(pluck(1), max(), packageDeps);

const width = packages.length * 16;

fs.writeFileSync(
writeText(
`package-deps.svg`,
serialize([
barChart,
Expand Down
23 changes: 13 additions & 10 deletions examples/package-stats/src/size-chart.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { dirs, readJSON, writeJSON, writeText } from "@thi.ng/file-io";
import { serialize } from "@thi.ng/hiccup";
import { group, text } from "@thi.ng/hiccup-svg";
import { defGetterUnsafe } from "@thi.ng/paths";
Expand All @@ -11,27 +12,29 @@ import {
push,
transduce,
} from "@thi.ng/transducers";
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
import { existsSync } from "node:fs";
import { barChart, labeledTickX, labeledTickY } from "./viz.js";

const BASE_DIR = "../../packages/";
const BASE_DIR = "../../packages";

const IGNORE_PACKAGES = new Set(["hiccup-carbon-icons"]);

const shortName = (x: string) => x.substring(x.lastIndexOf("/") + 1);

const meta = transduce(
comp(
filter((x) => !IGNORE_PACKAGES.has(x)),
map((m: string) => [m, BASE_DIR + m + "/.meta/size.json"]),
filter((x) => !IGNORE_PACKAGES.has(shortName(x))),
map((m: string) => [shortName(m), m + "/.meta/size.json"]),
filter(([_, path]) => existsSync(path)),
map(([m, path]) => [m, JSON.parse(readFileSync(path).toString())])
map(([m, path]) => [m, readJSON(path)])
),
push(),
readdirSync(BASE_DIR)
dirs(BASE_DIR, "", 1)
);

writeFileSync(
`package-sizes-${new Date().toISOString().substring(0, 10)}.json`,
JSON.stringify(meta, null, 4)
writeJSON(
`../../dev/package-sizes-${new Date().toISOString().substring(0, 10)}.json`,
meta
);
console.log(meta.length);

Expand All @@ -47,7 +50,7 @@ const fileSizeChart = (stats: any, modType: string, type: string) => {
stats
);

writeFileSync(
writeText(
`package-sizes-${modType}.svg`,
serialize([
barChart,
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1618,8 +1618,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@example/package-stats@workspace:examples/package-stats"
dependencies:
"@thi.ng/checks": "workspace:^"
"@thi.ng/dgraph": "workspace:^"
"@thi.ng/file-io": "workspace:^"
"@thi.ng/hiccup": "workspace:^"
"@thi.ng/hiccup-svg": "workspace:^"
"@thi.ng/math": "workspace:^"
Expand Down Expand Up @@ -1720,6 +1720,7 @@ __metadata:
"@thi.ng/color-palettes": "workspace:^"
"@thi.ng/pixel": "workspace:^"
"@thi.ng/pixel-dither": "workspace:^"
"@thi.ng/transducers": "workspace:^"
typescript: "npm:^5.5.3"
vite: "npm:^5.3.3"
languageName: unknown
Expand Down

0 comments on commit 0a16795

Please sign in to comment.