2020-05-10 22:19:32 +02:00
|
|
|
const util = require("util");
|
2020-05-10 16:43:11 +02:00
|
|
|
|
2020-05-11 14:18:59 +02:00
|
|
|
const { getDefaultConfig, getConfig, deepMergeConfigs, isConfigValid } = require("./utils");
|
|
|
|
|
|
|
|
const { getArgs } = require("./../utils");
|
2020-05-10 16:43:11 +02:00
|
|
|
|
2020-05-10 22:19:32 +02:00
|
|
|
const defaultConfig = getDefaultConfig();
|
|
|
|
|
|
|
|
const cliArgs = getArgs();
|
|
|
|
let userConfig = {};
|
|
|
|
|
|
|
|
if (cliArgs["config"]) {
|
|
|
|
userConfig = getConfig(cliArgs["config"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const config = deepMergeConfigs(defaultConfig, userConfig);
|
2020-05-10 15:34:19 +02:00
|
|
|
|
2020-05-10 16:43:11 +02:00
|
|
|
/**
|
|
|
|
* Update the config based on the CLI args
|
|
|
|
* @param {object} startArgs
|
|
|
|
*/
|
|
|
|
function updateConfigFromStartArgs(startArgs) {
|
2020-05-10 22:19:32 +02:00
|
|
|
function deprecateCliArg(key, callback) {
|
|
|
|
const val = startArgs[key];
|
|
|
|
if (val) {
|
|
|
|
console.warn(
|
|
|
|
"\x1b[33m\x1b[1m",
|
|
|
|
`Setting config values (${key}) from the CLI is deprecated. ` +
|
|
|
|
"This ability will be removed in the next major version. " +
|
|
|
|
"You should use the config file. "
|
|
|
|
);
|
|
|
|
callback(val);
|
|
|
|
}
|
2020-05-10 16:43:11 +02:00
|
|
|
}
|
2020-05-10 22:19:32 +02:00
|
|
|
|
|
|
|
deprecateCliArg("accesstoken", (val) => (config.backend.accessToken = val));
|
|
|
|
deprecateCliArg(
|
|
|
|
"disablesmallestscreen",
|
|
|
|
() => (config.backend.showSmallestScreenIndicator = false)
|
|
|
|
);
|
2020-05-11 16:00:45 +02:00
|
|
|
deprecateCliArg("webdav", () => (config.backend.enableWebdav = true));
|
2020-05-10 16:43:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the config based on the env variables
|
|
|
|
*/
|
|
|
|
function updateConfigFromEnv() {
|
2020-05-10 22:19:32 +02:00
|
|
|
function deprecateEnv(key, callback) {
|
|
|
|
const val = process.env[key];
|
|
|
|
if (val) {
|
|
|
|
console.warn(
|
|
|
|
"\x1b[33m\x1b[1m",
|
|
|
|
`Setting config values (${key}) from the environment is deprecated. ` +
|
|
|
|
"This ability will be removed in the next major version. " +
|
|
|
|
"You should use the config file. "
|
|
|
|
);
|
|
|
|
callback(val);
|
|
|
|
}
|
2020-05-10 16:43:11 +02:00
|
|
|
}
|
2020-05-10 22:19:32 +02:00
|
|
|
|
|
|
|
deprecateEnv("accesstoken", (val) => (config.backend.accessToken = val));
|
|
|
|
deprecateEnv(
|
|
|
|
"disablesmallestscreen",
|
|
|
|
() => (config.backend.showSmallestScreenIndicator = false)
|
|
|
|
);
|
2020-05-11 16:00:45 +02:00
|
|
|
deprecateEnv("webdav", () => (config.backend.enableWebdav = true));
|
2020-05-10 16:43:11 +02:00
|
|
|
}
|
|
|
|
|
2020-05-10 22:19:32 +02:00
|
|
|
// compatibility layer
|
|
|
|
// FIXME: remove this in next major
|
2020-05-10 16:43:11 +02:00
|
|
|
updateConfigFromEnv();
|
2020-05-10 22:19:32 +02:00
|
|
|
// FIXME: remove this in next major
|
|
|
|
updateConfigFromStartArgs(cliArgs);
|
|
|
|
|
|
|
|
if (!isConfigValid(config, true)) {
|
|
|
|
throw new Error("Config is not valid. Check logs for details");
|
|
|
|
}
|
2020-05-12 22:55:29 +02:00
|
|
|
|
|
|
|
if (!process.env.JEST_WORKER_ID) {
|
|
|
|
console.info(util.inspect(config, { showHidden: false, depth: null, colors: true }));
|
|
|
|
}
|
2020-05-10 16:43:11 +02:00
|
|
|
|
2020-05-10 15:34:19 +02:00
|
|
|
module.exports = config;
|