2014-02-17 09:51:21 -05:00
|
|
|
fs = require "fs"
|
|
|
|
path = require "path"
|
|
|
|
env = (process.env.NODE_ENV or "development").toLowerCase()
|
|
|
|
|
2014-04-02 12:25:50 -04:00
|
|
|
merge = (settings, defaults) ->
|
|
|
|
for key, value of settings
|
|
|
|
if typeof(value) == "object"
|
|
|
|
defaults[key] = merge(settings[key], defaults[key] or {})
|
|
|
|
else
|
|
|
|
defaults[key] = value
|
|
|
|
return defaults
|
|
|
|
|
|
|
|
defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults.coffee")
|
|
|
|
|
|
|
|
console.log "default settings", defaultSettingsPath
|
|
|
|
if fs.existsSync(defaultSettingsPath)
|
|
|
|
defaults = require(defaultSettingsPath)
|
|
|
|
settingsExist = true
|
|
|
|
else
|
|
|
|
defaults = {}
|
|
|
|
settingsExist = false
|
|
|
|
|
2014-02-19 08:21:32 -05:00
|
|
|
if process.env.SHARELATEX_CONFIG?
|
|
|
|
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
|
|
|
|
else
|
|
|
|
possibleConfigFiles = [
|
|
|
|
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)
|
2014-04-02 12:25:50 -04:00
|
|
|
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
|
2014-02-17 09:51:21 -05:00
|
|
|
|