Skip to content

Commit

Permalink
docs: add code metrics scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Sep 18, 2024
1 parent 369b371 commit 1fe4f23
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
15 changes: 15 additions & 0 deletions scripts/stats-assemble.sh
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions scripts/stats-get.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1fe4f23

Please sign in to comment.