diff --git a/care.js b/care.js index 2ea60ef..a97bc09 100755 --- a/care.js +++ b/care.js @@ -97,17 +97,15 @@ function doTheCodes() { var todayCommits = 0; var weekCommits = 0; - var today = spawn('sh ' + __dirname + '/standup-helper.sh', [config.repos], {shell:true}); todayBox.content = ''; - today.stdout.on('data', data => { + collectRepositoryLogs(config.repos, ['-d 1'], (data) => { todayCommits = getCommits(`${data}`, todayBox); updateCommitsGraph(todayCommits, weekCommits); screen.render(); }); - var week = spawn('sh ' + __dirname + '/standup-helper.sh', ['-d 7', config.repos], {shell:true}); weekBox.content = ''; - week.stdout.on('data', data => { + collectRepositoryLogs(config.repos, ['-d 7'], (data) => { weekCommits = getCommits(`${data}`, weekBox); updateCommitsGraph(todayCommits, weekCommits); screen.render(); @@ -142,6 +140,23 @@ function makeScrollBox(label) { return options; } +function collectRepositoryLogs(search_paths, args, handler) { + var n = search_paths.length; + var output = ''; + for (var search_path of search_paths) { + var proc = spawn(__dirname + '/node_modules/git-standup/git-standup', args, {shell: true, cwd: search_path}); + proc.stdout.on('data', (data) => { + output += data; + }); + proc.once('exit', () => { + --n; + if (n == 0) { + handler(output); + } + }); + } +} + var commitRegex = /(.......) (- .*)/g; function getCommits(data, box) { var content = colorizeLog(data); diff --git a/config.js b/config.js index f51abc2..46a9afd 100644 --- a/config.js +++ b/config.js @@ -11,7 +11,7 @@ config.apiKeys = config.apiKeys === 'true' ? true : false; // Directories in which to run git-standup on for a list of your recent commits. config.repos = process.env.TTC_REPOS || '~/Code'; -config.repos = config.repos.split(',').join(' '); +config.repos = config.repos.split(','); // Where to check the weather for. This can be a zip code or a location name // So both 90210 and "San Francisco, CA" should be ok. diff --git a/standup-helper.sh b/standup-helper.sh deleted file mode 100644 index 0a68457..0000000 --- a/standup-helper.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -set -e - -# I couldn't figure out how to cd into a different working directory -# and run git-standup there directly from node (cwd did nothing), so -# here we are. - -progname=$0 - -# I love 2 shell. -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -standup=$DIR"/node_modules/git-standup/git-standup" - -function usage () { - echo "Usage: " - echo " $progname [-d days] [-h] repo1 repo2 etc." - echo " -d \t - Specify the number of days back to include" - echo " -d \t - Display this help screen" -} - -# get the optional days -days=1 -while getopts "d:h" opt; do - case $opt in - d ) days=$OPTARG;; - h ) usage ;; - \?) usage ;; - esac -done -shift $(($OPTIND - 1)) - -# the repo names -for dir in "$@" -do - (cd $dir; $standup -d $days) -done