renovate/lib/config/file.ts
2020-05-01 18:03:48 +02:00

34 lines
1.1 KiB
TypeScript

import path from 'path';
import { logger } from '../logger';
import { RenovateConfig } from './common';
import { migrateConfig } from './migration';
export function getConfig(env: NodeJS.ProcessEnv): RenovateConfig {
let configFile = env.RENOVATE_CONFIG_FILE || 'config';
if (!path.isAbsolute(configFile)) {
configFile = `${process.cwd()}/${configFile}`;
logger.debug('Checking for config file in ' + configFile);
}
let config: RenovateConfig = {};
try {
// eslint-disable-next-line global-require,import/no-dynamic-require
config = require(configFile);
} catch (err) {
// istanbul ignore if
if (err instanceof SyntaxError) {
logger.fatal(`Could not parse config file \n ${err.stack}`);
process.exit(1);
}
// Do nothing
logger.debug('No config file found on disk - skipping');
}
const { isMigrated, migratedConfig } = migrateConfig(config);
if (isMigrated) {
logger.warn(
{ originalConfig: config, migratedConfig },
'Config needs migrating'
);
config = migratedConfig;
}
return config;
}