diff --git a/examples/package-stats/package.json b/examples/package-stats/package.json index c1f488c9d6..6f6df41603 100644 --- a/examples/package-stats/package.json +++ b/examples/package-stats/package.json @@ -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:^", @@ -32,10 +32,10 @@ "online": false, "readme": [ "dgraph", + "file-io", "hiccup", "hiccup-svg", - "transducers", - "vectors" + "transducers" ], "screenshot": "examples/package-stats.png" } diff --git a/examples/package-stats/src/dep-chart.ts b/examples/package-stats/src/dep-chart.ts index b773131498..9ed5d41f9a 100644 --- a/examples/package-stats/src/dep-chart.ts +++ b/examples/package-stats/src/dep-chart.ts @@ -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, @@ -16,22 +15,13 @@ 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, @@ -39,7 +29,7 @@ const packages: { id: string; v: string; deps: string[] }[] = transduce( })) ), push(), - fs.readdirSync(BASE_DIR) + files(BASE_DIR, "package.json", 2) ); const graph = transduce( @@ -59,7 +49,7 @@ const maxDeps = transduce(pluck(1), max(), packageDeps); const width = packages.length * 16; -fs.writeFileSync( +writeText( `package-deps.svg`, serialize([ barChart, diff --git a/examples/package-stats/src/size-chart.ts b/examples/package-stats/src/size-chart.ts index ca5222895e..8488b95175 100644 --- a/examples/package-stats/src/size-chart.ts +++ b/examples/package-stats/src/size-chart.ts @@ -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"; @@ -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); @@ -47,7 +50,7 @@ const fileSizeChart = (stats: any, modType: string, type: string) => { stats ); - writeFileSync( + writeText( `package-sizes-${modType}.svg`, serialize([ barChart, diff --git a/yarn.lock b/yarn.lock index 2375e3e9ec..cd96af596b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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:^" @@ -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