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