balena-settings-client
Advanced tools
Comparing version 4.0.0 to 4.0.1-56-resin-name-fallbacks-5e43ab7118bd03b72bba0c1e6f859f49bdb1eb22
@@ -33,8 +33,18 @@ "use strict"; | ||
/** | ||
* @property {String} user - path to legacy user config | ||
* @memberof paths | ||
*/ | ||
userLegacy: path_1.join(userHome, hidepath('resinrc.yml')), | ||
/** | ||
* @property {String} project - path to project config | ||
* @memberof paths | ||
*/ | ||
project: path_1.join(process.cwd(), 'balenarc.yml') | ||
project: path_1.join(process.cwd(), 'balenarc.yml'), | ||
/** | ||
* @property {String} project - path to legacy project config | ||
* @memberof paths | ||
*/ | ||
projectLegacy: path_1.join(process.cwd(), 'resinrc.yml') | ||
} | ||
}; | ||
//# sourceMappingURL=config.js.map |
@@ -86,2 +86,5 @@ "use strict"; | ||
} | ||
else if (this.balenaUrl === 'resin.io') { | ||
return 'resindevice.io'; | ||
} | ||
return "devices." + this.balenaUrl; | ||
@@ -88,0 +91,0 @@ }, |
@@ -38,3 +38,5 @@ "use strict"; | ||
} | ||
return _.camelCase(variable.replace(/^BALENARC_/i, '')); | ||
return _.camelCase(variable | ||
.replace(/^(BALENARC|RESINRC)_/i, '') | ||
.replace(/(^|_)RESIN(_|$)/, '$1BALENA$2')); | ||
}; | ||
@@ -58,3 +60,3 @@ /** | ||
exports.isSettingVariable = function (variable) { | ||
return /^BALENARC_(.)+/i.test(variable); | ||
return /^(BALENARC_|RESINRC_)(.)+/i.test(variable); | ||
}; | ||
@@ -61,0 +63,0 @@ /** |
@@ -90,4 +90,7 @@ "use strict"; | ||
}; | ||
var replaceResinKeys = function (parsedConfig) { | ||
return _.mapKeys(parsedConfig, function (_value, key) { return key.replace('resin', 'balena'); }); | ||
}; | ||
var getSettings = _.once(function () { | ||
return utils.mergeObjects({}, defaults, readConfigFile(config.paths.user), readConfigFile(config.paths.project), environment.parse(process.env)); | ||
return utils.mergeObjects({}, defaults, replaceResinKeys(readConfigFile(config.paths.userLegacy)), readConfigFile(config.paths.user), replaceResinKeys(readConfigFile(config.paths.projectLegacy)), readConfigFile(config.paths.project), environment.parse(process.env)); | ||
}); | ||
@@ -94,0 +97,0 @@ /** |
@@ -7,2 +7,7 @@ # Change Log | ||
## v4.0.1 - 2018-10-24 | ||
* Continue to support resinrc.yml config files [Tim Perry] | ||
* Continue to support RESINRC_ environment variables [Tim Perry] | ||
## v4.0.0 - 2018-10-15 | ||
@@ -9,0 +14,0 @@ |
@@ -40,7 +40,19 @@ /* | ||
/** | ||
* @property {String} user - path to legacy user config | ||
* @memberof paths | ||
*/ | ||
userLegacy: joinPath(userHome, hidepath('resinrc.yml')), | ||
/** | ||
* @property {String} project - path to project config | ||
* @memberof paths | ||
*/ | ||
project: joinPath(process.cwd(), 'balenarc.yml') | ||
project: joinPath(process.cwd(), 'balenarc.yml'), | ||
/** | ||
* @property {String} project - path to legacy project config | ||
* @memberof paths | ||
*/ | ||
projectLegacy: joinPath(process.cwd(), 'resinrc.yml') | ||
} | ||
}; |
@@ -98,2 +98,4 @@ /* | ||
return 'balena-staging-devices.com'; | ||
} else if (this.balenaUrl === 'resin.io') { | ||
return 'resindevice.io'; | ||
} | ||
@@ -100,0 +102,0 @@ return `devices.${this.balenaUrl}`; |
@@ -38,3 +38,7 @@ /* | ||
} | ||
return _.camelCase(variable.replace(/^BALENARC_/i, '')); | ||
return _.camelCase( | ||
variable | ||
.replace(/^(BALENARC|RESINRC)_/i, '') | ||
.replace(/(^|_)RESIN(_|$)/, '$1BALENA$2') | ||
); | ||
}; | ||
@@ -59,3 +63,3 @@ | ||
export const isSettingVariable = (variable: string) => | ||
/^BALENARC_(.)+/i.test(variable); | ||
/^(BALENARC_|RESINRC_)(.)+/i.test(variable); | ||
@@ -62,0 +66,0 @@ /** |
@@ -93,2 +93,5 @@ /* | ||
const replaceResinKeys = (parsedConfig: object) => | ||
_.mapKeys(parsedConfig, (_value, key) => key.replace('resin', 'balena')); | ||
const getSettings = _.once( | ||
@@ -99,3 +102,5 @@ (): { [k: string]: string | undefined } => | ||
defaults, | ||
replaceResinKeys(readConfigFile(config.paths.userLegacy)), | ||
readConfigFile(config.paths.user), | ||
replaceResinKeys(readConfigFile(config.paths.projectLegacy)), | ||
readConfigFile(config.paths.project), | ||
@@ -102,0 +107,0 @@ environment.parse(process.env) |
{ | ||
"name": "balena-settings-client", | ||
"version": "4.0.0", | ||
"version": "4.0.1-56-resin-name-fallbacks-5e43ab7118bd03b72bba0c1e6f859f49bdb1eb22", | ||
"description": "Balena client application shared settings", | ||
@@ -5,0 +5,0 @@ "main": "build/settings.js", |
@@ -39,6 +39,38 @@ import * as Promise from 'bluebird'; | ||
wary.it( | ||
'should override defaults given a user configuration that points to staging', | ||
'should override defaults given a legacy resin configuration', | ||
{}, | ||
() => { | ||
fs.writeFileSync( | ||
config.paths.user.replace('balenarc.yml', 'resinrc.yml'), | ||
stripIndent` | ||
resinUrl: resin.io | ||
` | ||
); | ||
return Promise.props({ | ||
balenaUrl: getSetting('balenaUrl'), | ||
apiUrl: getSetting('apiUrl'), | ||
dashboardUrl: getSetting('dashboardUrl'), | ||
vpnUrl: getSetting('vpnUrl'), | ||
registryUrl: getSetting('registryUrl'), | ||
registry2Url: getSetting('registry2Url'), | ||
proxyUrl: getSetting('proxyUrl') | ||
}).then(settings => { | ||
m.chai.expect(settings.balenaUrl).to.equal('resin.io'); | ||
m.chai.expect(settings.apiUrl).to.equal('https://api.resin.io'); | ||
m.chai | ||
.expect(settings.dashboardUrl) | ||
.to.equal('https://dashboard.resin.io'); | ||
m.chai.expect(settings.vpnUrl).to.equal('vpn.resin.io'); | ||
m.chai.expect(settings.registryUrl).to.equal('registry.resin.io'); | ||
m.chai.expect(settings.registry2Url).to.equal('registry2.resin.io'); | ||
m.chai.expect(settings.proxyUrl).to.equal('resindevice.io'); | ||
}); | ||
} | ||
); | ||
wary.it( | ||
'should override defaults and resin configuration given a user balena configuration that points to staging', | ||
{}, | ||
() => { | ||
fs.writeFileSync( | ||
config.paths.user, | ||
@@ -112,3 +144,3 @@ stripIndent` | ||
wary.it( | ||
'should give precedende to environment variable configuration', | ||
'should give precedence to environment variable configuration', | ||
{}, | ||
@@ -115,0 +147,0 @@ () => { |
@@ -40,2 +40,12 @@ import * as m from 'mochainon'; | ||
}); | ||
it('should return the correct setting with a RESINRC_ variable prefix', () => { | ||
const setting = environment.getSettingName('RESINRC_HELLO'); | ||
m.chai.expect(setting).to.equal('hello'); | ||
}); | ||
it('should return the correct setting for a resin-related variable name', () => { | ||
const setting = environment.getSettingName('RESINRC_RESIN_URL'); | ||
m.chai.expect(setting).to.equal('balenaUrl'); | ||
}); | ||
}); | ||
@@ -49,2 +59,7 @@ | ||
it('should return true if it starts with RESINRC_', () => | ||
m.chai | ||
.expect(environment.isSettingVariable('RESINRC_HELLO')) | ||
.to.equal(true)); | ||
it('should return true if it starts with balenarc_', () => | ||
@@ -51,0 +66,0 @@ m.chai |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80550
1708
1