From 59b804fe6cb789a198334cb37a2194c0bf9ef82e Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Tue, 2 Feb 2016 10:47:34 -0800 Subject: [PATCH] support triton.createClient(...) without requiring a configDir --- CHANGES.md | 4 +++- lib/config.js | 21 ++++++++++++++------- lib/index.js | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index aad11a1..1b16bbb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,9 @@ ## 4.4.2 (not yet released) -(nothing yet) +- Support `triton.createClient(...)` creation without requiring a + `configDir`. Basically this then fallsback to a `TritonApi` with the default + config. ## 4.4.1 diff --git a/lib/config.js b/lib/config.js index bd56add..6152eee 100644 --- a/lib/config.js +++ b/lib/config.js @@ -79,22 +79,27 @@ function configPathFromDir(configDir) { * * This includes some internal data on keys with a leading underscore: * _defaults the defaults.json object - * _user the "user" config.json object - * _configDir the user config dir + * _configDir the user config dir (if one is provided) + * _user the "user" config.json object (if exists) * + * @param opts.configDir {String} Optional. A base dir for TritonApi config. * @returns {Object} The loaded config. */ function loadConfig(opts) { assert.object(opts, 'opts'); - assert.string(opts.configDir, 'opts.configDir'); + assert.optionalString(opts.configDir, 'opts.configDir'); - var configDir = common.tildeSync(opts.configDir); - var configPath = configPathFromDir(configDir); + var configDir; + var configPath; + if (opts.configDir) { + configDir = common.tildeSync(opts.configDir); + configPath = configPathFromDir(configDir); + } var c = fs.readFileSync(DEFAULTS_PATH, 'utf8'); var _defaults = JSON.parse(c); var config = JSON.parse(c); - if (fs.existsSync(configPath)) { + if (configPath && fs.existsSync(configPath)) { c = fs.readFileSync(configPath, 'utf8'); var _user = JSON.parse(c); var userConfig = JSON.parse(c); @@ -121,7 +126,9 @@ function loadConfig(opts) { config._user = _user; } config._defaults = _defaults; - config._configDir = configDir; + if (configDir) { + config._configDir = configDir; + } return config; } diff --git a/lib/index.js b/lib/index.js index 87b436e..c050222 100644 --- a/lib/index.js +++ b/lib/index.js @@ -81,7 +81,7 @@ var tritonapi = require('./tritonapi'); * - @param profileName {String} A Triton profile name. For any profile * name other than "env", one must also provide either `configDir` * or `config`. - * Either `profile` or `profileName` is requires. See discussion above. + * Either `profile` or `profileName` is required. See discussion above. * - @param configDir {String} A base config directory. This is used * by TritonApi to find and store profiles, config, and cache data. * For example, the `triton` CLI uses "~/.triton".