overleaf/libraries/settings/Settings.coffee

42 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2014-02-17 09:51:21 -05:00
fs = require "fs"
path = require "path"
env = (process.env.NODE_ENV or "development").toLowerCase()
merge = (settings, defaults) ->
for key, value of settings
2014-04-03 06:14:28 -04:00
if typeof(value) == "object" and value not instanceof Array
defaults[key] = merge(settings[key], defaults[key] or {})
else
defaults[key] = value
return defaults
2018-04-10 09:01:32 -04:00
defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults")
2018-04-10 09:01:32 -04:00
if fs.existsSync("#{defaultSettingsPath}.coffee") or fs.existsSync("#{defaultSettingsPath}.js")
defaults = require(defaultSettingsPath)
settingsExist = true
else
defaults = {}
settingsExist = false
if process.env.SHARELATEX_CONFIG?
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
else
possibleConfigFiles = [
2018-04-10 09:01:32 -04:00
process.cwd() + "/config/settings.#{env}.js"
path.normalize(__dirname + "/../../config/settings.#{env}.js")
process.cwd() + "/config/settings.#{env}.coffee"
path.normalize(__dirname + "/../../config/settings.#{env}.coffee")
]
2014-02-17 09:51:21 -05:00
for file in possibleConfigFiles
if fs.existsSync(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