2021-12-16 04:19:28 -05:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
const fs = require('fs')
|
2022-02-07 06:46:51 -05:00
|
|
|
const Path = require('path')
|
2021-12-16 04:19:28 -05:00
|
|
|
const { merge } = require('./merge')
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2022-02-07 06:46:51 -05:00
|
|
|
const CWD = process.cwd()
|
|
|
|
const NODE_ENV = (process.env.NODE_ENV || 'development').toLowerCase()
|
|
|
|
const SHARELATEX_CONFIG = process.env.SHARELATEX_CONFIG
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2022-02-07 06:46:51 -05:00
|
|
|
let settings
|
|
|
|
let settingsExist = false
|
|
|
|
const defaultsPath = pathIfExists(Path.join(CWD, 'config/settings.defaults.js'))
|
|
|
|
if (defaultsPath) {
|
|
|
|
console.log(`Using default settings from ${defaultsPath}`)
|
|
|
|
settings = require(defaultsPath)
|
2021-12-16 04:19:28 -05:00
|
|
|
settingsExist = true
|
2021-05-26 09:24:24 -04:00
|
|
|
} else {
|
2022-02-07 06:46:51 -05:00
|
|
|
settings = {}
|
2021-05-26 09:24:24 -04:00
|
|
|
}
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2022-02-07 06:46:51 -05:00
|
|
|
const overridesPath =
|
|
|
|
pathIfExists(SHARELATEX_CONFIG) ||
|
|
|
|
pathIfExists(Path.join(CWD, `config/settings.${NODE_ENV}.js`))
|
|
|
|
if (overridesPath) {
|
|
|
|
console.log(`Using settings from ${overridesPath}`)
|
|
|
|
settings = merge(require(overridesPath), settings)
|
|
|
|
settingsExist = true
|
2021-05-26 09:24:24 -04:00
|
|
|
}
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2021-05-26 09:24:24 -04:00
|
|
|
if (!settingsExist) {
|
2021-12-16 04:19:28 -05:00
|
|
|
console.warn("No settings or defaults found. I'm flying blind.")
|
2021-05-26 09:24:24 -04:00
|
|
|
}
|
2014-04-02 12:25:50 -04:00
|
|
|
|
2022-02-07 06:46:51 -05:00
|
|
|
module.exports = settings
|
|
|
|
|
|
|
|
function pathIfExists(path) {
|
|
|
|
if (path && fs.existsSync(path)) {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|