mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 05:05:27 -05:00
7e41fbf81b
[settings] add check for `process.argv[1]` GitOrigin-RevId: 24e9e02dc840e9c4206d36b814150b092247d5d9
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
/* eslint-disable no-console */
|
|
const fs = require('fs')
|
|
const Path = require('path')
|
|
const { merge } = require('./merge')
|
|
|
|
const CWD = process.cwd()
|
|
const ENTRY_POINT_DIR = process.argv[1]
|
|
? Path.dirname(process.argv[1])
|
|
: undefined
|
|
const NODE_ENV = (process.env.NODE_ENV || 'development').toLowerCase()
|
|
const SHARELATEX_CONFIG = process.env.SHARELATEX_CONFIG
|
|
|
|
let settings
|
|
let settingsExist = false
|
|
const defaultsPath =
|
|
pathIfExists(Path.join(CWD, 'config/settings.defaults.js')) ||
|
|
pathIfExists(Path.join(ENTRY_POINT_DIR, 'config/settings.defaults.js'))
|
|
if (defaultsPath) {
|
|
console.log(`Using default settings from ${defaultsPath}`)
|
|
settings = require(defaultsPath)
|
|
settingsExist = true
|
|
} else {
|
|
settings = {}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
if (!settingsExist) {
|
|
console.warn("No settings or defaults found. I'm flying blind.")
|
|
}
|
|
|
|
module.exports = settings
|
|
|
|
function pathIfExists(path) {
|
|
if (path && fs.existsSync(path)) {
|
|
return path
|
|
}
|
|
return null
|
|
}
|