mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
decaffeinate: Convert Settings.coffee to JS
This commit is contained in:
parent
551eef00fb
commit
2787cd6152
1 changed files with 59 additions and 42 deletions
101
libraries/settings/Settings.js
Executable file → Normal file
101
libraries/settings/Settings.js
Executable file → Normal file
|
@ -1,50 +1,67 @@
|
|||
fs = require "fs"
|
||||
path = require "path"
|
||||
env = (process.env.NODE_ENV or "development").toLowerCase()
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let defaults, possibleConfigFiles, settingsExist;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const env = (process.env.NODE_ENV || "development").toLowerCase();
|
||||
|
||||
merge = (settings, defaults) ->
|
||||
for key, value of settings
|
||||
if typeof(value) == "object" and value not instanceof Array
|
||||
defaults[key] = merge(settings[key], defaults[key] or {})
|
||||
else
|
||||
defaults[key] = value
|
||||
return defaults
|
||||
var merge = function(settings, defaults) {
|
||||
for (let key in settings) {
|
||||
const value = settings[key];
|
||||
if ((typeof(value) === "object") && !(value instanceof Array)) {
|
||||
defaults[key] = merge(settings[key], defaults[key] || {});
|
||||
} else {
|
||||
defaults[key] = value;
|
||||
}
|
||||
}
|
||||
return defaults;
|
||||
};
|
||||
|
||||
defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults")
|
||||
const defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults");
|
||||
|
||||
if fs.existsSync("#{defaultSettingsPath}.js")
|
||||
console.log "Using default settings from #{defaultSettingsPath}.js"
|
||||
defaults = require("#{defaultSettingsPath}.js")
|
||||
settingsExist = true
|
||||
else if fs.existsSync("#{defaultSettingsPath}.coffee")
|
||||
console.warn "CoffeeScript settings file #{defaultSettingsPath}.coffee is deprecated, please convert to JavaScript"
|
||||
console.log "Using default settings from #{defaultSettingsPath}.coffee"
|
||||
defaults = require("#{defaultSettingsPath}.coffee")
|
||||
settingsExist = true
|
||||
else
|
||||
defaults = {}
|
||||
settingsExist = false
|
||||
if (fs.existsSync(`${defaultSettingsPath}.js`)) {
|
||||
console.log(`Using default settings from ${defaultSettingsPath}.js`);
|
||||
defaults = require(`${defaultSettingsPath}.js`);
|
||||
settingsExist = true;
|
||||
} else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) {
|
||||
console.warn(`CoffeeScript settings file ${defaultSettingsPath}.coffee is deprecated, please convert to JavaScript`);
|
||||
console.log(`Using default settings from ${defaultSettingsPath}.coffee`);
|
||||
defaults = require(`${defaultSettingsPath}.coffee`);
|
||||
settingsExist = true;
|
||||
} else {
|
||||
defaults = {};
|
||||
settingsExist = false;
|
||||
}
|
||||
|
||||
if process.env.SHARELATEX_CONFIG?
|
||||
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
|
||||
else
|
||||
if (process.env.SHARELATEX_CONFIG != null) {
|
||||
possibleConfigFiles = [process.env.SHARELATEX_CONFIG];
|
||||
} else {
|
||||
possibleConfigFiles = [
|
||||
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")
|
||||
]
|
||||
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`)
|
||||
];
|
||||
}
|
||||
|
||||
for file in possibleConfigFiles
|
||||
if fs.existsSync(file)
|
||||
if file.endsWith('.coffee')
|
||||
console.warn "CoffeeScript settings file #{file} is deprecated, please convert to JavaScript"
|
||||
console.log "Using settings from " + file
|
||||
module.exports = merge(require(file), defaults)
|
||||
settingsExist = true
|
||||
break
|
||||
for (let file of Array.from(possibleConfigFiles)) {
|
||||
if (fs.existsSync(file)) {
|
||||
if (file.endsWith('.coffee')) {
|
||||
console.warn(`CoffeeScript settings file ${file} is deprecated, please convert to JavaScript`);
|
||||
}
|
||||
console.log("Using settings from " + file);
|
||||
module.exports = merge(require(file), defaults);
|
||||
settingsExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if !settingsExist
|
||||
console.warn "No settings or defaults found. I'm flying blind."
|
||||
if (!settingsExist) {
|
||||
console.warn("No settings or defaults found. I'm flying blind.");
|
||||
}
|
||||
|
||||
module.exports = defaults
|
||||
module.exports = defaults;
|
||||
|
|
Loading…
Reference in a new issue