mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
4de9c98d2f
[settings] setup linting and fix all the violations GitOrigin-RevId: 321ecf0e8749a0481d61ad720baffe06089dc5cf
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
/* 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')
|
|
|
|
const defaultSettingsPath = path.join(
|
|
__dirname,
|
|
'../../../config/settings.defaults'
|
|
)
|
|
|
|
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`)) {
|
|
// TODO: remove this in the next major version
|
|
throw new Error(
|
|
`CoffeeScript settings file ${defaultSettingsPath}.coffee is no longer supported, please convert to JavaScript`
|
|
)
|
|
} else {
|
|
defaults = {}
|
|
settingsExist = false
|
|
}
|
|
|
|
if (process.env.SHARELATEX_CONFIG) {
|
|
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
|
|
} else {
|
|
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`),
|
|
]
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
if (!settingsExist) {
|
|
console.warn("No settings or defaults found. I'm flying blind.")
|
|
}
|
|
|
|
module.exports = defaults
|