renovate/lib/config/env.js
2017-04-21 10:12:41 +02:00

41 lines
870 B
JavaScript

const configDefinitions = require('./definitions');
module.exports = {
getEnvName,
getConfig,
};
function getEnvName(option) {
if (option.env === false) {
return '';
}
if (option.env) {
return option.env;
}
const nameWithUnderscores = option.name.replace(/([A-Z])/g, '_$1');
return `RENOVATE_${nameWithUnderscores.toUpperCase()}`;
}
function getConfig(env) {
const options = configDefinitions.getOptions();
const config = {};
const coersions = {
boolean: val => val === 'true',
list: val => val.split(',').map(el => el.trim()),
string: val => val,
};
options.forEach(option => {
if (option.env !== false) {
const envName = getEnvName(option);
if (env[envName]) {
const coerce = coersions[option.type];
config[option.name] = coerce(env[envName]);
}
}
});
return config;
}