DEV Community

0xkoji
0xkoji

Posted on

Retrieve lines from a GitHub repo by a command

[requirements]

$ curl -sS https://api.github.com/repos/userName/repoName/stats/code_frequency | jq 'reduce .[] as $row (0; . + $row[1] + $row[2])'
Enter fullscreen mode Exit fullscreen mode

tested with this repo

GitHub logo koji / node-typescript-boilerplate

boilerplate for nodejs with typescript

typescript-node-boilerplate

This is a boilerplate for nodejs project with typescript.
The followings are details of this boilerplate.

blog post for this

npm-script

The commands are ordered alphabetically.

yarn clean

This command will clean up dist folder that is for build files(.js files)

"clean": "rimraf dist/*",
Enter fullscreen mode Exit fullscreen mode

yarn dev:watch

This commands allows run index.ts file without compile and monitor the changes on the file

"dev:watch": "ts-node-dev --respwn src/index.ts",
Enter fullscreen mode Exit fullscreen mode

yarn dev

This commands allows run index.ts file without compile

"dev": "ts-node src/index.ts",
Enter fullscreen mode Exit fullscreen mode

yarn format

This commands will format all files with the rules that are based on .eslintrc.js

"format": "prettier --write 'src/**/*.{js,ts,json}'",
Enter fullscreen mode Exit fullscreen mode

yarn lint:all

This command will lint all ts files and run tsc without generating any .js files

"lint:all": "yarn lint && yarn tscCheck
Enter fullscreen mode Exit fullscreen mode
$ curl -sS https://api.github.com/repos/koji/node-typescript-boilerplate/stats/code_frequency | jq 'reduce .[] as $row (0; . + $row[1] + $row[2])'
2605
Enter fullscreen mode Exit fullscreen mode

The output is including empty lines and comments in the codebase.

If you use cloc, you can count code without empty lines and comments.

# install cloc
$ brew install cloc
Enter fullscreen mode Exit fullscreen mode
#!/usr/bin/env zsh

git clone --depth 1 "$1" linecount-repo && \
  printf "('linecount-repo' will be deleted automatically)\n\n\n" && \
  cloc linecount-repo && \
  rm -rf linecount-repo
Enter fullscreen mode Exit fullscreen mode

Then you can register the above script as an alias and use it easily.

Other way

$ cd your_github_repo
$ git ls-files | xargs -n1 git --no-pager blame -f -w|grep <userName> |wc -l
Enter fullscreen mode Exit fullscreen mode

Top comments (0)