mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-23 16:32:02 +00:00
Load and merge defaults if available
Load and merge defaults if available
This commit is contained in:
parent
6baf4ebe85
commit
c06e237e31
1 changed files with 27 additions and 4 deletions
|
@ -2,6 +2,24 @@ fs = require "fs"
|
||||||
path = require "path"
|
path = require "path"
|
||||||
env = (process.env.NODE_ENV or "development").toLowerCase()
|
env = (process.env.NODE_ENV or "development").toLowerCase()
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
if process.env.SHARELATEX_CONFIG?
|
if process.env.SHARELATEX_CONFIG?
|
||||||
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
|
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
|
||||||
else
|
else
|
||||||
|
@ -12,8 +30,13 @@ else
|
||||||
|
|
||||||
for file in possibleConfigFiles
|
for file in possibleConfigFiles
|
||||||
if fs.existsSync(file)
|
if fs.existsSync(file)
|
||||||
module.exports = require(file)
|
module.exports = merge(require(file), defaults)
|
||||||
return
|
settingsExist = true
|
||||||
|
break
|
||||||
|
|
||||||
console.log "No config file could be found at: ", possibleConfigFiles
|
if !settingsExist
|
||||||
throw new Error("No config file found")
|
console.warn "No settings or defaults found. I'm flying blind."
|
||||||
|
|
||||||
|
module.exports = defaults
|
||||||
|
|
||||||
|
console.log "Settings", module.exports
|
Loading…
Reference in a new issue