From 1fe4f2366d428eaea97ba0d775f95eba4e245417 Mon Sep 17 00:00:00 2001 From: Arild Matsson Date: Wed, 18 Sep 2024 16:48:32 +0200 Subject: [PATCH] docs: add code metrics scripts --- scripts/stats-assemble.sh | 15 +++++++++++ scripts/stats-get.sh | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100755 scripts/stats-assemble.sh create mode 100755 scripts/stats-get.sh diff --git a/scripts/stats-assemble.sh b/scripts/stats-assemble.sh new file mode 100755 index 000000000..f68c48e4b --- /dev/null +++ b/scripts/stats-assemble.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +DIR=$(dirname "$0") + +# CSV header corresponding to lines in the metrics +echo "Commit,Version,Date,TS,JS,TS%,lib,test,Dependencies,window,Directives,Components" + +# Check out each tagged version and run metrics +# Skip v6.x, it had lots of dependencies checked in +for TAG in $(git tag | grep -v 'v6'); do + git checkout -q "$TAG" + DATE=$(git show --no-patch --format=%cs) + # Output as CSV rows + "$DIR"/fe-stats-get.sh -q | paste -sd , - +done diff --git a/scripts/stats-get.sh b/scripts/stats-get.sh new file mode 100755 index 000000000..3b1b753b5 --- /dev/null +++ b/scripts/stats-get.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# Add `-q` to skip labels +while getopts "q" flag; do + case $flag in + q) OPT_QUIET=1 ;; + esac +done + +function label() { + # Say label unless -q was given + [ -z $OPT_QUIET ] && echo -ne "$1:\t" + # Say value if present + [ -n "$2" ] && echo $2 +} + +WC_JS=$(find app -type f -name '*.js' | xargs wc -l --total=only) +WC_TS=$(find app -type f -name '*.ts' | xargs wc -l --total=only) +TS_RATIO=$(node -pe "Math.round($WC_TS / ($WC_TS + $WC_JS) * 100)") + +# TODO The git commands output control chars, and they bork the label strings +label "Commit hash" +git show --no-patch --format="%h" + +label "Tag" +git tag --points-at HEAD | grep "^v" + +label "Date" +git show --no-patch --format=%cs + +label "TypeScript lines of code" $WC_TS +label "JavaScript lines of code" $WC_JS +label "Ratio of TypeScript" $TS_RATIO% + +label "Size of repo (KB)" +git ls-files | xargs du --apparent-size -c | tail -n1 | cut -f1 + +label "Size of lib/ (KB)" +du --apparent-size -s app/lib/ | cut -f1 + +label "Test lines of code" +find test/ -type f | xargs wc -l --total=only + +label "Direct dependencies" +cat package.json | jq '.dependencies * .devDependencies | keys | length' + +label "Assignments to \`window\`" +grep -roE 'window\.\w+ =' app/scripts/ | grep -v window.location | wc -l + +label "AngularJS directives" +grep -r .directive\( app/scripts/ | wc -l + +label "AngularJS components" +grep -r .component\( app/scripts/ | wc -l