2021-05-26 09:24:24 -04:00
|
|
|
let defaults, possibleConfigFiles, settingsExist;
|
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
const env = (process.env.NODE_ENV || "development").toLowerCase();
|
2021-07-06 08:51:28 -04:00
|
|
|
const { merge } = require('./merge');
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2021-07-06 10:19:13 -04:00
|
|
|
const defaultSettingsPath = path.normalize(__dirname + "/../../../config/settings.defaults");
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2021-05-26 09:24:24 -04:00
|
|
|
if (fs.existsSync(`${defaultSettingsPath}.js`)) {
|
|
|
|
console.log(`Using default settings from ${defaultSettingsPath}.js`);
|
|
|
|
defaults = require(`${defaultSettingsPath}.js`);
|
|
|
|
settingsExist = true;
|
|
|
|
} else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) {
|
2021-05-26 10:06:24 -04:00
|
|
|
// TODO: remove this in the next major version
|
|
|
|
throw new Error(`CoffeeScript settings file ${defaultSettingsPath}.coffee is no longer supported, please convert to JavaScript`);
|
2021-05-26 09:24:24 -04:00
|
|
|
} else {
|
|
|
|
defaults = {};
|
|
|
|
settingsExist = false;
|
|
|
|
}
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2021-05-26 10:06:24 -04:00
|
|
|
if (process.env.SHARELATEX_CONFIG) {
|
2021-05-26 09:24:24 -04:00
|
|
|
possibleConfigFiles = [process.env.SHARELATEX_CONFIG];
|
|
|
|
} else {
|
2014-02-19 08:21:32 -05:00
|
|
|
possibleConfigFiles = [
|
2021-05-26 09:24:24 -04:00
|
|
|
process.cwd() + `/config/settings.${env}.js`,
|
2021-07-06 10:19:13 -04:00
|
|
|
path.normalize(__dirname + `/../../../config/settings.${env}.js`),
|
2021-05-26 10:06:24 -04:00
|
|
|
// TODO: remove these in the next major version
|
2021-05-26 09:24:24 -04:00
|
|
|
process.cwd() + `/config/settings.${env}.coffee`,
|
2021-07-06 10:19:13 -04:00
|
|
|
path.normalize(__dirname + `/../../../config/settings.${env}.coffee`)
|
2021-05-26 09:24:24 -04:00
|
|
|
];
|
|
|
|
}
|
2014-02-17 09:51:21 -05:00
|
|
|
|
2021-05-26 10:06:24 -04:00
|
|
|
for (let file of possibleConfigFiles) {
|
2021-05-26 09:24:24 -04:00
|
|
|
if (fs.existsSync(file)) {
|
2021-05-26 10:06:24 -04:00
|
|
|
// TODO: remove this in the next major version
|
2021-05-26 09:24:24 -04:00
|
|
|
if (file.endsWith('.coffee')) {
|
2021-05-26 10:06:24 -04:00
|
|
|
throw new Error(`CoffeeScript settings file ${file} is no longer supported, please convert to JavaScript`);
|
2021-05-26 09:24:24 -04:00
|
|
|
}
|
|
|
|
console.log("Using settings from " + file);
|
|
|
|
module.exports = merge(require(file), defaults);
|
|
|
|
settingsExist = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2021-05-26 09:24:24 -04:00
|
|
|
if (!settingsExist) {
|
|
|
|
console.warn("No settings or defaults found. I'm flying blind.");
|
|
|
|
}
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2021-05-26 09:24:24 -04:00
|
|
|
module.exports = defaults;
|