renovate/lib/config/massage.js
2017-09-01 07:43:49 +02:00

42 lines
1.1 KiB
JavaScript

const options = require('./definitions').getOptions();
const allowedStrings = [];
options.forEach(option => {
if (option.allowString) {
allowedStrings.push(option.name);
}
});
module.exports = {
massageConfig,
};
// Returns a massaged config
function massageConfig(config) {
const massagedConfig = { ...config };
for (const key of Object.keys(config)) {
const val = config[key];
if (allowedStrings.includes(key) && typeof val === 'string') {
massagedConfig[key] = [val];
} else if (key === 'npmToken' && val.length < 30) {
massagedConfig.npmrc = `//registry.npmjs.org/:_authToken=${val}\n`;
delete massagedConfig.npmToken;
} else if (isObject(val)) {
massagedConfig[key] = massageConfig(val);
} else if (Array.isArray(val)) {
massagedConfig[key] = [];
val.forEach(item => {
if (isObject(item)) {
massagedConfig[key].push(massageConfig(item));
} else {
massagedConfig[key].push(item);
}
});
}
}
return massagedConfig;
}
function isObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}