support triton.createClient(...) without requiring a configDir

This commit is contained in:
Trent Mick 2016-02-02 10:47:34 -08:00
parent e91f8f28da
commit 59b804fe6c
3 changed files with 18 additions and 9 deletions

View File

@ -2,7 +2,9 @@
## 4.4.2 (not yet released) ## 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 ## 4.4.1

View File

@ -79,22 +79,27 @@ function configPathFromDir(configDir) {
* *
* This includes some internal data on keys with a leading underscore: * This includes some internal data on keys with a leading underscore:
* _defaults the defaults.json object * _defaults the defaults.json object
* _user the "user" config.json object * _configDir the user config dir (if one is provided)
* _configDir the user config dir * _user the "user" config.json object (if exists)
* *
* @param opts.configDir {String} Optional. A base dir for TritonApi config.
* @returns {Object} The loaded config. * @returns {Object} The loaded config.
*/ */
function loadConfig(opts) { function loadConfig(opts) {
assert.object(opts, 'opts'); assert.object(opts, 'opts');
assert.string(opts.configDir, 'opts.configDir'); assert.optionalString(opts.configDir, 'opts.configDir');
var configDir = common.tildeSync(opts.configDir); var configDir;
var configPath = configPathFromDir(configDir); var configPath;
if (opts.configDir) {
configDir = common.tildeSync(opts.configDir);
configPath = configPathFromDir(configDir);
}
var c = fs.readFileSync(DEFAULTS_PATH, 'utf8'); var c = fs.readFileSync(DEFAULTS_PATH, 'utf8');
var _defaults = JSON.parse(c); var _defaults = JSON.parse(c);
var config = JSON.parse(c); var config = JSON.parse(c);
if (fs.existsSync(configPath)) { if (configPath && fs.existsSync(configPath)) {
c = fs.readFileSync(configPath, 'utf8'); c = fs.readFileSync(configPath, 'utf8');
var _user = JSON.parse(c); var _user = JSON.parse(c);
var userConfig = JSON.parse(c); var userConfig = JSON.parse(c);
@ -121,7 +126,9 @@ function loadConfig(opts) {
config._user = _user; config._user = _user;
} }
config._defaults = _defaults; config._defaults = _defaults;
config._configDir = configDir; if (configDir) {
config._configDir = configDir;
}
return config; return config;
} }

View File

@ -81,7 +81,7 @@ var tritonapi = require('./tritonapi');
* - @param profileName {String} A Triton profile name. For any profile * - @param profileName {String} A Triton profile name. For any profile
* name other than "env", one must also provide either `configDir` * name other than "env", one must also provide either `configDir`
* or `config`. * 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 * - @param configDir {String} A base config directory. This is used
* by TritonApi to find and store profiles, config, and cache data. * by TritonApi to find and store profiles, config, and cache data.
* For example, the `triton` CLI uses "~/.triton". * For example, the `triton` CLI uses "~/.triton".