support triton.createClient(...) without requiring a configDir
This commit is contained in:
parent
e91f8f28da
commit
59b804fe6c
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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".
|
||||
|
Reference in New Issue
Block a user