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"
|
* decaffeinate suggestions:
|
||||||
env = (process.env.NODE_ENV or "development").toLowerCase()
|
* 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) ->
|
var merge = function(settings, defaults) {
|
||||||
for key, value of settings
|
for (let key in settings) {
|
||||||
if typeof(value) == "object" and value not instanceof Array
|
const value = settings[key];
|
||||||
defaults[key] = merge(settings[key], defaults[key] or {})
|
if ((typeof(value) === "object") && !(value instanceof Array)) {
|
||||||
else
|
defaults[key] = merge(settings[key], defaults[key] || {});
|
||||||
defaults[key] = value
|
} else {
|
||||||
return defaults
|
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")
|
if (fs.existsSync(`${defaultSettingsPath}.js`)) {
|
||||||
console.log "Using default settings from #{defaultSettingsPath}.js"
|
console.log(`Using default settings from ${defaultSettingsPath}.js`);
|
||||||
defaults = require("#{defaultSettingsPath}.js")
|
defaults = require(`${defaultSettingsPath}.js`);
|
||||||
settingsExist = true
|
settingsExist = true;
|
||||||
else if fs.existsSync("#{defaultSettingsPath}.coffee")
|
} else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) {
|
||||||
console.warn "CoffeeScript settings file #{defaultSettingsPath}.coffee is deprecated, please convert to JavaScript"
|
console.warn(`CoffeeScript settings file ${defaultSettingsPath}.coffee is deprecated, please convert to JavaScript`);
|
||||||
console.log "Using default settings from #{defaultSettingsPath}.coffee"
|
console.log(`Using default settings from ${defaultSettingsPath}.coffee`);
|
||||||
defaults = require("#{defaultSettingsPath}.coffee")
|
defaults = require(`${defaultSettingsPath}.coffee`);
|
||||||
settingsExist = true
|
settingsExist = true;
|
||||||
else
|
} else {
|
||||||
defaults = {}
|
defaults = {};
|
||||||
settingsExist = false
|
settingsExist = false;
|
||||||
|
}
|
||||||
|
|
||||||
if process.env.SHARELATEX_CONFIG?
|
if (process.env.SHARELATEX_CONFIG != null) {
|
||||||
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
|
possibleConfigFiles = [process.env.SHARELATEX_CONFIG];
|
||||||
else
|
} else {
|
||||||
possibleConfigFiles = [
|
possibleConfigFiles = [
|
||||||
process.cwd() + "/config/settings.#{env}.js"
|
process.cwd() + `/config/settings.${env}.js`,
|
||||||
path.normalize(__dirname + "/../../config/settings.#{env}.js")
|
path.normalize(__dirname + `/../../config/settings.${env}.js`),
|
||||||
process.cwd() + "/config/settings.#{env}.coffee"
|
process.cwd() + `/config/settings.${env}.coffee`,
|
||||||
path.normalize(__dirname + "/../../config/settings.#{env}.coffee")
|
path.normalize(__dirname + `/../../config/settings.${env}.coffee`)
|
||||||
]
|
];
|
||||||
|
}
|
||||||
|
|
||||||
for file in possibleConfigFiles
|
for (let file of Array.from(possibleConfigFiles)) {
|
||||||
if fs.existsSync(file)
|
if (fs.existsSync(file)) {
|
||||||
if file.endsWith('.coffee')
|
if (file.endsWith('.coffee')) {
|
||||||
console.warn "CoffeeScript settings file #{file} is deprecated, please convert to JavaScript"
|
console.warn(`CoffeeScript settings file ${file} is deprecated, please convert to JavaScript`);
|
||||||
console.log "Using settings from " + file
|
}
|
||||||
module.exports = merge(require(file), defaults)
|
console.log("Using settings from " + file);
|
||||||
settingsExist = true
|
module.exports = merge(require(file), defaults);
|
||||||
break
|
settingsExist = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !settingsExist
|
if (!settingsExist) {
|
||||||
console.warn "No settings or defaults found. I'm flying blind."
|
console.warn("No settings or defaults found. I'm flying blind.");
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = defaults
|
module.exports = defaults;
|
||||||
|
|
Loading…
Reference in a new issue