JSDoc comments

This commit is contained in:
Ionică Bizău 2015-09-14 17:29:40 +03:00
parent f28e390309
commit 66d51ae7b0
3 changed files with 22 additions and 8 deletions

View file

@ -20,17 +20,15 @@ const CONFIG_PATH = GitStatsLib.CONFIG_PATH
// Configurations // Configurations
Moment.suppressDeprecationWarnings = true; Moment.suppressDeprecationWarnings = true;
GitStats.config = {};
try { try {
GitStats.config = ReadJson(CONFIG_PATH); GitStats.initConfig();
} catch (err) { } catch (err) {
if (err.code !== "ENOENT") { if (err.code !== "ENOENT") {
Logger.log("Failed to read the config file: " + err.stack, "warn"); Logger.log("Failed to read the config file:\n" + err.stack, "warn");
} }
} }
GitStats.config = Ul.deepMerge(GitStats.config, DEFAULT_CONFIG);
// Parse the command line arguments // Parse the command line arguments
var recordOpt = new Clp.Option(["record"], "Records a new commit. Don't use this unless you are a mad scientist. If you are a developer, just use this option as part of the module.", "data") var recordOpt = new Clp.Option(["record"], "Records a new commit. Don't use this unless you are a mad scientist. If you are a developer, just use this option as part of the module.", "data")
, sinceDateOpt = new Clp.Option(["s", "since"], "Optional start date.", "date", GitStats.config.since) , sinceDateOpt = new Clp.Option(["s", "since"], "Optional start date.", "date", GitStats.config.since)
@ -85,10 +83,8 @@ if (GitStats.config.global_activity) {
globalActivityOpt.is_provided = true; globalActivityOpt.is_provided = true;
} }
// --record // --record
if (recordOpt.is_provided) { if (recordOpt.is_provided) {
try { try {
options = JSON.parse(recordOpt.value.replace(/^\"|\"$/g, "")); options = JSON.parse(recordOpt.value.replace(/^\"|\"$/g, ""));
} catch (e) { } catch (e) {

View file

@ -67,6 +67,15 @@ GitStats.DEFAULT_CONFIG = {
, global_activity: false , global_activity: false
}; };
/**
* getConfig
* Fetches the configuration object from file (`~/.git-stats-config.json`).
*
* @name getConfig
* @function
* @param {Function} callback The callback function.
* @return {Object|Undefined} If no callback is provided, the configuration object will be returned.
*/
GitStats.prototype.getConfig = function (callback) { GitStats.prototype.getConfig = function (callback) {
if (callback) { if (callback) {
ReadJson(CONFIG_PATH, function (err, data) { ReadJson(CONFIG_PATH, function (err, data) {
@ -84,6 +93,15 @@ GitStats.prototype.getConfig = function (callback) {
} }
}; };
/**
* initConfig
* Inits the configuration field (`this.config`).
*
* @name initConfig
* @function
* @param {Object|String} input The path to a custom git-stats configuration file or the configuration object.
* @param {Function} callback The callback function.
*/
GitStats.prototype.initConfig = function (input, callback) { GitStats.prototype.initConfig = function (input, callback) {
var self = this; var self = this;

View file

@ -45,7 +45,7 @@
"moment": "^2.9.0", "moment": "^2.9.0",
"progress": "1.1.8", "progress": "1.1.8",
"r-json": "^1.0.0", "r-json": "^1.0.0",
"typpy": "2.0.0", "typpy": "^2.1.0",
"ul": "^5.0.0", "ul": "^5.0.0",
"w-json": "^1.0.0" "w-json": "^1.0.0"
}, },