Skip to content

Commit

Permalink
feat(tools): add/update stats scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 20, 2024
1 parent 70df6eb commit eff1959
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/stats
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi
if [ $# -gt 1 ]; then
out="$2"
else
out=assets/stats.csv
out=dev/stats.csv
fi

echo "package,files,comments,sloc" > $out
Expand Down
2 changes: 1 addition & 1 deletion scripts/stats-examples
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi
if [ $# -gt 1 ]; then
out="$2"
else
out=assets/stats-examples.csv
out=dev/stats-examples.csv
fi

echo "example,files,comments,sloc" > $out
Expand Down
43 changes: 43 additions & 0 deletions tools/src/commit-stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { lower, percent, split } from "@thi.ng/strings";
import {
assocObj,
comp,
filter,
keep,
map,
normFrequenciesAuto,
transduce,
} from "@thi.ng/transducers";
import { execFileSync } from "node:child_process";

const args =
"log --all --pretty=format:%ad~~%s --date=iso-strict --since=2018-01-01";

console.log(args);

const commits = execFileSync("git", args.split(" ")).toString("utf8");

const xfPreproc = comp(
map(lower),
map((x) => x.split("~~"))
);

const types = transduce(
comp(
xfPreproc,
map(([_, msg]) => /^(\w+)\(/.exec(msg)),
keep(),
map((x) => x[1]),
filter((x) => ["feat", "refactor", "docs", "fix", "perf"].includes(x))
),
normFrequenciesAuto(),
split(commits)
);

console.log(
assocObj(
[...types.keys()]
.sort()
.map((x) => <[string, string]>[x, percent(1)(types.get(x)!)])
)
);
14 changes: 14 additions & 0 deletions tools/src/example-sizes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { files, writeText } from "@thi.ng/file-io";
import { FMT_yyyyMMdd_HHmmss } from "@thi.ng/date";
import { table } from "@thi.ng/markdown-table";
import { statSync } from "node:fs";

const stats = [...files("examples", /assets\/index-.+\.js$/)].map((x) => [
/examples\/([a-z0-9-]+)/.exec(x)![1],
statSync(x).size,
]);

writeText(
`dev/example-sizes-${FMT_yyyyMMdd_HHmmss()}.md`,
table(["name", "size"], stats)
);

0 comments on commit eff1959

Please sign in to comment.