From 1b65c2565bcce6b29b9b0a484c7ee9f28e9ed943 Mon Sep 17 00:00:00 2001 From: Josh Perez Date: Wed, 23 Nov 2011 15:12:58 -0800 Subject: [PATCH] Done? --- bin/git-stats | 5 ++++- lib/index.js | 25 +++++++++++++++++++++++-- {node_modules => lib}/xhr.js | 4 ++-- node_modules/inject.js | 9 --------- 4 files changed, 29 insertions(+), 14 deletions(-) rename {node_modules => lib}/xhr.js (98%) delete mode 100644 node_modules/inject.js diff --git a/bin/git-stats b/bin/git-stats index eec2505..cc08005 100755 --- a/bin/git-stats +++ b/bin/git-stats @@ -1,3 +1,6 @@ #!/bin/bash -git "$@" +if [ $1 != "--conf" ] + then + git "$@" +fi nohup bin/gitstatsjs "$@" > /dev/null 2>&1 & diff --git a/lib/index.js b/lib/index.js index 6cd7954..ec235ee 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,27 @@ -var config = require('../config.json'); +var config; -var xhr = require('xhr').load(config.host, config.port); +// check for/add config file +(function () { + var url = require('url'); + var fs = require('fs'); + var argv = process.argv.slice(2); + var uri; + if (argv[0] === "--conf") { + config = url.parse(argv[1]); + fs.writeFileSync("./config.json", JSON.stringify(config), "utf8"); + process.exit(); + } +}()); + +try { + config = require('../config.json'); +} catch (e) { + process.stdout.write("Run git --conf \n"); + process.stdout.write("You must first create a config.json\n"); + process.exit(); +} + +var xhr = require('./xhr').load(config.hostname, config.port); var stats = function (args) { var data = { diff --git a/node_modules/xhr.js b/lib/xhr.js similarity index 98% rename from node_modules/xhr.js rename to lib/xhr.js index dc861b8..7dcad2c 100644 --- a/node_modules/xhr.js +++ b/lib/xhr.js @@ -44,7 +44,7 @@ var doXHR = function (options, callback, data) { }); res.on('end', function () { - callback(res); + callback && callback(res); }); }); @@ -66,7 +66,7 @@ var doXHR = function (options, callback, data) { exports.load = function (host, port) { var options = { host: host, - port: port || 443, + port: port || 80, headers: { "Accept": "application/json", "Content-Type": "application/json" diff --git a/node_modules/inject.js b/node_modules/inject.js deleted file mode 100644 index 9a636e3..0000000 --- a/node_modules/inject.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = function (str, obj) { - Object.keys(obj).forEach(function (prop) { - if (obj.hasOwnProperty(prop)) { - str = str.replace(new RegExp('#{' + prop + '}', 'g'), typeof obj[prop][1] === 'f' ? obj[prop]() : obj[prop]); - } - }); - - return str; -};